Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import spaces
|
|
4 |
import torch
|
5 |
import random
|
6 |
import os
|
7 |
-
import time
|
8 |
|
9 |
# from diffusers import QwenImageEditInpaintPipeline
|
10 |
from optimization import optimize_pipeline_
|
@@ -143,26 +142,6 @@ def clear_result():
|
|
143 |
"""Clears the result image."""
|
144 |
return gr.update(value=None)
|
145 |
|
146 |
-
def update_history(new_image, history):
|
147 |
-
"""Updates the history gallery with the new image."""
|
148 |
-
time.sleep(0.5) # Small delay to ensure image is ready
|
149 |
-
if history is None:
|
150 |
-
history = []
|
151 |
-
if new_image is not None:
|
152 |
-
# Convert to list if needed (Gradio sometimes returns tuples)
|
153 |
-
if not isinstance(history, list):
|
154 |
-
history = list(history) if history else []
|
155 |
-
history.insert(0, new_image)
|
156 |
-
# Keep only the last 20 images in history
|
157 |
-
history = history[:20]
|
158 |
-
return history
|
159 |
-
|
160 |
-
def use_history_as_input(evt: gr.SelectData, history):
|
161 |
-
"""Sets the selected history image as the new input image."""
|
162 |
-
if history and evt.index < len(history):
|
163 |
-
return gr.update(value=history[evt.index][0])
|
164 |
-
return gr.update()
|
165 |
-
|
166 |
def use_output_as_input(output_image):
|
167 |
"""Sets the generated output as the new input image."""
|
168 |
if output_image is not None:
|
@@ -262,9 +241,6 @@ css = """
|
|
262 |
width: 400px;
|
263 |
}
|
264 |
#edit_text{margin-top: -62px !important}
|
265 |
-
.gallery-container {
|
266 |
-
margin-top: 20px;
|
267 |
-
}
|
268 |
"""
|
269 |
|
270 |
|
@@ -317,23 +293,6 @@ with gr.Blocks(css=css) as demo:
|
|
317 |
result = gr.ImageSlider(label="Result", show_label=False)
|
318 |
|
319 |
use_as_input_button = gr.Button("🔄 Use as Input Image", visible=False, variant="secondary")
|
320 |
-
|
321 |
-
gr.Markdown("---")
|
322 |
-
|
323 |
-
with gr.Row():
|
324 |
-
gr.Markdown("### 📜 History")
|
325 |
-
clear_history_button = gr.Button("🗑️ Clear History", size="sm", variant="stop")
|
326 |
-
|
327 |
-
history_gallery = gr.Gallery(
|
328 |
-
label="Click any image to use as input",
|
329 |
-
columns=4,
|
330 |
-
rows=2,
|
331 |
-
object_fit="contain",
|
332 |
-
height="auto",
|
333 |
-
interactive=False,
|
334 |
-
show_label=True,
|
335 |
-
elem_classes=["gallery-container"]
|
336 |
-
)
|
337 |
|
338 |
with gr.Accordion("Advanced Settings", open=False):
|
339 |
|
@@ -386,22 +345,8 @@ with gr.Blocks(css=css) as demo:
|
|
386 |
outputs=[edit_image],
|
387 |
show_api=False
|
388 |
)
|
389 |
-
|
390 |
-
history_gallery.select(
|
391 |
-
fn=use_history_as_input,
|
392 |
-
inputs=[history_gallery],
|
393 |
-
outputs=[edit_image],
|
394 |
-
show_api=False
|
395 |
-
)
|
396 |
-
|
397 |
-
clear_history_button.click(
|
398 |
-
fn=lambda: [],
|
399 |
-
inputs=None,
|
400 |
-
outputs=history_gallery,
|
401 |
-
show_api=False
|
402 |
-
)
|
403 |
|
404 |
-
# Main generation pipeline with result clearing
|
405 |
gr.on(
|
406 |
triggers=[run_button.click, prompt.submit],
|
407 |
fn=clear_result,
|
@@ -417,11 +362,6 @@ with gr.Blocks(css=css) as demo:
|
|
417 |
inputs=None,
|
418 |
outputs=use_as_input_button,
|
419 |
show_api=False
|
420 |
-
).then(
|
421 |
-
fn=update_history,
|
422 |
-
inputs=[result, history_gallery],
|
423 |
-
outputs=history_gallery,
|
424 |
-
show_api=False
|
425 |
)
|
426 |
|
427 |
demo.launch()
|
|
|
4 |
import torch
|
5 |
import random
|
6 |
import os
|
|
|
7 |
|
8 |
# from diffusers import QwenImageEditInpaintPipeline
|
9 |
from optimization import optimize_pipeline_
|
|
|
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:
|
|
|
241 |
width: 400px;
|
242 |
}
|
243 |
#edit_text{margin-top: -62px !important}
|
|
|
|
|
|
|
244 |
"""
|
245 |
|
246 |
|
|
|
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 |
|
|
|
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,
|
|
|
362 |
inputs=None,
|
363 |
outputs=use_as_input_button,
|
364 |
show_api=False
|
|
|
|
|
|
|
|
|
|
|
365 |
)
|
366 |
|
367 |
demo.launch()
|