Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -63,7 +63,7 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
|
|
63 |
good_vae=good_vae, # Assuming good_vae is defined elsewhere
|
64 |
joint_attention_kwargs=joint_attention_kwargs, # Fixed parameter name
|
65 |
):
|
66 |
-
yield img, seed
|
67 |
finally:
|
68 |
# Unload LoRA weights if they were loaded
|
69 |
if lora_id:
|
@@ -93,57 +93,159 @@ css = """
|
|
93 |
}
|
94 |
"""
|
95 |
|
96 |
-
with gr.Blocks(css=css) as app:
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
with gr.Column(elem_id="col-container"):
|
|
|
|
|
|
|
|
|
|
|
99 |
with gr.Row():
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
value=0.95,
|
113 |
-
)
|
114 |
-
with gr.Row():
|
115 |
-
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=8)
|
116 |
-
height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=8)
|
117 |
-
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=4294967296, step=1)
|
118 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
119 |
-
with gr.Row():
|
120 |
-
steps = gr.Slider(label="Inference steps steps", value=28, minimum=1, maximum=100, step=1)
|
121 |
-
cfg = gr.Slider(label="Guidance Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
122 |
-
# method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
123 |
-
|
124 |
-
with gr.Row():
|
125 |
-
# text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
126 |
-
text_button = gr.Button("✨ Generate Image", variant='primary', elem_classes=["generate-btn"])
|
127 |
-
with gr.Column():
|
128 |
-
with gr.Row():
|
129 |
-
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
130 |
-
with gr.Row():
|
131 |
-
seed_output = gr.Textbox(label="Seed Used", show_copy_button = True)
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
gr.
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
138 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
gr.on(
|
140 |
-
triggers=[
|
141 |
fn = infer,
|
142 |
-
inputs=[
|
143 |
-
outputs=[
|
144 |
)
|
145 |
-
|
146 |
-
# text_button.click(query, inputs=[custom_lora, text_prompt, steps, cfg, randomize_seed, seed, width, height], outputs=[image_output,seed_output, seed])
|
147 |
-
# text_button.click(infer, inputs=[text_prompt, seed, randomize_seed, width, height, cfg, steps, custom_lora, lora_scale], outputs=[image_output,seed_output, seed])
|
148 |
|
149 |
-
|
|
|
63 |
good_vae=good_vae, # Assuming good_vae is defined elsewhere
|
64 |
joint_attention_kwargs=joint_attention_kwargs, # Fixed parameter name
|
65 |
):
|
66 |
+
yield img, seed
|
67 |
finally:
|
68 |
# Unload LoRA weights if they were loaded
|
69 |
if lora_id:
|
|
|
93 |
}
|
94 |
"""
|
95 |
|
96 |
+
# with gr.Blocks(css=css) as app:
|
97 |
+
# gr.HTML("<center><h1>FLUX.1-Dev with LoRA support</h1></center>")
|
98 |
+
# with gr.Column(elem_id="col-container"):
|
99 |
+
# with gr.Row():
|
100 |
+
# with gr.Column():
|
101 |
+
# with gr.Row():
|
102 |
+
# text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
|
103 |
+
# with gr.Row():
|
104 |
+
# custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux")
|
105 |
+
# with gr.Row():
|
106 |
+
# with gr.Accordion("Advanced Settings", open=False):
|
107 |
+
# lora_scale = gr.Slider(
|
108 |
+
# label="LoRA Scale",
|
109 |
+
# minimum=0,
|
110 |
+
# maximum=2,
|
111 |
+
# step=0.01,
|
112 |
+
# value=0.95,
|
113 |
+
# )
|
114 |
+
# with gr.Row():
|
115 |
+
# width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=8)
|
116 |
+
# height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=8)
|
117 |
+
# seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=4294967296, step=1)
|
118 |
+
# randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
119 |
+
# with gr.Row():
|
120 |
+
# steps = gr.Slider(label="Inference steps steps", value=28, minimum=1, maximum=100, step=1)
|
121 |
+
# cfg = gr.Slider(label="Guidance Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
122 |
+
# # method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
123 |
+
|
124 |
+
# with gr.Row():
|
125 |
+
# # text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
126 |
+
# text_button = gr.Button("✨ Generate Image", variant='primary', elem_classes=["generate-btn"])
|
127 |
+
# with gr.Column():
|
128 |
+
# with gr.Row():
|
129 |
+
# image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
130 |
+
# with gr.Row():
|
131 |
+
# seed_output = gr.Textbox(label="Seed Used", show_copy_button = True)
|
132 |
+
|
133 |
+
# # gr.Markdown(article_text)
|
134 |
+
# with gr.Column():
|
135 |
+
# gr.Examples(
|
136 |
+
# examples = examples,
|
137 |
+
# inputs = [text_prompt],
|
138 |
+
# )
|
139 |
+
# gr.on(
|
140 |
+
# triggers=[text_button.click, text_prompt.submit],
|
141 |
+
# fn = infer,
|
142 |
+
# inputs=[text_prompt, seed, randomize_seed, width, height, cfg, steps, custom_lora, lora_scale],
|
143 |
+
# outputs=[image_output,seed_output, seed]
|
144 |
+
# )
|
145 |
+
|
146 |
+
# # text_button.click(query, inputs=[custom_lora, text_prompt, steps, cfg, randomize_seed, seed, width, height], outputs=[image_output,seed_output, seed])
|
147 |
+
# # text_button.click(infer, inputs=[text_prompt, seed, randomize_seed, width, height, cfg, steps, custom_lora, lora_scale], outputs=[image_output,seed_output, seed])
|
148 |
+
|
149 |
+
# app.launch(share=True)
|
150 |
+
|
151 |
+
|
152 |
+
with gr.Blocks(css=css) as demo:
|
153 |
+
|
154 |
with gr.Column(elem_id="col-container"):
|
155 |
+
gr.Markdown(f"""# FLUX.1 [dev] LoRA
|
156 |
+
12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
157 |
+
[[non-commercial license](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)] [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-dev)]
|
158 |
+
""")
|
159 |
+
|
160 |
with gr.Row():
|
161 |
+
|
162 |
+
prompt = gr.Text(
|
163 |
+
label="Prompt",
|
164 |
+
show_label=False,
|
165 |
+
max_lines=1,
|
166 |
+
placeholder="Enter your prompt",
|
167 |
+
container=False,
|
168 |
+
)
|
169 |
+
|
170 |
+
run_button = gr.Button("Run", scale=0)
|
171 |
+
|
172 |
+
result = gr.Image(label="Result", show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
+
with gr.Accordion("Advanced Settings", open=False):
|
175 |
+
|
176 |
+
seed = gr.Slider(
|
177 |
+
label="Seed",
|
178 |
+
minimum=0,
|
179 |
+
maximum=MAX_SEED,
|
180 |
+
step=1,
|
181 |
+
value=0,
|
182 |
)
|
183 |
+
|
184 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
185 |
+
|
186 |
+
with gr.Row():
|
187 |
+
|
188 |
+
width = gr.Slider(
|
189 |
+
label="Width",
|
190 |
+
minimum=256,
|
191 |
+
maximum=MAX_IMAGE_SIZE,
|
192 |
+
step=8,
|
193 |
+
value=1024,
|
194 |
+
)
|
195 |
+
|
196 |
+
height = gr.Slider(
|
197 |
+
label="Height",
|
198 |
+
minimum=256,
|
199 |
+
maximum=MAX_IMAGE_SIZE,
|
200 |
+
step=8,
|
201 |
+
value=1024,
|
202 |
+
)
|
203 |
+
|
204 |
+
with gr.Row():
|
205 |
+
|
206 |
+
guidance_scale = gr.Slider(
|
207 |
+
label="Guidance Scale",
|
208 |
+
minimum=1,
|
209 |
+
maximum=15,
|
210 |
+
step=0.1,
|
211 |
+
value=3.5,
|
212 |
+
)
|
213 |
+
|
214 |
+
num_inference_steps = gr.Slider(
|
215 |
+
label="Number of inference steps",
|
216 |
+
minimum=1,
|
217 |
+
maximum=50,
|
218 |
+
step=1,
|
219 |
+
value=28,
|
220 |
+
)
|
221 |
+
|
222 |
+
with gr.Row():
|
223 |
+
lora_id = gr.Textbox(
|
224 |
+
label="LoRA Model ID (HuggingFace path)",
|
225 |
+
placeholder="username/lora-model",
|
226 |
+
max_lines=1
|
227 |
+
)
|
228 |
+
lora_scale = gr.Slider(
|
229 |
+
label="LoRA Scale",
|
230 |
+
minimum=0,
|
231 |
+
maximum=2,
|
232 |
+
step=0.01,
|
233 |
+
value=0.95,
|
234 |
+
)
|
235 |
+
|
236 |
+
gr.Examples(
|
237 |
+
examples = examples,
|
238 |
+
fn = infer,
|
239 |
+
inputs = [prompt],
|
240 |
+
outputs = [result, seed],
|
241 |
+
cache_examples="lazy"
|
242 |
+
)
|
243 |
+
|
244 |
gr.on(
|
245 |
+
triggers=[run_button.click, prompt.submit],
|
246 |
fn = infer,
|
247 |
+
inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,lora_id,lora_scale],
|
248 |
+
outputs = [result, seed]
|
249 |
)
|
|
|
|
|
|
|
250 |
|
251 |
+
demo.launch()
|