Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio_client import Client
|
3 |
import numpy as np
|
4 |
|
5 |
MAX_SEED = np.iinfo(np.int32).max
|
6 |
MAX_IMAGE_SIZE = 2048
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
client = None
|
13 |
job = None
|
14 |
|
15 |
-
|
16 |
-
|
17 |
global job
|
18 |
global client
|
19 |
-
|
20 |
if client is None:
|
21 |
try:
|
22 |
client = Client(selected_space)
|
@@ -25,7 +29,7 @@ def infer(selected_space, prompt, seed=42, randomize_seed=False, width=1024, hei
|
|
25 |
client = None
|
26 |
print(f"Failed to load custom model from {selected_space}: {e}")
|
27 |
raise gr.Error("Failed to load client after trying all spaces.")
|
28 |
-
|
29 |
try:
|
30 |
job = client.submit(
|
31 |
prompt=prompt,
|
@@ -40,16 +44,15 @@ def infer(selected_space, prompt, seed=42, randomize_seed=False, width=1024, hei
|
|
40 |
except ValueError as e:
|
41 |
client = None
|
42 |
raise gr.Error(e)
|
43 |
-
|
44 |
return result
|
45 |
-
|
46 |
examples = [
|
47 |
"a tiny astronaut hatching from an egg on the moon",
|
48 |
"a cat holding a sign that says hello world",
|
49 |
"an anime illustration of a wiener schnitzel",
|
50 |
]
|
51 |
|
52 |
-
css="""
|
53 |
#col-container {
|
54 |
margin: 0 auto;
|
55 |
max-width: 520px;
|
@@ -57,12 +60,14 @@ css="""
|
|
57 |
"""
|
58 |
|
59 |
with gr.Blocks(css=css) as demo:
|
60 |
-
selected_space_index = gr.State(0)
|
61 |
|
62 |
with gr.Column(elem_id="col-container"):
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
with gr.Row():
|
68 |
prompt = gr.Text(
|
@@ -72,13 +77,11 @@ with gr.Blocks(css=css) as demo:
|
|
72 |
placeholder="Enter your prompt",
|
73 |
container=False,
|
74 |
)
|
75 |
-
|
76 |
run_button = gr.Button("Run", scale=0)
|
77 |
-
|
78 |
result = gr.Image(label="Result", show_label=False)
|
79 |
|
80 |
with gr.Accordion("Advanced Settings", open=False):
|
81 |
-
|
82 |
seed = gr.Slider(
|
83 |
label="Seed",
|
84 |
minimum=0,
|
@@ -86,11 +89,9 @@ with gr.Blocks(css=css) as demo:
|
|
86 |
step=1,
|
87 |
value=0,
|
88 |
)
|
89 |
-
|
90 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
91 |
|
92 |
with gr.Row():
|
93 |
-
|
94 |
width = gr.Slider(
|
95 |
label="Width",
|
96 |
minimum=256,
|
@@ -98,7 +99,6 @@ with gr.Blocks(css=css) as demo:
|
|
98 |
step=32,
|
99 |
value=1024,
|
100 |
)
|
101 |
-
|
102 |
height = gr.Slider(
|
103 |
label="Height",
|
104 |
minimum=256,
|
@@ -106,10 +106,8 @@ with gr.Blocks(css=css) as demo:
|
|
106 |
step=32,
|
107 |
value=1024,
|
108 |
)
|
109 |
-
|
110 |
-
with gr.Row():
|
111 |
|
112 |
-
|
113 |
num_inference_steps = gr.Slider(
|
114 |
label="Number of inference steps",
|
115 |
minimum=1,
|
@@ -117,23 +115,29 @@ with gr.Blocks(css=css) as demo:
|
|
117 |
step=1,
|
118 |
value=4,
|
119 |
)
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
<div class="footer">
|
138 |
<p>
|
139 |
Best AI Tools •
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
import numpy as np
|
4 |
|
5 |
MAX_SEED = np.iinfo(np.int32).max
|
6 |
MAX_IMAGE_SIZE = 2048
|
7 |
|
8 |
+
flux_1_schell_spaces = [
|
9 |
+
"https://black-forest-labs-flux-1-schnell.hf.space",
|
10 |
+
"ChristianHappy/FLUX.1-schnell",
|
11 |
+
"innoai/FLUX.1-schnell",
|
12 |
+
"tuan2308/FLUX.1-schnell",
|
13 |
+
"FiditeNemini/FLUX.1-schnell"
|
14 |
+
]
|
15 |
|
16 |
client = None
|
17 |
job = None
|
18 |
|
19 |
+
def infer(selected_space, prompt, seed=42, randomize_seed=False, width=1024, height=1024,
|
20 |
+
num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
21 |
global job
|
22 |
global client
|
23 |
+
|
24 |
if client is None:
|
25 |
try:
|
26 |
client = Client(selected_space)
|
|
|
29 |
client = None
|
30 |
print(f"Failed to load custom model from {selected_space}: {e}")
|
31 |
raise gr.Error("Failed to load client after trying all spaces.")
|
32 |
+
|
33 |
try:
|
34 |
job = client.submit(
|
35 |
prompt=prompt,
|
|
|
44 |
except ValueError as e:
|
45 |
client = None
|
46 |
raise gr.Error(e)
|
|
|
47 |
return result
|
48 |
+
|
49 |
examples = [
|
50 |
"a tiny astronaut hatching from an egg on the moon",
|
51 |
"a cat holding a sign that says hello world",
|
52 |
"an anime illustration of a wiener schnitzel",
|
53 |
]
|
54 |
|
55 |
+
css = """
|
56 |
#col-container {
|
57 |
margin: 0 auto;
|
58 |
max-width: 520px;
|
|
|
60 |
"""
|
61 |
|
62 |
with gr.Blocks(css=css) as demo:
|
63 |
+
selected_space_index = gr.State(0)
|
64 |
|
65 |
with gr.Column(elem_id="col-container"):
|
66 |
+
space = gr.Radio(
|
67 |
+
flux_1_schell_spaces,
|
68 |
+
label="Choose Your Flux Model",
|
69 |
+
value=flux_1_schell_spaces[0]
|
70 |
+
)
|
71 |
|
72 |
with gr.Row():
|
73 |
prompt = gr.Text(
|
|
|
77 |
placeholder="Enter your prompt",
|
78 |
container=False,
|
79 |
)
|
|
|
80 |
run_button = gr.Button("Run", scale=0)
|
81 |
+
|
82 |
result = gr.Image(label="Result", show_label=False)
|
83 |
|
84 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
85 |
seed = gr.Slider(
|
86 |
label="Seed",
|
87 |
minimum=0,
|
|
|
89 |
step=1,
|
90 |
value=0,
|
91 |
)
|
|
|
92 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
93 |
|
94 |
with gr.Row():
|
|
|
95 |
width = gr.Slider(
|
96 |
label="Width",
|
97 |
minimum=256,
|
|
|
99 |
step=32,
|
100 |
value=1024,
|
101 |
)
|
|
|
102 |
height = gr.Slider(
|
103 |
label="Height",
|
104 |
minimum=256,
|
|
|
106 |
step=32,
|
107 |
value=1024,
|
108 |
)
|
|
|
|
|
109 |
|
110 |
+
with gr.Row():
|
111 |
num_inference_steps = gr.Slider(
|
112 |
label="Number of inference steps",
|
113 |
minimum=1,
|
|
|
115 |
step=1,
|
116 |
value=4,
|
117 |
)
|
118 |
+
|
119 |
+
gr.Examples(
|
120 |
+
examples=examples,
|
121 |
+
fn=infer,
|
122 |
+
inputs=[selected_space_index, prompt],
|
123 |
+
outputs=[selected_space_index, space, result, seed],
|
124 |
+
cache_examples="lazy"
|
125 |
+
)
|
126 |
|
127 |
+
gr.on(
|
128 |
+
triggers=[run_button.click, prompt.submit],
|
129 |
+
fn=infer,
|
130 |
+
inputs=[
|
131 |
+
space,
|
132 |
+
prompt,
|
133 |
+
seed,
|
134 |
+
randomize_seed,
|
135 |
+
width,
|
136 |
+
height,
|
137 |
+
num_inference_steps
|
138 |
+
],
|
139 |
+
outputs=[result, seed]
|
140 |
+
)
|
141 |
<div class="footer">
|
142 |
<p>
|
143 |
Best AI Tools •
|