AItool commited on
Commit
4e2e497
·
verified ·
1 Parent(s): dae661e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -8,13 +8,11 @@ import gradio as gr
8
  FRAME1 = Path("demo/frame1.png")
9
  FRAME2 = Path("demo/frame2.png")
10
 
11
- TARGET_DIR = "/home/user/app/output/" # absolute path that inference writes to
12
- PALETTE_PNG = Path("/home/user/app/output/palette.png")
13
- OUTPUT_GIF= Path("/home/user/app/output/output.gif")
14
- OUTPUT_GIF_DIR= Path("/home/user/app/output")
15
 
16
  os.makedirs(TARGET_DIR, exist_ok=True)
17
- os.makedirs(OUTPUT_GIF_DIR, exist_ok=True)
18
 
19
  def interpolate_image(img_a_path: str, img_b_path: str) -> tuple[str, str]:
20
  # 1) Run inference to generate frames into TARGET_DIR/img%d.png
@@ -29,20 +27,20 @@ def interpolate_image(img_a_path: str, img_b_path: str) -> tuple[str, str]:
29
  "ffmpeg", "-y", "-r", "14", "-f", "image2",
30
  "-i", f"{TARGET_DIR}img%d.png",
31
  "-vf", "palettegen=stats_mode=single",
32
- "-frames:v", "1", # <- critical: write exactly one image
33
- "/home/user/app/output/palette.png"
34
  ], check=True)
35
 
36
  # 3) Generate final GIF using palette
37
  subprocess.run([
38
  "ffmpeg", "-y", "-r", "14", "-f", "image2",
39
  "-i", f"{TARGET_DIR}img%d.png",
40
- "-i", "/home/user/app/output/palette.png",
41
  "-lavfi", "paletteuse",
42
- OUTPUT_GIF
43
  ], check=True)
44
 
45
- return out_gif, out_gif
46
 
47
  with gr.Blocks(title="RIFE Interpolation") as demo:
48
  with gr.Tab("Demo"):
 
8
  FRAME1 = Path("demo/frame1.png")
9
  FRAME2 = Path("demo/frame2.png")
10
 
11
+ TARGET_DIR = "/home/user/app/output/"
12
+ PALETTE_PNG = Path(TARGET_DIR) / "palette.png"
13
+ OUTPUT_GIF = Path(TARGET_DIR) / "output.gif"
 
14
 
15
  os.makedirs(TARGET_DIR, exist_ok=True)
 
16
 
17
  def interpolate_image(img_a_path: str, img_b_path: str) -> tuple[str, str]:
18
  # 1) Run inference to generate frames into TARGET_DIR/img%d.png
 
27
  "ffmpeg", "-y", "-r", "14", "-f", "image2",
28
  "-i", f"{TARGET_DIR}img%d.png",
29
  "-vf", "palettegen=stats_mode=single",
30
+ "-frames:v", "1",
31
+ str(PALETTE_PNG)
32
  ], check=True)
33
 
34
  # 3) Generate final GIF using palette
35
  subprocess.run([
36
  "ffmpeg", "-y", "-r", "14", "-f", "image2",
37
  "-i", f"{TARGET_DIR}img%d.png",
38
+ "-i", str(PALETTE_PNG),
39
  "-lavfi", "paletteuse",
40
+ str(OUTPUT_GIF)
41
  ], check=True)
42
 
43
+ return str(OUTPUT_GIF), str(OUTPUT_GIF)
44
 
45
  with gr.Blocks(title="RIFE Interpolation") as demo:
46
  with gr.Tab("Demo"):