saad1BM commited on
Commit
7a0f64b
·
verified ·
1 Parent(s): 69e8f76

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app_streamlit_final.py
2
+ import streamlit as st
3
+ import cv2
4
+ from ultralytics import YOLO
5
+ import numpy as np
6
+
7
+ # Page configuration
8
+ st.set_page_config(page_title="Live Mask Detector", layout="wide")
9
+ st.title("🎭 Real-Time Face Mask Detection")
10
+
11
+ # 1. Model load karein
12
+ model = YOLO("best.pt")
13
+
14
+ # 2. UI Layout
15
+ col1, col2 = st.columns([2, 1])
16
+ with col1:
17
+ # Frame placeholder jahan video nazar aayegi
18
+ frame_placeholder = st.empty()
19
+
20
+ with col2:
21
+ st.info("System Status: Running")
22
+ stop_button = st.button("Stop Camera")
23
+ conf_slider = st.slider("Confidence Threshold", 0.1, 1.0, 0.4)
24
+
25
+ # 3. Camera Loop
26
+ cap = cv2.VideoCapture(0)
27
+
28
+ while cap.isOpened() and not stop_button:
29
+ ret, frame = cap.read()
30
+ if not ret:
31
+ st.error("Camera access nahi mil raha. Please check permissions.")
32
+ break
33
+
34
+ # Prediction (Wahi logic jo mask_test.py mein tha)
35
+ results = model.predict(frame, conf=conf_slider)
36
+
37
+ # Annotated frame
38
+ annotated_frame = results[0].plot()
39
+
40
+ # BGR to RGB (Streamlit requirements)
41
+ frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
42
+
43
+ # Browser mein display karein
44
+ frame_placeholder.image(frame_rgb, channels="RGB", use_container_width=True)
45
+
46
+ if stop_button:
47
+ break
48
+
49
+ cap.release()
50
+ st.warning("Camera Stopped.")