junaid-simamdigital commited on
Commit
ee17daa
·
verified ·
1 Parent(s): e6d8ec6

Add Gradio race timeline app

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ import tempfile
6
+ from pathlib import Path
7
+
8
+ import gradio as gr
9
+
10
+ from race_core import build_manifest, markdown_timeline
11
+
12
+
13
+ def run(video, telemetry):
14
+ video_name = Path(video).name if video else ""
15
+ csv_text = None
16
+ if telemetry:
17
+ csv_text = Path(telemetry).read_text(encoding="utf-8-sig", errors="replace")
18
+ manifest = build_manifest(video_name, csv_text)
19
+ work = Path(tempfile.mkdtemp(prefix="simam_race_highlights_"))
20
+ manifest_path = work / "race_highlights.json"
21
+ markdown_path = work / "race_highlights.md"
22
+ manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8")
23
+ markdown_path.write_text(markdown_timeline(manifest), encoding="utf-8")
24
+ table = [[e["time_s"], e["label"], e["source"], e["confidence"]] for e in manifest["events"]]
25
+ note = "Telemetry-derived event candidates are ready for XR Jump to Moment." if csv_text else "Only a Start marker was created because no telemetry CSV was supplied."
26
+ return table, markdown_timeline(manifest), json.dumps(manifest, indent=2), str(manifest_path), str(markdown_path), note
27
+
28
+
29
+ with gr.Blocks(title="SimamRaceHighlights") as demo:
30
+ gr.Markdown("# SimamRaceHighlights\n### Turn race video + telemetry into an XR-jumpable event timeline\n\nThe manifest uses one shared `time_s` so video, RaceClock, telemetry, camera, and vehicle state can seek together.")
31
+ with gr.Row():
32
+ with gr.Column():
33
+ video = gr.Video(label="Race video (optional for indexing baseline)", sources=["upload"], format="mp4")
34
+ telemetry = gr.File(label="Telemetry CSV (recommended)", file_types=[".csv"], type="filepath")
35
+ button = gr.Button("Build race highlights", variant="primary")
36
+ with gr.Column():
37
+ note = gr.Markdown()
38
+ table = gr.Dataframe(headers=["time_s", "event", "source", "confidence"], label="Highlight timeline", interactive=False)
39
+ timeline = gr.Markdown(label="Readable timeline")
40
+ manifest = gr.Code(label="XR event manifest", language="json")
41
+ manifest_file = gr.File(label="Download JSON manifest")
42
+ markdown_file = gr.File(label="Download Markdown timeline")
43
+ button.click(run, [video, telemetry], [table, timeline, manifest, manifest_file, markdown_file, note], api_name="build_highlights")
44
+ gr.Markdown("**Roadmap:** video-language model event proposals → telemetry/video alignment → confidence calibration → clickable Jump to Moment controls → live RaceClock/WebXR integration.")
45
+
46
+
47
+ if __name__ == "__main__":
48
+ demo.launch(server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"), server_port=int(os.getenv("GRADIO_SERVER_PORT", "7860")))