Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,12 @@ 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 |
TARGET_DIR = "/home/user/app/output/"
|
12 |
OUTPUT_GIF = "output.gif"
|
13 |
-
|
14 |
|
15 |
|
16 |
def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
@@ -37,7 +38,7 @@ def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
|
37 |
print("Exists?", os.path.exists("output/img0.png")) # ⬅️ Add it here
|
38 |
|
39 |
|
40 |
-
# Step
|
41 |
subprocess.run([
|
42 |
"ffmpeg", "-y", "-r", "14", "-f", "image2",
|
43 |
"-i", f"{TARGET_DIR}img%d.png",
|
@@ -49,14 +50,14 @@ subprocess.run([
|
|
49 |
subprocess.run([
|
50 |
"ffmpeg", "-y", "-r", "14", "-f", "image2",
|
51 |
"-i", f"{TARGET_DIR}img%d.png",
|
52 |
-
"-i",
|
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
|
60 |
gif = Image.open(io.BytesIO(f.read()))
|
61 |
print("✅ GIF created!")
|
62 |
# You can return or display the gif here
|
|
|
6 |
import io
|
7 |
|
8 |
# Fixed input paths and output location
|
9 |
+
|
10 |
FRAME1_PATH = "demo/frame1.png"
|
11 |
FRAME2_PATH = "demo/frame2.png"
|
12 |
TARGET_DIR = "/home/user/app/output/"
|
13 |
OUTPUT_GIF = "output.gif"
|
14 |
+
PALETTE_PNG = "palette.png"
|
15 |
|
16 |
|
17 |
def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
|
|
|
38 |
print("Exists?", os.path.exists("output/img0.png")) # ⬅️ Add it here
|
39 |
|
40 |
|
41 |
+
# Step 2: Generate palette
|
42 |
subprocess.run([
|
43 |
"ffmpeg", "-y", "-r", "14", "-f", "image2",
|
44 |
"-i", f"{TARGET_DIR}img%d.png",
|
|
|
50 |
subprocess.run([
|
51 |
"ffmpeg", "-y", "-r", "14", "-f", "image2",
|
52 |
"-i", f"{TARGET_DIR}img%d.png",
|
53 |
+
"-i", PALETTE_PNG,
|
54 |
"-lavfi", "paletteuse",
|
55 |
OUTPUT_GIF
|
56 |
], check=True)
|
57 |
|
58 |
# Step 3: Check and display result
|
59 |
+
if os.path.exists(TARGET_DIR/OUTPUT_GIF):
|
60 |
+
with openTARGET_DIR/OUTPUT_GIF, "rb") as f:
|
61 |
gif = Image.open(io.BytesIO(f.read()))
|
62 |
print("✅ GIF created!")
|
63 |
# You can return or display the gif here
|