Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import json
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from runner import process_video
|
| 6 |
+
from config import FRAME_INTERVAL_SEC, MAX_FRAMES
|
| 7 |
+
|
| 8 |
+
def run_pipeline(video_file, interval, max_frames):
|
| 9 |
+
if video_file is None:
|
| 10 |
+
return None, "No file", {}, []
|
| 11 |
+
src = Path(video_file)
|
| 12 |
+
zip_path = process_video(src, interval_sec=interval, max_frames=max_frames)
|
| 13 |
+
|
| 14 |
+
# Build previews
|
| 15 |
+
out_root = Path("out") / src.stem
|
| 16 |
+
trans_path = out_root / "transcription.txt"
|
| 17 |
+
exp_path = out_root / "explanations.json"
|
| 18 |
+
frames_dir = out_root / "frames"
|
| 19 |
+
|
| 20 |
+
transcript_snippet = (trans_path.read_text(encoding="utf-8")[:1000] + "…") if trans_path.exists() else ""
|
| 21 |
+
explanations = json.loads(exp_path.read_text(encoding="utf-8")) if exp_path.exists() else {}
|
| 22 |
+
first_items = dict(list(explanations.items())[:5])
|
| 23 |
+
|
| 24 |
+
# gallery preview (up to 8)
|
| 25 |
+
previews = [str(p) for p in sorted(frames_dir.glob("*.jpg"))[:8]]
|
| 26 |
+
|
| 27 |
+
return str(zip_path), transcript_snippet, first_items, previews
|
| 28 |
+
|
| 29 |
+
with gr.Blocks(title="Video → ZIP Caption Prep") as demo:
|
| 30 |
+
gr.Markdown("## Video → ZIP Caption Prep")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
video = gr.Video(label="Upload video", sources=["upload"], interactive=True)
|
| 34 |
+
with gr.Column():
|
| 35 |
+
interval = gr.Number(value=FRAME_INTERVAL_SEC, label="Frame interval (sec)", precision=1)
|
| 36 |
+
max_frames = gr.Number(value=MAX_FRAMES, label="Max frames", precision=0)
|
| 37 |
+
run_btn = gr.Button("Process", variant="primary")
|
| 38 |
+
|
| 39 |
+
zip_out = gr.File(label="Download ZIP")
|
| 40 |
+
transcript_box = gr.Textbox(label="Transcription snippet", lines=8)
|
| 41 |
+
json_preview = gr.JSON(label="First 5 frame captions")
|
| 42 |
+
gallery = gr.Gallery(label="Frame preview", columns=4, height=300)
|
| 43 |
+
|
| 44 |
+
run_btn.click(run_pipeline, inputs=[video, interval, max_frames], outputs=[zip_out, transcript_box, json_preview, gallery])
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
demo.launch()
|