File size: 1,940 Bytes
c3500d3
 
 
 
c516919
120cb4a
c3500d3
f42a100
 
 
 
c3500d3
c516919
70494de
 
 
f42a100
c3500d3
f42a100
 
 
 
 
120cb4a
f42a100
c3500d3
 
f42a100
 
120cb4a
c3500d3
120cb4a
c516919
f42a100
c3500d3
 
f08dd09
c3500d3
f42a100
 
c516919
f42a100
 
 
c3500d3
f42a100
c3500d3
f42a100
c3500d3
f42a100
120cb4a
c3500d3
f42a100
 
120cb4a
c516919
 
f42a100
c3500d3
 
c516919
c3500d3
37836b2
f42a100
ba134cf
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
from pathlib import Path
import subprocess
import gradio as gr
from PIL import Image
import io

# Fixed input paths and output location
FRAME1_PATH = "demo/frame1.png"
FRAME2_PATH = "demo/frame2.png"
OUTPUT_GIF = "/tmp/output.gif"

def generate_demo_gif(exp=2, progress=gr.Progress(track_tqdm=True)):
    success = cv2.imwrite('/output/test.png', img_array)
    print("Saved?", success)

    progress(0.1, desc="Starting inference...")

    # Delete old output if exists
    try:
        os.remove(OUTPUT_GIF)
    except FileNotFoundError:
        pass

    # Build and run command
    cmd = [
        "python", "inference_img.py",
        "--img", FRAME1_PATH, FRAME2_PATH,
        "--exp", str(exp),
        "--model", "train_log/"
    ]
    print("Running:", " ".join(cmd))
    result = subprocess.run(cmd, capture_output=True, text=True)

    print("STDOUT:", result.stdout)
    print("STDERR:", result.stderr)
    print("Exists?", os.path.exists("/output/output.gif"))  # ⬅️ Add it here

    # Check and display result
    if result.returncode == 0 and os.path.exists(OUTPUT_GIF):
        with open(OUTPUT_GIF, "rb") as f:
            gif = Image.open(io.BytesIO(f.read()))
        progress(1.0, desc="GIF created!")
        return gif, "βœ… Done!"
    else:
        return None, "❌ Inference failed or output missing"

# UI setup
with gr.Blocks() as demo_ui:
    gr.Markdown("## 🎞️ Demo GIF Generator β€” Interpolate Two Frames")

    with gr.Row():
        gr.Image(value=FRAME1_PATH, label="Frame 1", interactive=False)
        gr.Image(value=FRAME2_PATH, label="Frame 2", interactive=False)

    exp = gr.Slider(1, 4, value=2, step=1, label="Interpolation Exponent")
    run_btn = gr.Button("Generate GIF")
    out_gif = gr.Image(label="Output GIF")
    status = gr.Markdown()

    run_btn.click(fn=generate_demo_gif, inputs=[exp], outputs=[out_gif, status])


# Launch the app
demo_ui.launch(ssr_mode=False)