Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -41,9 +41,9 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
|
|
41 |
|
42 |
# Handle LoRA loading
|
43 |
# Load LoRA weights and prepare joint_attention_kwargs
|
44 |
-
if lora_id:
|
45 |
pipe.unload_lora_weights()
|
46 |
-
pipe.load_lora_weights(lora_id)
|
47 |
joint_attention_kwargs = {"scale": lora_scale}
|
48 |
else:
|
49 |
joint_attention_kwargs = None
|
@@ -61,7 +61,7 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
|
|
61 |
good_vae=good_vae, # Assuming good_vae is defined elsewhere
|
62 |
joint_attention_kwargs=joint_attention_kwargs, # Fixed parameter name
|
63 |
):
|
64 |
-
yield img, seed
|
65 |
finally:
|
66 |
# Unload LoRA weights if they were loaded
|
67 |
if lora_id:
|
@@ -73,168 +73,181 @@ examples = [
|
|
73 |
"an anime illustration of a wiener schnitzel",
|
74 |
]
|
75 |
|
76 |
-
css="""
|
77 |
-
#col-container {
|
78 |
-
|
79 |
-
|
80 |
-
}
|
81 |
-
"""
|
82 |
|
83 |
-
with gr.Blocks(css=css) as demo:
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
88 |
-
[[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)]
|
89 |
-
|
90 |
|
91 |
-
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
|
101 |
-
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
|
182 |
-
demo.launch()
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
#
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
# with gr.Row():
|
222 |
-
# seed_output = gr.Textbox(label="Seed Used", show_copy_button = True)
|
223 |
|
224 |
-
#
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
|
237 |
-
#
|
238 |
-
#
|
239 |
|
240 |
-
|
|
|
41 |
|
42 |
# Handle LoRA loading
|
43 |
# Load LoRA weights and prepare joint_attention_kwargs
|
44 |
+
if lora_id and lora_id.strip() != "":
|
45 |
pipe.unload_lora_weights()
|
46 |
+
pipe.load_lora_weights(lora_id.strip())
|
47 |
joint_attention_kwargs = {"scale": lora_scale}
|
48 |
else:
|
49 |
joint_attention_kwargs = None
|
|
|
61 |
good_vae=good_vae, # Assuming good_vae is defined elsewhere
|
62 |
joint_attention_kwargs=joint_attention_kwargs, # Fixed parameter name
|
63 |
):
|
64 |
+
yield img, seed, seed
|
65 |
finally:
|
66 |
# Unload LoRA weights if they were loaded
|
67 |
if lora_id:
|
|
|
73 |
"an anime illustration of a wiener schnitzel",
|
74 |
]
|
75 |
|
76 |
+
# css="""
|
77 |
+
# #col-container {
|
78 |
+
# margin: 0 auto;
|
79 |
+
# max-width: 520px;
|
80 |
+
# }
|
81 |
+
# """
|
82 |
|
83 |
+
# with gr.Blocks(css=css) as demo:
|
84 |
|
85 |
+
# with gr.Column(elem_id="col-container"):
|
86 |
+
# gr.Markdown(f"""# FLUX.1 [dev] LoRA
|
87 |
+
# 12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
88 |
+
# [[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)]
|
89 |
+
# """)
|
90 |
|
91 |
+
# with gr.Row():
|
92 |
|
93 |
+
# prompt = gr.Text(
|
94 |
+
# label="Prompt",
|
95 |
+
# show_label=False,
|
96 |
+
# max_lines=1,
|
97 |
+
# placeholder="Enter your prompt",
|
98 |
+
# container=False,
|
99 |
+
# )
|
100 |
|
101 |
+
# run_button = gr.Button("Run", scale=0)
|
102 |
|
103 |
+
# result = gr.Image(label="Result", show_label=False)
|
104 |
|
105 |
+
# with gr.Accordion("Advanced Settings", open=False):
|
106 |
|
107 |
+
# seed = gr.Slider(
|
108 |
+
# label="Seed",
|
109 |
+
# minimum=0,
|
110 |
+
# maximum=MAX_SEED,
|
111 |
+
# step=1,
|
112 |
+
# value=0,
|
113 |
+
# )
|
114 |
|
115 |
+
# randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
116 |
|
117 |
+
# with gr.Row():
|
118 |
|
119 |
+
# width = gr.Slider(
|
120 |
+
# label="Width",
|
121 |
+
# minimum=256,
|
122 |
+
# maximum=MAX_IMAGE_SIZE,
|
123 |
+
# step=8,
|
124 |
+
# value=1024,
|
125 |
+
# )
|
126 |
|
127 |
+
# height = gr.Slider(
|
128 |
+
# label="Height",
|
129 |
+
# minimum=256,
|
130 |
+
# maximum=MAX_IMAGE_SIZE,
|
131 |
+
# step=8,
|
132 |
+
# value=1024,
|
133 |
+
# )
|
134 |
|
135 |
+
# with gr.Row():
|
136 |
+
|
137 |
+
# guidance_scale = gr.Slider(
|
138 |
+
# label="Guidance Scale",
|
139 |
+
# minimum=1,
|
140 |
+
# maximum=15,
|
141 |
+
# step=0.1,
|
142 |
+
# value=3.5,
|
143 |
+
# )
|
144 |
|
145 |
+
# num_inference_steps = gr.Slider(
|
146 |
+
# label="Number of inference steps",
|
147 |
+
# minimum=1,
|
148 |
+
# maximum=50,
|
149 |
+
# step=1,
|
150 |
+
# value=28,
|
151 |
+
# )
|
152 |
+
|
153 |
+
# with gr.Row():
|
154 |
+
# lora_id = gr.Textbox(
|
155 |
+
# label="LoRA Model ID (HuggingFace path)",
|
156 |
+
# placeholder="username/lora-model",
|
157 |
+
# max_lines=1
|
158 |
+
# )
|
159 |
+
# lora_scale = gr.Slider(
|
160 |
+
# label="LoRA Scale",
|
161 |
+
# minimum=0,
|
162 |
+
# maximum=2,
|
163 |
+
# step=0.01,
|
164 |
+
# value=0.95,
|
165 |
+
# )
|
166 |
|
167 |
+
# gr.Examples(
|
168 |
+
# examples = examples,
|
169 |
+
# fn = infer,
|
170 |
+
# inputs = [prompt],
|
171 |
+
# outputs = [result, seed],
|
172 |
+
# cache_examples="lazy"
|
173 |
+
# )
|
174 |
|
175 |
+
# gr.on(
|
176 |
+
# triggers=[run_button.click, prompt.submit],
|
177 |
+
# fn = infer,
|
178 |
+
# inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,lora_id,lora_scale],
|
179 |
+
# outputs = [result, seed]
|
180 |
+
# )
|
181 |
|
182 |
+
# demo.launch()
|
183 |
|
184 |
+
css = """
|
185 |
+
#col-container {
|
186 |
+
margin: 0 auto;
|
187 |
+
max-width: 960px;
|
188 |
+
}
|
189 |
+
.generate-btn {
|
190 |
+
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%) !important;
|
191 |
+
border: none !important;
|
192 |
+
color: white !important;
|
193 |
+
}
|
194 |
+
.generate-btn:hover {
|
195 |
+
transform: translateY(-2px);
|
196 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
197 |
+
}
|
198 |
+
"""
|
199 |
|
200 |
+
with gr.Blocks(css=css) as app:
|
201 |
+
gr.HTML("<center><h1>FLUX.1-Dev with LoRA support</h1></center>")
|
202 |
+
with gr.Column(elem_id="col-container"):
|
203 |
+
with gr.Row():
|
204 |
+
with gr.Column():
|
205 |
+
with gr.Row():
|
206 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
|
207 |
+
with gr.Row():
|
208 |
+
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux")
|
209 |
+
with gr.Row():
|
210 |
+
with gr.Accordion("Advanced Settings", open=False):
|
211 |
+
lora_scale = gr.Slider(
|
212 |
+
label="LoRA Scale",
|
213 |
+
minimum=0,
|
214 |
+
maximum=2,
|
215 |
+
step=0.01,
|
216 |
+
value=0.95,
|
217 |
+
)
|
218 |
+
with gr.Row():
|
219 |
+
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=8)
|
220 |
+
height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=8)
|
221 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=4294967296, step=1)
|
222 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
223 |
+
with gr.Row():
|
224 |
+
steps = gr.Slider(label="Inference steps steps", value=28, minimum=1, maximum=100, step=1)
|
225 |
+
cfg = gr.Slider(label="Guidance Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
226 |
+
# method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
227 |
+
|
228 |
+
with gr.Row():
|
229 |
+
# text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
230 |
+
text_button = gr.Button("✨ Generate Image", variant='primary', elem_classes=["generate-btn"])
|
231 |
+
with gr.Column():
|
232 |
+
with gr.Row():
|
233 |
+
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
234 |
+
with gr.Row():
|
235 |
+
seed_output = gr.Textbox(label="Seed Used", show_copy_button = True)
|
|
|
|
|
236 |
|
237 |
+
# gr.Markdown(article_text)
|
238 |
+
with gr.Column():
|
239 |
+
gr.Examples(
|
240 |
+
examples = examples,
|
241 |
+
inputs = [text_prompt],
|
242 |
+
)
|
243 |
+
gr.on(
|
244 |
+
triggers=[text_button.click, text_prompt.submit],
|
245 |
+
fn = infer,
|
246 |
+
inputs=[text_prompt, seed, randomize_seed, width, height, cfg, steps, custom_lora, lora_scale],
|
247 |
+
outputs=[image_output,seed_output, seed]
|
248 |
+
)
|
249 |
|
250 |
+
# text_button.click(query, inputs=[custom_lora, text_prompt, steps, cfg, randomize_seed, seed, width, height], outputs=[image_output,seed_output, seed])
|
251 |
+
# text_button.click(infer, inputs=[text_prompt, seed, randomize_seed, width, height, cfg, steps, custom_lora, lora_scale], outputs=[image_output,seed_output, seed])
|
252 |
|
253 |
+
app.launch(share=True)
|