Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,20 +2,23 @@ import gradio as gr
|
|
2 |
from pathlib import Path
|
3 |
import subprocess
|
4 |
from inference_img import *
|
|
|
5 |
|
|
|
6 |
OUTPUT_GIF = Path("demo/output.gif")
|
|
|
|
|
7 |
|
|
|
8 |
def generate_demo_gif(img1, img2):
|
9 |
# Save uploaded images
|
10 |
-
|
11 |
-
|
12 |
-
img1.save(frame1_path)
|
13 |
-
img2.save(frame2_path)
|
14 |
|
15 |
try:
|
16 |
result = subprocess.run([
|
17 |
"python", "inference_img.py",
|
18 |
-
"--img", str(
|
19 |
"--exp=4",
|
20 |
"--model", "train_log/"
|
21 |
], capture_output=True, text=True)
|
@@ -24,13 +27,15 @@ def generate_demo_gif(img1, img2):
|
|
24 |
print("STDERR:", result.stderr)
|
25 |
|
26 |
if result.returncode == 0 and OUTPUT_GIF.exists():
|
27 |
-
return OUTPUT_GIF
|
28 |
else:
|
29 |
-
return "GIF generation failed."
|
|
|
30 |
except Exception as e:
|
31 |
print(f"Error: {e}")
|
32 |
-
return "
|
33 |
|
|
|
34 |
with gr.Blocks() as demo_ui:
|
35 |
with gr.Tab("Demo"):
|
36 |
gr.Markdown("### Upload two frames to generate a GIF")
|
@@ -39,11 +44,12 @@ with gr.Blocks() as demo_ui:
|
|
39 |
img2_input = gr.Image(type="pil", label="Frame 2")
|
40 |
generate_btn = gr.Button("Generate GIF")
|
41 |
output_gif = gr.Image(label="Generated GIF")
|
|
|
42 |
|
43 |
generate_btn.click(
|
44 |
fn=generate_demo_gif,
|
45 |
inputs=[img1_input, img2_input],
|
46 |
-
outputs=output_gif
|
47 |
)
|
48 |
|
49 |
demo_ui.launch()
|
|
|
2 |
from pathlib import Path
|
3 |
import subprocess
|
4 |
from inference_img import *
|
5 |
+
import spaces
|
6 |
|
7 |
+
# Constants
|
8 |
OUTPUT_GIF = Path("demo/output.gif")
|
9 |
+
FRAME1_PATH = Path("demo/frame1.jpg")
|
10 |
+
FRAME2_PATH = Path("demo/frame2.jpg")
|
11 |
|
12 |
+
# Function to generate GIF
|
13 |
def generate_demo_gif(img1, img2):
|
14 |
# Save uploaded images
|
15 |
+
img1.save(FRAME1_PATH)
|
16 |
+
img2.save(FRAME2_PATH)
|
|
|
|
|
17 |
|
18 |
try:
|
19 |
result = subprocess.run([
|
20 |
"python", "inference_img.py",
|
21 |
+
"--img", str(FRAME1_PATH), str(FRAME2_PATH),
|
22 |
"--exp=4",
|
23 |
"--model", "train_log/"
|
24 |
], capture_output=True, text=True)
|
|
|
27 |
print("STDERR:", result.stderr)
|
28 |
|
29 |
if result.returncode == 0 and OUTPUT_GIF.exists():
|
30 |
+
return str(OUTPUT_GIF), "✅ GIF generated successfully!"
|
31 |
else:
|
32 |
+
return None, "❌ GIF generation failed. Check logs or file paths."
|
33 |
+
|
34 |
except Exception as e:
|
35 |
print(f"Error: {e}")
|
36 |
+
return None, f"❌ Subprocess error: {e}"
|
37 |
|
38 |
+
# Gradio UI
|
39 |
with gr.Blocks() as demo_ui:
|
40 |
with gr.Tab("Demo"):
|
41 |
gr.Markdown("### Upload two frames to generate a GIF")
|
|
|
44 |
img2_input = gr.Image(type="pil", label="Frame 2")
|
45 |
generate_btn = gr.Button("Generate GIF")
|
46 |
output_gif = gr.Image(label="Generated GIF")
|
47 |
+
status_msg = gr.Markdown()
|
48 |
|
49 |
generate_btn.click(
|
50 |
fn=generate_demo_gif,
|
51 |
inputs=[img1_input, img2_input],
|
52 |
+
outputs=[output_gif, status_msg]
|
53 |
)
|
54 |
|
55 |
demo_ui.launch()
|