Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,10 @@ import io
|
|
8 |
# Fixed input paths and output location
|
9 |
FRAME1_PATH = "demo/frame1.png"
|
10 |
FRAME2_PATH = "demo/frame2.png"
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
14 |
progress(0.1, desc="Starting inference...")
|
@@ -33,14 +36,32 @@ def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
|
33 |
print("STDERR:", result.stderr)
|
34 |
print("Exists?", os.path.exists("output/img0.png")) # ⬅️ Add it here
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# UI setup
|
46 |
with gr.Blocks() as demo_ui:
|
|
|
8 |
# Fixed input paths and output location
|
9 |
FRAME1_PATH = "demo/frame1.png"
|
10 |
FRAME2_PATH = "demo/frame2.png"
|
11 |
+
TARGET_DIR = "/home/user/app/output/"
|
12 |
+
OUTPUT_GIF = "output.gif"
|
13 |
+
PALETTE_PATH = "palette.png"
|
14 |
+
|
15 |
|
16 |
def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
17 |
progress(0.1, desc="Starting inference...")
|
|
|
36 |
print("STDERR:", result.stderr)
|
37 |
print("Exists?", os.path.exists("output/img0.png")) # ⬅️ Add it here
|
38 |
|
39 |
+
|
40 |
+
# Step 1: Generate palette
|
41 |
+
subprocess.run([
|
42 |
+
"ffmpeg", "-y", "-r", "14", "-f", "image2",
|
43 |
+
"-i", f"{TARGET_DIR}img%d.png",
|
44 |
+
"-vf", "palettegen=stats_mode=single",
|
45 |
+
PALETTE_PATH
|
46 |
+
], check=True)
|
47 |
+
|
48 |
+
# Step 2: Generate GIF using palette
|
49 |
+
subprocess.run([
|
50 |
+
"ffmpeg", "-y", "-r", "14", "-f", "image2",
|
51 |
+
"-i", f"{TARGET_DIR}img%d.png",
|
52 |
+
"-i", PALETTE_PATH,
|
53 |
+
"-lavfi", "paletteuse",
|
54 |
+
OUTPUT_GIF
|
55 |
+
], check=True)
|
56 |
+
|
57 |
+
# Step 3: Check and display result
|
58 |
+
if os.path.exists(OUTPUT_GIF):
|
59 |
+
with open(OUTPUT_GIF, "rb") as f:
|
60 |
+
gif = Image.open(io.BytesIO(f.read()))
|
61 |
+
print("✅ GIF created!")
|
62 |
+
# You can return or display the gif here
|
63 |
+
else:
|
64 |
+
print("❌ Inference failed or output missing")
|
65 |
|
66 |
# UI setup
|
67 |
with gr.Blocks() as demo_ui:
|