AItool commited on
Commit
f1ea9c1
·
verified ·
1 Parent(s): 688aa4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -9
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
- OUTPUT_GIF = "/tmp/output.gif"
 
 
 
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
- # Check and display result
37
- if result.returncode == 0 and os.path.exists(OUTPUT_GIF):
38
- with open(OUTPUT_GIF, "rb") as f:
39
- gif = Image.open(io.BytesIO(f.read()))
40
- progress(1.0, desc="GIF created!")
41
- return gif, "✅ Done!"
42
- else:
43
- return None, "❌ Inference failed or output missing"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: