Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,22 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import
|
4 |
-
from gully_drs_core.ball_detection import process_video
|
5 |
|
6 |
-
|
7 |
-
logging.basicConfig(level=logging.INFO)
|
8 |
-
logger = logging.getLogger(__name__)
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
if uploaded_file is not None:
|
25 |
-
try:
|
26 |
-
# Save uploaded video
|
27 |
-
video_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
|
28 |
-
with open(video_path, "wb") as f:
|
29 |
-
f.write(uploaded_file.getbuffer())
|
30 |
-
st.success(f"Video '{uploaded_file.name}' uploaded successfully!")
|
31 |
-
|
32 |
-
# Process video
|
33 |
-
with st.spinner("Processing video for DRS analysis..."):
|
34 |
-
result = process_video(video_path)
|
35 |
-
if result["status"] == "success":
|
36 |
-
# Display replay video (live preview)
|
37 |
-
st.subheader("Replay Video")
|
38 |
-
st.video(result["replay_path"])
|
39 |
-
st.write(f"**LBW Decision**: {result['decision']}")
|
40 |
-
st.write(f"**Ball Speed**: {result['speed_kmh']:.2f} km/h")
|
41 |
-
# External test frame (local file access for testing)
|
42 |
-
st.subheader("External Replay (Test Frame)")
|
43 |
-
st.markdown(f'<video width="640" height="360" controls><source src="file://{result["replay_path"]}" type="video/mp4"></video>', unsafe_allow_html=True)
|
44 |
-
else:
|
45 |
-
st.error(f"Error: {result['error']}")
|
46 |
-
except Exception as e:
|
47 |
-
logger.error(f"Error processing video: {str(e)}")
|
48 |
-
st.error(f"Failed to process video: {str(e)}")
|
49 |
-
|
50 |
-
if __name__ == "__main__":
|
51 |
-
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
import tempfile
|
3 |
+
from gully_drs_core import ball_detection, replay_utils
|
|
|
4 |
|
5 |
+
st.title("🏏 GullyDRS – LBW Review System")
|
|
|
|
|
6 |
|
7 |
+
video_file = st.file_uploader("Upload a cricket match video", type=["mp4", "avi"])
|
8 |
+
if video_file:
|
9 |
+
tfile = tempfile.NamedTemporaryFile(delete=False)
|
10 |
+
tfile.write(video_file.read())
|
11 |
+
st.video(video_file)
|
12 |
|
13 |
+
if st.button("Analyze Video"):
|
14 |
+
with st.spinner("Processing..."):
|
15 |
+
result = ball_detection.analyze_video(tfile.name)
|
16 |
+
replay_path = replay_utils.generate_replay(
|
17 |
+
result["frames"],
|
18 |
+
result["trajectory"],
|
19 |
+
fps=result["fps"]
|
20 |
+
)
|
21 |
+
st.success("Replay generated!")
|
22 |
+
st.video(replay_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|