| import gradio as gr |
| import replicate |
| import os |
| import requests |
| from PIL import Image |
| from io import BytesIO |
|
|
| def generate_image(prompt, api_key): |
| |
| os.environ["REPLICATE_API_TOKEN"] = api_key |
| |
| |
| inputs = { |
| "prompt": prompt, |
| "prompt_upsampling": True |
| } |
| |
| |
| output_url = replicate.run( |
| "black-forest-labs/flux-1.1-pro", |
| input=inputs |
| ) |
| |
| |
| response = requests.get(output_url) |
| image = Image.open(BytesIO(response.content)) |
| |
| |
| return image |
|
|
| |
| iface = gr.Interface( |
| fn=generate_image, |
| inputs=[ |
| gr.Textbox( |
| lines=2, |
| placeholder="Enter your prompt here...", |
| label="Prompt" |
| ), |
| gr.Textbox( |
| lines=1, |
| placeholder="Enter your Replicate API key...", |
| type="password", |
| label="Replicate API Key" |
| ) |
| ], |
| outputs=gr.Image(type="pil"), |
| title="FLUX 1.1 Pro Text-to-Image Generator", |
| description="Generate images from text prompts using the FLUX 1.1 Pro model." |
| ) |
|
|
| |
| iface.launch() |
|
|