muskan19 commited on
Commit
2f25418
Β·
verified Β·
1 Parent(s): 258cf12

Delete src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +0 -65
src/app.py DELETED
@@ -1,65 +0,0 @@
1
-
2
- # Streamlit app will be generated here
3
- #import os
4
-
5
- # βœ… Set config to avoid writing to root dir
6
- #os.environ["STREAMLIT_HOME"] = os.path.join(os.getcwd(), ".streamlit_safe")
7
- #os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
8
- #os.makedirs(os.environ["STREAMLIT_HOME"], exist_ok=True)
9
-
10
- #import os
11
- #import streamlit as st
12
-
13
- # Fix permission error for Hugging Face Spaces
14
- #os.environ["STREAMLIT_HOME"] = "./safe_streamlit_home"
15
- #os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
16
- #os.makedirs(os.environ["STREAMLIT_HOME"], exist_ok=True)
17
- #import streamlit as st
18
- # Your other imports...
19
- import os
20
-
21
- # βœ… Tell Streamlit NOT to collect usage data or write config files
22
- os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
23
- os.environ["XDG_CONFIG_HOME"] = "/tmp"
24
-
25
- import streamlit as st
26
-
27
- from src.process import preprocess_frame
28
- from src.predict import load_trained_model, predict_violence
29
-
30
- import streamlit as st
31
- import cv2
32
- import numpy as np
33
- from src.preprocess import preprocess_frame
34
- from src.predict import load_trained_model, predict_violence
35
- import tempfile
36
-
37
- st.set_page_config(layout="wide")
38
- st.title("πŸ” Violence Detection in Video")
39
- st.markdown("Upload a video and let the model detect violent scenes in real-time.")
40
-
41
- uploaded_file = st.file_uploader("Upload a video", type=["mp4", "avi"])
42
- model = load_trained_model("models/violence_model.h5")
43
-
44
- if uploaded_file is not None:
45
- tfile = tempfile.NamedTemporaryFile(delete=False)
46
- tfile.write(uploaded_file.read())
47
- cap = cv2.VideoCapture(tfile.name)
48
- stframe = st.empty()
49
-
50
- while cap.isOpened():
51
- ret, frame = cap.read()
52
- if not ret:
53
- break
54
-
55
- processed = preprocess_frame(frame)
56
- pred = predict_violence(model, processed)
57
- label = "Violent" if pred <= 0.5 else "Non-Violent"
58
- color = (0, 0, 255) if label == "Violent" else (0, 255, 0)
59
-
60
- cv2.putText(frame, f'{label} ({pred:.2f})', (10, 30),
61
- cv2.FONT_HERSHEY_SIMPLEX, 1, color, 2)
62
- stframe.image(frame, channels="BGR")
63
-
64
- cap.release()
65
-