Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import random
|
| 3 |
+
import requests
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
def generate_image(prompt, width, height, seed, randomize):
|
| 8 |
+
# If randomized seed is checked, generate a random seed.
|
| 9 |
+
if randomize:
|
| 10 |
+
seed = random.randint(0, 99999)
|
| 11 |
+
# Fetch the secret URL from environment variables.
|
| 12 |
+
# The URL should be stored in an env variable named "FLUX_URL".
|
| 13 |
+
base_url = os.environ.get("FLUX_URL")
|
| 14 |
+
if not base_url:
|
| 15 |
+
return "Error: FLUX_URL environment variable not set."
|
| 16 |
+
# Replace placeholders in the URL.
|
| 17 |
+
url = (
|
| 18 |
+
base_url.replace("[prompt]", prompt)
|
| 19 |
+
.replace("[w]", str(width))
|
| 20 |
+
.replace("[h]", str(height))
|
| 21 |
+
.replace("[seed]", str(seed))
|
| 22 |
+
)
|
| 23 |
+
# Fetch the image from the URL.
|
| 24 |
+
response = requests.get(url)
|
| 25 |
+
return BytesIO(response.content)
|
| 26 |
+
|
| 27 |
+
# Gradio Interface setup with title and description.
|
| 28 |
+
title = "Unlimited FLUX-Pro"
|
| 29 |
+
description = "Here you can use the FLUX-Pro as much as you want without limits"
|
| 30 |
+
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=generate_image,
|
| 33 |
+
inputs=[
|
| 34 |
+
gr.inputs.Textbox(label="Prompt", placeholder="Enter your image prompt..."),
|
| 35 |
+
gr.inputs.Slider(minimum=100, maximum=1024, step=1, default=512, label="Width"),
|
| 36 |
+
gr.inputs.Slider(minimum=100, maximum=1024, step=1, default=512, label="Height"),
|
| 37 |
+
gr.inputs.Number(label="Seed", default=0),
|
| 38 |
+
gr.inputs.Checkbox(label="Randomize Seed")
|
| 39 |
+
],
|
| 40 |
+
outputs=gr.outputs.Image(type="pil"),
|
| 41 |
+
title=title,
|
| 42 |
+
description=description,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
iface.launch()
|