Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,56 +5,56 @@ import gradio as gr
|
|
5 |
from PIL import Image
|
6 |
import io
|
7 |
|
8 |
-
#
|
9 |
-
FRAME1_PATH =
|
10 |
-
FRAME2_PATH =
|
11 |
-
OUTPUT_GIF =
|
12 |
|
13 |
def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
14 |
-
progress(0.
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
# Build
|
21 |
cmd = [
|
22 |
"python", "inference_img.py",
|
23 |
-
"--img",
|
24 |
-
|
25 |
"--model", "train_log/"
|
26 |
]
|
27 |
print("Running:", " ".join(cmd))
|
28 |
-
progress(0.25, desc="Running model")
|
29 |
-
|
30 |
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
|
31 |
print("STDOUT:", result.stdout)
|
32 |
print("STDERR:", result.stderr)
|
33 |
|
34 |
-
# Check result
|
35 |
-
if result.returncode == 0 and
|
36 |
-
progress(0.85, desc="Loading GIF")
|
37 |
with open(OUTPUT_GIF, "rb") as f:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
return image, "β
GIF generated successfully!"
|
42 |
else:
|
43 |
-
return None, "β
|
44 |
|
45 |
-
#
|
46 |
with gr.Blocks() as demo_ui:
|
47 |
-
gr.Markdown("##
|
48 |
|
49 |
with gr.Row():
|
50 |
-
|
51 |
-
|
52 |
|
53 |
exp = gr.Slider(1, 4, value=2, step=1, label="Interpolation Exponent")
|
54 |
run_btn = gr.Button("Generate GIF")
|
55 |
-
out_gif = gr.Image(label="
|
56 |
status = gr.Markdown()
|
57 |
|
58 |
run_btn.click(fn=generate_demo_gif, inputs=[exp], outputs=[out_gif, status])
|
59 |
|
|
|
60 |
demo_ui.launch()
|
|
|
5 |
from PIL import Image
|
6 |
import io
|
7 |
|
8 |
+
# Fixed input paths and output location
|
9 |
+
FRAME1_PATH = "demo/frame1.png"
|
10 |
+
FRAME2_PATH = "demo/frame2.png"
|
11 |
+
OUTPUT_GIF = "/tmp/output.gif"
|
12 |
|
13 |
def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
14 |
+
progress(0.1, desc="Starting inference...")
|
15 |
|
16 |
+
# Delete old output if exists
|
17 |
+
try:
|
18 |
+
os.remove(OUTPUT_GIF)
|
19 |
+
except FileNotFoundError:
|
20 |
+
pass
|
21 |
|
22 |
+
# Build and run command
|
23 |
cmd = [
|
24 |
"python", "inference_img.py",
|
25 |
+
"--img", FRAME1_PATH, FRAME2_PATH,
|
26 |
+
"--exp", str(exp),
|
27 |
"--model", "train_log/"
|
28 |
]
|
29 |
print("Running:", " ".join(cmd))
|
|
|
|
|
30 |
result = subprocess.run(cmd, capture_output=True, text=True)
|
31 |
+
|
32 |
print("STDOUT:", result.stdout)
|
33 |
print("STDERR:", result.stderr)
|
34 |
|
35 |
+
# Check and display result
|
36 |
+
if result.returncode == 0 and os.path.exists(OUTPUT_GIF):
|
|
|
37 |
with open(OUTPUT_GIF, "rb") as f:
|
38 |
+
gif = Image.open(io.BytesIO(f.read()))
|
39 |
+
progress(1.0, desc="GIF created!")
|
40 |
+
return gif, "β
Done!"
|
|
|
41 |
else:
|
42 |
+
return None, "β Inference failed or output missing"
|
43 |
|
44 |
+
# UI setup
|
45 |
with gr.Blocks() as demo_ui:
|
46 |
+
gr.Markdown("## ποΈ Demo GIF Generator β Interpolate Two Frames")
|
47 |
|
48 |
with gr.Row():
|
49 |
+
gr.Image(value=FRAME1_PATH, label="Frame 1", interactive=False)
|
50 |
+
gr.Image(value=FRAME2_PATH, label="Frame 2", interactive=False)
|
51 |
|
52 |
exp = gr.Slider(1, 4, value=2, step=1, label="Interpolation Exponent")
|
53 |
run_btn = gr.Button("Generate GIF")
|
54 |
+
out_gif = gr.Image(label="Output GIF")
|
55 |
status = gr.Markdown()
|
56 |
|
57 |
run_btn.click(fn=generate_demo_gif, inputs=[exp], outputs=[out_gif, status])
|
58 |
|
59 |
+
# Launch the app
|
60 |
demo_ui.launch()
|