Skip to content

Commit

Permalink
Add text-to-speech and text-to-video examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hanouticelina committed Jan 27, 2025
1 parent 10a2392 commit c7d6f73
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 8 deletions.
61 changes: 59 additions & 2 deletions src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2468,8 +2468,7 @@ def text_to_image(
... )
>>> image.save("better_astronaut.png")
```
Example using fal.ai provider:
Example using a third-party provider directly. Usage will be billed on your fal.ai account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
Expand Down Expand Up @@ -2555,6 +2554,38 @@ def text_to_video(
Returns:
`bytes`: The generated video.
Example:
Example using a third-party provider directly. Usage will be billed on your fal.ai account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="fal-ai", # Using fal.ai provider
... api_key="fal-ai-api-key", # Pass your fal.ai API key
... )
>>> video = client.text_to_video(
... "A majestic lion running in a fantasy forest",
... model="tencent/HunyuanVideo",
... )
>>> with open("lion.mp4", "wb") as file:
... file.write(video)
```
Example using a third-party provider through Hugging Face Routing. Usage will be billed on your Hugging Face account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="replicate", # Using replicate provider
... api_key="hf_...", # Pass your HF token
... )
>>> video = client.text_to_video(
... "A cat running in a park",
... model="genmo/mochi-1-preview",
... )
>>> with open("cat.mp4", "wb") as file:
... file.write(video)
```
"""
provider_helper = get_provider_helper(self.provider, task="text-to-video")
request_parameters = provider_helper.prepare_request(
Expand Down Expand Up @@ -2671,6 +2702,32 @@ def text_to_speech(
>>> audio = client.text_to_speech("Hello world")
>>> Path("hello_world.flac").write_bytes(audio)
```
Example using a third-party provider directly. Usage will be billed on your Replicate account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="replicate",
... api_key="your-replicate-api-key", # Pass your Replicate API key directly
... )
>>> audio = client.text_to_speech(
... text="Hello world",
... model="OuteAI/OuteTTS-0.3-500M",
... )
```
Example using a third-party provider through Hugging Face Routing. Usage will be billed on your Hugging Face account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="replicate",
... api_key="hf_...", # Pass your HF token
... )
>>> audio =client.text_to_speech(
... text="Hello world",
... model="OuteAI/OuteTTS-0.3-500M",
... )
```
"""
provider_helper = get_provider_helper(self.provider, task="text-to-speech")
request_parameters = provider_helper.prepare_request(
Expand Down
68 changes: 62 additions & 6 deletions src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2528,16 +2528,14 @@ async def text_to_image(
... )
>>> image.save("better_astronaut.png")
```
Example using fal.ai provider:
Example using a third-party provider directly. Usage will be billed on your fal.ai account.
```py
# Must be run in an async context
>>> from huggingface_hub import AsyncInferenceClient
>>> client = AsyncInferenceClient(
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="fal-ai", # Use fal.ai provider
... api_key="fal-ai-api-key", # Pass your fal.ai API key
... )
>>> image = await client.text_to_image(
>>> image = client.text_to_image(
... "A majestic lion in a fantasy forest",
... model="black-forest-labs/FLUX.1-schnell",
... )
Expand Down Expand Up @@ -2616,6 +2614,38 @@ async def text_to_video(
Returns:
`bytes`: The generated video.
Example:
Example using a third-party provider directly. Usage will be billed on your fal.ai account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="fal-ai", # Using fal.ai provider
... api_key="fal-ai-api-key", # Pass your fal.ai API key
... )
>>> video = client.text_to_video(
... "A majestic lion running in a fantasy forest",
... model="tencent/HunyuanVideo",
... )
>>> with open("lion.mp4", "wb") as file:
... file.write(video)
```
Example using a third-party provider through Hugging Face Routing. Usage will be billed on your Hugging Face account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="replicate", # Using replicate provider
... api_key="hf_...", # Pass your HF token
... )
>>> video = client.text_to_video(
... "A cat running in a park",
... model="genmo/mochi-1-preview",
... )
>>> with open("cat.mp4", "wb") as file:
... file.write(video)
```
"""
provider_helper = get_provider_helper(self.provider, task="text-to-video")
request_parameters = provider_helper.prepare_request(
Expand Down Expand Up @@ -2733,6 +2763,32 @@ async def text_to_speech(
>>> audio = await client.text_to_speech("Hello world")
>>> Path("hello_world.flac").write_bytes(audio)
```
Example using a third-party provider directly. Usage will be billed on your Replicate account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="replicate",
... api_key="your-replicate-api-key", # Pass your Replicate API key directly
... )
>>> audio = client.text_to_speech(
... text="Hello world",
... model="OuteAI/OuteTTS-0.3-500M",
... )
```
Example using a third-party provider through Hugging Face Routing. Usage will be billed on your Hugging Face account.
```py
>>> from huggingface_hub import InferenceClient
>>> client = InferenceClient(
... provider="replicate",
... api_key="hf_...", # Pass your HF token
... )
>>> audio =client.text_to_speech(
... text="Hello world",
... model="OuteAI/OuteTTS-0.3-500M",
... )
```
"""
provider_helper = get_provider_helper(self.provider, task="text-to-speech")
request_parameters = provider_helper.prepare_request(
Expand Down

0 comments on commit c7d6f73

Please sign in to comment.