File size: 2,330 Bytes
3840cda
 
 
 
 
 
 
172f849
f87a4b4
 
 
 
 
 
 
 
 
51fc284
 
 
 
 
 
 
f87a4b4
51fc284
 
 
 
 
 
f87a4b4
51fc284
172f849
51fc284
3840cda
 
f87a4b4
172f849
f87a4b4
 
 
 
 
 
 
 
172f849
f87a4b4
 
 
 
3840cda
f87a4b4
 
 
 
 
3840cda
 
51fc284
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
from pathlib import Path
import json
import gradio as gr

from runner import process_video
from config import FRAME_INTERVAL_SEC, MAX_FRAMES

def run_pipeline(video_file, interval, max_frames, movie_title, movie_year):
    if video_file is None:
        return None, "No file", {}, []
    src = Path(video_file)
    zip_path = process_video(
        src,
        interval_sec=interval,
        max_frames=max_frames,
        movie_title=(movie_title or "").strip(),
        movie_year=(movie_year or "").strip(),
    )

    # Build previews
    out_root = Path("out") / src.stem
    trans_path = out_root / "transcription.txt"
    exp_path = out_root / "explanations.json"
    frames_dir = out_root / "frames"

    transcript_snippet = (trans_path.read_text(encoding="utf-8")[:1000] + "…") if trans_path.exists() else ""
    explanations = json.loads(exp_path.read_text(encoding="utf-8")) if exp_path.exists() else {}
    try:
        first_items = dict(list(explanations.items())[:5])
    except Exception:
        first_items = explanations

    previews = [str(p) for p in sorted(frames_dir.glob("*.jpg"))[:8]]

    return str(zip_path), transcript_snippet, first_items, previews

with gr.Blocks(title="Video → ZIP Caption Prep") as demo:
    gr.Markdown("## Video → ZIP Caption Prep")

    with gr.Row():
        video = gr.Video(label="Upload video", sources=["upload"], interactive=True)
        with gr.Column():
            interval = gr.Number(value=FRAME_INTERVAL_SEC, label="Frame interval (sec)", precision=1)
            max_frames = gr.Number(value=MAX_FRAMES, label="Max frames", precision=0)
            movie_title = gr.Textbox(label="Movie title (optional)", placeholder="Peacemaker")
            movie_year = gr.Textbox(label="Year (optional)", placeholder="2022")
            run_btn = gr.Button("Process", variant="primary")

    zip_out = gr.File(label="Download ZIP")
    transcript_box = gr.Textbox(label="Transcription snippet", lines=8)
    json_preview = gr.JSON(label="First 5 frame captions")
    gallery = gr.Gallery(label="Frame preview", columns=4, height=300)

    run_btn.click(
        run_pipeline,
        inputs=[video, interval, max_frames, movie_title, movie_year],
        outputs=[zip_out, transcript_box, json_preview, gallery],
    )

if __name__ == "__main__":
    demo.launch()