import gradio as gr import replicate import os import requests from PIL import Image from io import BytesIO def generate_image(prompt, api_key): # Set the API key for the current session os.environ["REPLICATE_API_TOKEN"] = api_key # Prepare the input for the model inputs = { "prompt": prompt, "prompt_upsampling": True } # Run the model and get the output URL output_url = replicate.run( "black-forest-labs/flux-1.1-pro", input=inputs ) # Fetch the image from the URL response = requests.get(output_url) image = Image.open(BytesIO(response.content)) # Return the image return image # Create the Gradio interface 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." ) # Launch the Gradio app iface.launch()