Skip to content

Commit 8164742

Browse files
committed
text-to-image section
1 parent 09f1bc5 commit 8164742

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

docs/inference-providers/index.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,49 @@ curl https://router.huggingface.co/v1/chat/completions \
287287
}'
288288
```
289289

290-
### Quick Start - Image generation
290+
### Quick Start - Text-to-Image Generation
291291

292-
TODO: explain how to use inference providers for text-to-image task
292+
Let's explore how to generate images from text prompts using Inference Providers. We'll use [black-forest-labs/FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev), a state-of-the-art diffusion model that produces highly detailed, photorealistic images.
293+
294+
#### Python
295+
296+
Use the `huggingface_hub` library for the simplest image generation experience with automatic provider selection:
297+
298+
```python
299+
import os
300+
from huggingface_hub import InferenceClient
301+
302+
client = InferenceClient(api_key=os.environ["HF_TOKEN"])
303+
304+
image = client.text_to_image(
305+
prompt="A serene lake surrounded by mountains at sunset, photorealistic style",
306+
model="black-forest-labs/FLUX.1-dev"
307+
)
308+
309+
# Save the generated image
310+
image.save("generated_image.png")
311+
```
312+
313+
#### JavaScript
314+
315+
Use our JavaScript SDK for streamlined image generation with TypeScript support:
316+
317+
```js
318+
import { InferenceClient } from "@huggingface/inference";
319+
import fs from "fs";
320+
321+
const client = new InferenceClient(process.env.HF_TOKEN);
322+
323+
const imageBlob = await client.textToImage({
324+
model: "black-forest-labs/FLUX.1-dev",
325+
inputs:
326+
"A serene lake surrounded by mountains at sunset, photorealistic style",
327+
});
328+
329+
// Save the image
330+
const buffer = Buffer.from(await imageBlob.arrayBuffer());
331+
fs.writeFileSync("generated_image.png", buffer);
332+
```
293333

294334
## Advanced usage
295335

0 commit comments

Comments
 (0)