Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
import random
|
4 |
+
|
5 |
+
def generate_image(prompt, width, height, steps, seed_choice):
|
6 |
+
client = Client("black-forest-labs/FLUX.1-schnell")
|
7 |
+
|
8 |
+
# Определяем seed
|
9 |
+
if seed_choice == "Random":
|
10 |
+
seed = random.randint(0, 999999)
|
11 |
+
else:
|
12 |
+
seed = 0
|
13 |
+
|
14 |
+
result = client.predict(
|
15 |
+
prompt=prompt,
|
16 |
+
seed=seed,
|
17 |
+
randomize_seed=(seed_choice == "Random"),
|
18 |
+
width=width,
|
19 |
+
height=height,
|
20 |
+
num_inference_steps=steps,
|
21 |
+
api_name="/infer"
|
22 |
+
)
|
23 |
+
|
24 |
+
return result
|
25 |
+
|
26 |
+
# Создаем интерфейс
|
27 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
28 |
+
gr.Markdown(
|
29 |
+
"""
|
30 |
+
# 🎨 AI Image Generator
|
31 |
+
Create amazing images using advanced AI technology!
|
32 |
+
"""
|
33 |
+
)
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
with gr.Column(scale=1):
|
37 |
+
# Inputs
|
38 |
+
prompt = gr.Textbox(
|
39 |
+
label="Prompt",
|
40 |
+
placeholder="Describe the image you want to generate...",
|
41 |
+
lines=3
|
42 |
+
)
|
43 |
+
|
44 |
+
with gr.Row():
|
45 |
+
width = gr.Slider(
|
46 |
+
minimum=512,
|
47 |
+
maximum=1024,
|
48 |
+
step=64,
|
49 |
+
value=1024,
|
50 |
+
label="Width"
|
51 |
+
)
|
52 |
+
height = gr.Slider(
|
53 |
+
minimum=512,
|
54 |
+
maximum=1024,
|
55 |
+
step=64,
|
56 |
+
value=1024,
|
57 |
+
label="Height"
|
58 |
+
)
|
59 |
+
|
60 |
+
steps = gr.Slider(
|
61 |
+
minimum=1,
|
62 |
+
maximum=50,
|
63 |
+
step=1,
|
64 |
+
value=4,
|
65 |
+
label="Inference Steps"
|
66 |
+
)
|
67 |
+
|
68 |
+
seed_choice = gr.Radio(
|
69 |
+
choices=["Fixed", "Random"],
|
70 |
+
value="Random",
|
71 |
+
label="Seed Type"
|
72 |
+
)
|
73 |
+
|
74 |
+
generate_btn = gr.Button(
|
75 |
+
"🎨 Generate",
|
76 |
+
variant="primary"
|
77 |
+
)
|
78 |
+
|
79 |
+
with gr.Column(scale=1):
|
80 |
+
# Output
|
81 |
+
output_image = gr.Image(
|
82 |
+
label="Generated Image",
|
83 |
+
type="filepath"
|
84 |
+
)
|
85 |
+
|
86 |
+
# События
|
87 |
+
generate_btn.click(
|
88 |
+
fn=generate_image,
|
89 |
+
inputs=[prompt, width, height, steps, seed_choice],
|
90 |
+
outputs=output_image
|
91 |
+
)
|
92 |
+
|
93 |
+
gr.Markdown(
|
94 |
+
"""
|
95 |
+
### Tips:
|
96 |
+
- Try different prompts to get various results
|
97 |
+
- Adjust width and height for different image sizes
|
98 |
+
- Increase steps for better quality (but slower generation)
|
99 |
+
- Use fixed seed to get reproducible results
|
100 |
+
"""
|
101 |
+
)
|
102 |
+
|
103 |
+
# Запускаем интерфейс
|
104 |
+
demo.launch()
|