Spaces:
Running
on
Zero
Running
on
Zero
hi
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ def generate_vstack_from_image(image: Image.Image, input_focal_position: int, nu
|
|
| 41 |
if not first_frame.exists():
|
| 42 |
raise gr.Error("frame_0.png not found in output_dir")
|
| 43 |
|
| 44 |
-
#
|
| 45 |
return str(first_frame), gr.update(value=0)
|
| 46 |
|
| 47 |
def show_frame(idx: int):
|
|
@@ -51,15 +51,12 @@ def show_frame(idx: int):
|
|
| 51 |
return str(path)
|
| 52 |
|
| 53 |
def advance_frame(idx: int, autoplay: bool):
|
| 54 |
-
# If autoplay is off, don't change anything.
|
| 55 |
if not autoplay:
|
| 56 |
-
# keep slider value, keep image (returning None keeps the current image)
|
| 57 |
return gr.update(value=int(idx)), gr.update()
|
| 58 |
|
| 59 |
next_idx = (int(idx) + 1) % NUM_FRAMES
|
| 60 |
next_path = OUTPUT_DIR / f"frame_{next_idx}.png"
|
| 61 |
if not next_path.exists():
|
| 62 |
-
# If frames aren't ready yet, hold.
|
| 63 |
return gr.update(value=int(idx)), gr.update()
|
| 64 |
|
| 65 |
return gr.update(value=next_idx), str(next_path)
|
|
@@ -68,7 +65,7 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
| 68 |
gr.Markdown(
|
| 69 |
"""
|
| 70 |
# 🖼️ ➜ 🎬 Generate Focal Stacks from a Single Image
|
| 71 |
-
Generate a focal stack and scrub through frames
|
| 72 |
"""
|
| 73 |
)
|
| 74 |
|
|
@@ -93,8 +90,6 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
| 93 |
info="More steps = better quality but slower",
|
| 94 |
)
|
| 95 |
|
| 96 |
-
autoplay = gr.Checkbox(value=True, label="Autoplay")
|
| 97 |
-
|
| 98 |
generate_btn = gr.Button("Generate stack", variant="primary")
|
| 99 |
|
| 100 |
with gr.Column():
|
|
@@ -105,10 +100,11 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
| 105 |
maximum=NUM_FRAMES - 1,
|
| 106 |
step=1,
|
| 107 |
value=0,
|
| 108 |
-
label="
|
| 109 |
)
|
| 110 |
|
| 111 |
-
|
|
|
|
| 112 |
generate_btn.click(
|
| 113 |
fn=generate_vstack_from_image,
|
| 114 |
inputs=[image_in, input_focal_position, num_inference_steps],
|
|
@@ -116,14 +112,12 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
| 116 |
api_name="predict",
|
| 117 |
)
|
| 118 |
|
| 119 |
-
# Manual scrubbing
|
| 120 |
frame_slider.change(
|
| 121 |
fn=show_frame,
|
| 122 |
inputs=frame_slider,
|
| 123 |
outputs=frame_view,
|
| 124 |
)
|
| 125 |
|
| 126 |
-
# Autoplay loop (can be toggled off via checkbox)
|
| 127 |
timer = gr.Timer(LOOP_MS)
|
| 128 |
timer.tick(
|
| 129 |
fn=advance_frame,
|
|
|
|
| 41 |
if not first_frame.exists():
|
| 42 |
raise gr.Error("frame_0.png not found in output_dir")
|
| 43 |
|
| 44 |
+
# Show first frame + reset slider
|
| 45 |
return str(first_frame), gr.update(value=0)
|
| 46 |
|
| 47 |
def show_frame(idx: int):
|
|
|
|
| 51 |
return str(path)
|
| 52 |
|
| 53 |
def advance_frame(idx: int, autoplay: bool):
|
|
|
|
| 54 |
if not autoplay:
|
|
|
|
| 55 |
return gr.update(value=int(idx)), gr.update()
|
| 56 |
|
| 57 |
next_idx = (int(idx) + 1) % NUM_FRAMES
|
| 58 |
next_path = OUTPUT_DIR / f"frame_{next_idx}.png"
|
| 59 |
if not next_path.exists():
|
|
|
|
| 60 |
return gr.update(value=int(idx)), gr.update()
|
| 61 |
|
| 62 |
return gr.update(value=next_idx), str(next_path)
|
|
|
|
| 65 |
gr.Markdown(
|
| 66 |
"""
|
| 67 |
# 🖼️ ➜ 🎬 Generate Focal Stacks from a Single Image
|
| 68 |
+
Generate a focal stack and scrub through frames. Toggle autoplay on the output panel.
|
| 69 |
"""
|
| 70 |
)
|
| 71 |
|
|
|
|
| 90 |
info="More steps = better quality but slower",
|
| 91 |
)
|
| 92 |
|
|
|
|
|
|
|
| 93 |
generate_btn = gr.Button("Generate stack", variant="primary")
|
| 94 |
|
| 95 |
with gr.Column():
|
|
|
|
| 100 |
maximum=NUM_FRAMES - 1,
|
| 101 |
step=1,
|
| 102 |
value=0,
|
| 103 |
+
label="Output Focus Position",
|
| 104 |
)
|
| 105 |
|
| 106 |
+
autoplay = gr.Checkbox(value=True, label="Autoplay")
|
| 107 |
+
|
| 108 |
generate_btn.click(
|
| 109 |
fn=generate_vstack_from_image,
|
| 110 |
inputs=[image_in, input_focal_position, num_inference_steps],
|
|
|
|
| 112 |
api_name="predict",
|
| 113 |
)
|
| 114 |
|
|
|
|
| 115 |
frame_slider.change(
|
| 116 |
fn=show_frame,
|
| 117 |
inputs=frame_slider,
|
| 118 |
outputs=frame_view,
|
| 119 |
)
|
| 120 |
|
|
|
|
| 121 |
timer = gr.Timer(LOOP_MS)
|
| 122 |
timer.tick(
|
| 123 |
fn=advance_frame,
|