Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,19 @@ import gradio as gr
|
|
2 |
from pathlib import Path
|
3 |
import subprocess
|
4 |
|
5 |
-
# Paths
|
6 |
-
FRAME1 = Path("demo/frame1.jpg")
|
7 |
-
FRAME2 = Path("demo/frame2.jpg")
|
8 |
OUTPUT_GIF = Path("demo/demo.gif")
|
9 |
|
10 |
-
def generate_demo_gif():
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
try:
|
12 |
result = subprocess.run([
|
13 |
"python", "inference_img.py",
|
14 |
-
"--img", str(
|
15 |
"--exp=4"
|
16 |
], capture_output=True, text=True)
|
17 |
|
@@ -21,20 +24,24 @@ def generate_demo_gif():
|
|
21 |
if result.returncode == 0 and OUTPUT_GIF.exists():
|
22 |
return OUTPUT_GIF
|
23 |
else:
|
24 |
-
return
|
25 |
except Exception as e:
|
26 |
print(f"Error: {e}")
|
27 |
-
return
|
28 |
-
|
29 |
-
def demo_tab():
|
30 |
-
gif_path = generate_demo_gif()
|
31 |
-
if gif_path:
|
32 |
-
return gif_path
|
33 |
-
else:
|
34 |
-
return "GIF generation failed."
|
35 |
|
36 |
with gr.Blocks() as demo_ui:
|
37 |
with gr.Tab("Demo"):
|
38 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
demo_ui.launch()
|
|
|
2 |
from pathlib import Path
|
3 |
import subprocess
|
4 |
|
|
|
|
|
|
|
5 |
OUTPUT_GIF = Path("demo/demo.gif")
|
6 |
|
7 |
+
def generate_demo_gif(img1, img2):
|
8 |
+
# Save uploaded images
|
9 |
+
frame1_path = Path("demo/frame1.jpg")
|
10 |
+
frame2_path = Path("demo/frame2.jpg")
|
11 |
+
img1.save(frame1_path)
|
12 |
+
img2.save(frame2_path)
|
13 |
+
|
14 |
try:
|
15 |
result = subprocess.run([
|
16 |
"python", "inference_img.py",
|
17 |
+
"--img", str(frame1_path), str(frame2_path),
|
18 |
"--exp=4"
|
19 |
], capture_output=True, text=True)
|
20 |
|
|
|
24 |
if result.returncode == 0 and OUTPUT_GIF.exists():
|
25 |
return OUTPUT_GIF
|
26 |
else:
|
27 |
+
return "GIF generation failed."
|
28 |
except Exception as e:
|
29 |
print(f"Error: {e}")
|
30 |
+
return "Error during GIF generation."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
with gr.Blocks() as demo_ui:
|
33 |
with gr.Tab("Demo"):
|
34 |
+
gr.Markdown("### Upload two frames to generate a GIF")
|
35 |
+
with gr.Row():
|
36 |
+
img1_input = gr.Image(type="pil", label="Frame 1")
|
37 |
+
img2_input = gr.Image(type="pil", label="Frame 2")
|
38 |
+
generate_btn = gr.Button("Generate GIF")
|
39 |
+
output_gif = gr.Image(label="Generated GIF")
|
40 |
+
|
41 |
+
generate_btn.click(
|
42 |
+
fn=generate_demo_gif,
|
43 |
+
inputs=[img1_input, img2_input],
|
44 |
+
outputs=output_gif
|
45 |
+
)
|
46 |
|
47 |
demo_ui.launch()
|