gokaygokay
commited on
Commit
•
bd1238e
1
Parent(s):
732db50
Update app.py
Browse files
app.py
CHANGED
@@ -12,24 +12,35 @@ def set_fal_key(api_key):
|
|
12 |
def generate_image(api_key, model, prompt, image_size, num_inference_steps, guidance_scale, num_images, safety_tolerance, enable_safety_checker, seed):
|
13 |
set_fal_key(api_key)
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
if seed != -1:
|
35 |
arguments["seed"] = seed
|
@@ -45,10 +56,18 @@ def generate_image(api_key, model, prompt, image_size, num_inference_steps, guid
|
|
45 |
images.append(img)
|
46 |
return images
|
47 |
except Exception as e:
|
|
|
48 |
return [Image.new('RGB', (512, 512), color='black')]
|
49 |
|
50 |
def update_visible_components(model):
|
51 |
-
if model == "Flux
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
return [
|
53 |
gr.update(visible=True, value=28),
|
54 |
gr.update(visible=True, value=3.5),
|
@@ -72,11 +91,11 @@ def update_visible_components(model):
|
|
72 |
|
73 |
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
74 |
gr.HTML("""
|
75 |
-
<h1 align="center">FLUX.1 Image Generation</h1>
|
76 |
<p align="center">
|
77 |
<a href="https://blackforestlabs.ai/" target="_blank">[Black Forest Labs]</a>
|
78 |
<a href="https://blackforestlabs.ai/announcing-black-forest-labs/" target="_blank">[Blog]</a>
|
79 |
-
<a href="https://fal.ai/models/fal-ai/flux-pro" target="_blank">[FLUX.1
|
80 |
<a href="https://fal.ai/dashboard/keys" target="_blank">[GET YOUR API KEY HERE]</a>
|
81 |
</p>
|
82 |
""")
|
@@ -86,19 +105,24 @@ with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
|
86 |
api_key = gr.Textbox(type="password", label="FAL API Key")
|
87 |
model = gr.Dropdown(
|
88 |
label="Model",
|
89 |
-
choices=["Flux Pro", "Flux Dev", "Flux Schnell"],
|
90 |
-
value="Flux
|
91 |
)
|
92 |
prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Add your prompt here")
|
|
|
|
|
|
|
|
|
|
|
93 |
image_size = gr.Dropdown(
|
94 |
-
choices=
|
95 |
-
label="
|
96 |
-
value="
|
97 |
)
|
98 |
|
99 |
with gr.Accordion("Advanced settings", open=False):
|
100 |
-
num_inference_steps = gr.Slider(1, 100, 28, step=1, label="Number of Inference Steps")
|
101 |
-
guidance_scale = gr.Slider(0, 20, 3.5, step=0.1, label="Guidance Scale")
|
102 |
num_images = gr.Slider(1, 10, 1, step=1, label="Number of Images")
|
103 |
safety_tolerance = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6"], label="Safety Tolerance", value="2")
|
104 |
enable_safety_checker = gr.Checkbox(label="Enable Safety Checker", value=True)
|
@@ -109,7 +133,23 @@ with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
|
109 |
with gr.Column(scale=1):
|
110 |
output_gallery = gr.Gallery(label="Generated Images", elem_id="gallery", show_label=False)
|
111 |
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
generate_btn.click(
|
115 |
fn=generate_image,
|
|
|
12 |
def generate_image(api_key, model, prompt, image_size, num_inference_steps, guidance_scale, num_images, safety_tolerance, enable_safety_checker, seed):
|
13 |
set_fal_key(api_key)
|
14 |
|
15 |
+
if model == "Flux Ultra":
|
16 |
+
arguments = {
|
17 |
+
"prompt": prompt,
|
18 |
+
"num_images": num_images,
|
19 |
+
"enable_safety_checker": enable_safety_checker,
|
20 |
+
"safety_tolerance": safety_tolerance,
|
21 |
+
"aspect_ratio": image_size # For Ultra, we pass the aspect ratio directly
|
22 |
+
}
|
23 |
+
fal_model = "fal-ai/flux-pro/v1.1-ultra"
|
24 |
+
else:
|
25 |
+
# Original logic for other models
|
26 |
+
arguments = {
|
27 |
+
"prompt": prompt,
|
28 |
+
"image_size": image_size,
|
29 |
+
"num_inference_steps": num_inference_steps,
|
30 |
+
"num_images": num_images,
|
31 |
+
}
|
32 |
+
|
33 |
+
if model == "Flux Pro":
|
34 |
+
arguments["guidance_scale"] = guidance_scale
|
35 |
+
arguments["safety_tolerance"] = safety_tolerance
|
36 |
+
fal_model = "fal-ai/flux-pro"
|
37 |
+
elif model == "Flux Dev":
|
38 |
+
arguments["guidance_scale"] = guidance_scale
|
39 |
+
arguments["enable_safety_checker"] = enable_safety_checker
|
40 |
+
fal_model = "fal-ai/flux/dev"
|
41 |
+
else: # Flux Schnell
|
42 |
+
arguments["enable_safety_checker"] = enable_safety_checker
|
43 |
+
fal_model = "fal-ai/flux/schnell"
|
44 |
|
45 |
if seed != -1:
|
46 |
arguments["seed"] = seed
|
|
|
56 |
images.append(img)
|
57 |
return images
|
58 |
except Exception as e:
|
59 |
+
print(f"Error: {str(e)}")
|
60 |
return [Image.new('RGB', (512, 512), color='black')]
|
61 |
|
62 |
def update_visible_components(model):
|
63 |
+
if model == "Flux Ultra":
|
64 |
+
return [
|
65 |
+
gr.update(visible=False), # num_inference_steps not used in Ultra
|
66 |
+
gr.update(visible=False), # guidance_scale not used in Ultra
|
67 |
+
gr.update(visible=True, value="2"), # safety_tolerance
|
68 |
+
gr.update(visible=True, value=True) # enable_safety_checker
|
69 |
+
]
|
70 |
+
elif model == "Flux Pro":
|
71 |
return [
|
72 |
gr.update(visible=True, value=28),
|
73 |
gr.update(visible=True, value=3.5),
|
|
|
91 |
|
92 |
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
93 |
gr.HTML("""
|
94 |
+
<h1 align="center">FLUX 1.1 Ultra Image Generation</h1>
|
95 |
<p align="center">
|
96 |
<a href="https://blackforestlabs.ai/" target="_blank">[Black Forest Labs]</a>
|
97 |
<a href="https://blackforestlabs.ai/announcing-black-forest-labs/" target="_blank">[Blog]</a>
|
98 |
+
<a href="https://fal.ai/models/fal-ai/flux-pro/v1.1-ultra" target="_blank">[FLUX 1.1 Ultra Model FAL]</a>
|
99 |
<a href="https://fal.ai/dashboard/keys" target="_blank">[GET YOUR API KEY HERE]</a>
|
100 |
</p>
|
101 |
""")
|
|
|
105 |
api_key = gr.Textbox(type="password", label="FAL API Key")
|
106 |
model = gr.Dropdown(
|
107 |
label="Model",
|
108 |
+
choices=["Flux Ultra", "Flux Pro", "Flux Dev", "Flux Schnell"],
|
109 |
+
value="Flux Ultra"
|
110 |
)
|
111 |
prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Add your prompt here")
|
112 |
+
|
113 |
+
# Different aspect ratio options based on model
|
114 |
+
ultra_sizes = ["21:9", "16:9", "4:3", "1:1", "3:4", "9:16", "9:21"]
|
115 |
+
other_sizes = ["square_hd", "square", "portrait_4_3", "portrait_16_9", "landscape_4_3", "landscape_16_9"]
|
116 |
+
|
117 |
image_size = gr.Dropdown(
|
118 |
+
choices=ultra_sizes,
|
119 |
+
label="Aspect Ratio",
|
120 |
+
value="16:9"
|
121 |
)
|
122 |
|
123 |
with gr.Accordion("Advanced settings", open=False):
|
124 |
+
num_inference_steps = gr.Slider(1, 100, 28, step=1, label="Number of Inference Steps", visible=False)
|
125 |
+
guidance_scale = gr.Slider(0, 20, 3.5, step=0.1, label="Guidance Scale", visible=False)
|
126 |
num_images = gr.Slider(1, 10, 1, step=1, label="Number of Images")
|
127 |
safety_tolerance = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6"], label="Safety Tolerance", value="2")
|
128 |
enable_safety_checker = gr.Checkbox(label="Enable Safety Checker", value=True)
|
|
|
133 |
with gr.Column(scale=1):
|
134 |
output_gallery = gr.Gallery(label="Generated Images", elem_id="gallery", show_label=False)
|
135 |
|
136 |
+
def update_model_options(model):
|
137 |
+
if model == "Flux Ultra":
|
138 |
+
return [
|
139 |
+
gr.update(choices=ultra_sizes, value="16:9", label="Aspect Ratio"),
|
140 |
+
*update_visible_components(model)
|
141 |
+
]
|
142 |
+
else:
|
143 |
+
return [
|
144 |
+
gr.update(choices=other_sizes, value="landscape_16_9", label="Image Size"),
|
145 |
+
*update_visible_components(model)
|
146 |
+
]
|
147 |
+
|
148 |
+
model.change(
|
149 |
+
update_model_options,
|
150 |
+
inputs=[model],
|
151 |
+
outputs=[image_size, num_inference_steps, guidance_scale, safety_tolerance, enable_safety_checker]
|
152 |
+
)
|
153 |
|
154 |
generate_btn.click(
|
155 |
fn=generate_image,
|