Spaces:
Running
Running
| import os | |
| import random | |
| import requests | |
| import gradio as gr | |
| from PIL import Image | |
| from io import BytesIO | |
| def generate_image(prompt, width, height, seed, randomize): | |
| print(prompt+"\n\n") | |
| if randomize: | |
| seed = random.randint(0, 9999999) | |
| base_url = os.environ.get("FLUX_URL") | |
| if not base_url: | |
| return "Error: FLUX_URL environment variable not set." | |
| url = ( | |
| base_url.replace("[prompt]", prompt) | |
| .replace("[w]", str(width)) | |
| .replace("[h]", str(height)) | |
| .replace("[seed]", str(seed)) | |
| ) | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| image = Image.open(BytesIO(response.content)) | |
| return image | |
| else: | |
| return "Failed to retrieve image." | |
| 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.Textbox(label="Prompt", placeholder="Enter your image prompt..."), | |
| gr.Slider(minimum=512, maximum=1280, step=16, value=1280, label="Width"), | |
| gr.Slider(minimum=512, maximum=1280, step=16, value=1280, label="Height"), | |
| gr.Number(label="Seed", value=0), | |
| gr.Checkbox(label="Randomize Seed", value=True) | |
| ], | |
| outputs=gr.Image(type="pil"), | |
| title=title, | |
| description=description, | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |