import streamlit as st import tempfile import os from gully_drs_core import ball_detection, replay_utils st.set_page_config(page_title="GullyDRS – LBW Review", layout="centered") st.title("🏏 GullyDRS – LBW Decision Review System") st.markdown(""" Upload a cricket match video and let AI analyze whether it's **OUT** or **NOT OUT** based on ball trajectory, bounce point, and stump zone detection. """) video_file = st.file_uploader("🎥 Upload your match video", type=["mp4", "avi"]) if video_file: tfile = tempfile.NamedTemporaryFile(delete=False) tfile.write(video_file.read()) st.video(video_file) if st.button("🧠 Analyze Video"): with st.spinner("Analyzing with AI..."): result = ball_detection.analyze_video(tfile.name) st.write(f"🔍 Trajectory points: {len(result['trajectory'])}") st.write(f"🏁 Final Decision: **{result['decision']}**") st.write(f"🚀 Ball Speed: **{result['speed_kmh']} km/h**") if result["bounce_point"]: st.info(f"📍 Bounce detected at: {result['bounce_point']}") if result["impact_point"]: st.info(f"🎯 Impact point: {result['impact_point']}") replay_path = replay_utils.generate_replay( frames=result["frames"], ball_path=result["trajectory"], bounce_point=result["bounce_point"], impact_point=result["impact_point"], decision=result["decision"], stump_zone=result["stump_zone"], speed_kmh=result["speed_kmh"], fps=result["fps"] ) if replay_path and os.path.exists(replay_path): st.success("✅ Replay generated successfully!") st.video(replay_path) else: st.error("⚠️ Replay generation failed or produced no video.")