import os import random import requests import gradio as gr from io import BytesIO def generate_image(prompt, width, height, seed, randomize): # If randomized seed is checked, generate a random seed. if randomize: seed = random.randint(0, 99999) # Fetch the secret URL from environment variables. # The URL should be stored in an env variable named "FLUX_URL". base_url = os.environ.get("FLUX_URL") if not base_url: return "Error: FLUX_URL environment variable not set." # Replace placeholders in the URL. url = ( base_url.replace("[prompt]", prompt) .replace("[w]", str(width)) .replace("[h]", str(height)) .replace("[seed]", str(seed)) ) # Fetch the image from the URL. response = requests.get(url) return BytesIO(response.content) # Gradio Interface setup with title and description. title = "Unlimited FLUX-Pro" description = "Here you can use the FLUX-Pro as much as you want without limits" iface = gr.Interface( fn=generate_image, inputs=[ gr.inputs.Textbox(label="Prompt", placeholder="Enter your image prompt..."), gr.inputs.Slider(minimum=100, maximum=1024, step=1, default=512, label="Width"), gr.inputs.Slider(minimum=100, maximum=1024, step=1, default=512, label="Height"), gr.inputs.Number(label="Seed", default=0), gr.inputs.Checkbox(label="Randomize Seed") ], outputs=gr.outputs.Image(type="pil"), title=title, description=description, ) if __name__ == "__main__": iface.launch()