Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
#2
by
linoyts
HF Staff
- opened
app.py
CHANGED
@@ -137,6 +137,17 @@ Return only the rewritten instruction text directly, without JSON formatting or
|
|
137 |
MAX_SEED = np.iinfo(np.int32).max
|
138 |
MAX_IMAGE_SIZE = 2048
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
# Initialize Qwen Image Edit pipeline
|
141 |
# Scheduler configuration for Lightning
|
142 |
scheduler_config = {
|
@@ -278,7 +289,10 @@ with gr.Blocks(css=css) as demo:
|
|
278 |
)
|
279 |
run_button = gr.Button("Run")
|
280 |
|
281 |
-
|
|
|
|
|
|
|
282 |
|
283 |
with gr.Accordion("Advanced Settings", open=False):
|
284 |
|
@@ -324,11 +338,30 @@ with gr.Blocks(css=css) as demo:
|
|
324 |
value=True
|
325 |
)
|
326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
gr.on(
|
328 |
triggers=[run_button.click, prompt.submit],
|
|
|
|
|
|
|
|
|
|
|
329 |
fn = infer,
|
330 |
inputs = [edit_image, prompt, negative_prompt, seed, randomize_seed, strength, num_inference_steps, true_cfg_scale, rewrite_prompt],
|
331 |
outputs = [result, seed]
|
|
|
|
|
|
|
|
|
|
|
332 |
)
|
333 |
|
334 |
demo.launch()
|
|
|
137 |
MAX_SEED = np.iinfo(np.int32).max
|
138 |
MAX_IMAGE_SIZE = 2048
|
139 |
|
140 |
+
# --- Helper functions for reuse feature ---
|
141 |
+
def clear_result():
|
142 |
+
"""Clears the result image."""
|
143 |
+
return gr.update(value=None)
|
144 |
+
|
145 |
+
def use_output_as_input(output_image):
|
146 |
+
"""Sets the generated output as the new input image."""
|
147 |
+
if output_image is not None:
|
148 |
+
return gr.update(value=output_image)
|
149 |
+
return gr.update()
|
150 |
+
|
151 |
# Initialize Qwen Image Edit pipeline
|
152 |
# Scheduler configuration for Lightning
|
153 |
scheduler_config = {
|
|
|
289 |
)
|
290 |
run_button = gr.Button("Run")
|
291 |
|
292 |
+
with gr.Column():
|
293 |
+
result = gr.ImageSlider(label="Result", show_label=False)
|
294 |
+
|
295 |
+
use_as_input_button = gr.Button("🔄 Use as Input Image", visible=False, variant="secondary")
|
296 |
|
297 |
with gr.Accordion("Advanced Settings", open=False):
|
298 |
|
|
|
338 |
value=True
|
339 |
)
|
340 |
|
341 |
+
# Event handlers for reuse functionality
|
342 |
+
use_as_input_button.click(
|
343 |
+
fn=use_output_as_input,
|
344 |
+
inputs=[result],
|
345 |
+
outputs=[edit_image],
|
346 |
+
show_api=False
|
347 |
+
)
|
348 |
+
|
349 |
+
# Main generation pipeline with result clearing and button visibility
|
350 |
gr.on(
|
351 |
triggers=[run_button.click, prompt.submit],
|
352 |
+
fn=clear_result,
|
353 |
+
inputs=None,
|
354 |
+
outputs=result,
|
355 |
+
show_api=False
|
356 |
+
).then(
|
357 |
fn = infer,
|
358 |
inputs = [edit_image, prompt, negative_prompt, seed, randomize_seed, strength, num_inference_steps, true_cfg_scale, rewrite_prompt],
|
359 |
outputs = [result, seed]
|
360 |
+
).then(
|
361 |
+
fn=lambda: gr.update(visible=True),
|
362 |
+
inputs=None,
|
363 |
+
outputs=use_as_input_button,
|
364 |
+
show_api=False
|
365 |
)
|
366 |
|
367 |
demo.launch()
|