SRUTHI123 commited on
Commit
bdf1b61
·
verified ·
1 Parent(s): b4cb0eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import numpy as np
4
+ import cv2
5
+ from ultralytics import YOLO
6
+
7
+ # Title
8
+ st.title("Suspicious Activity Detection")
9
+ st.markdown("Upload an image to detect activity (Normal, Peaking, Sneaking, Stealing).")
10
+
11
+ # Load model
12
+ @st.cache_resource
13
+ def load_model():
14
+ model = YOLO("yolo11l.pt") # Make sure this file is uploaded to your Space
15
+ return model
16
+
17
+ model = load_model()
18
+
19
+ # File uploader
20
+ uploaded_file = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
21
+
22
+ if uploaded_file:
23
+ image = Image.open(uploaded_file).convert("RGB")
24
+ st.image(image, caption="Uploaded Image", use_column_width=True)
25
+
26
+ # Convert to numpy array for OpenCV/YOLO
27
+ img_array = np.array(image)
28
+
29
+ # Run prediction
30
+ st.info("Running detection...")
31
+ results = model.predict(source=img_array, conf=0.25, classes=None)
32
+
33
+ for r in results:
34
+ # Show annotated image
35
+ annotated_img = r.plot()
36
+ st.image(annotated_img, caption="Detection Result", use_column_width=True)
37
+
38
+ # Show detected objects with confidence
39
+ st.subheader("Detections:")
40
+ for box in r.boxes:
41
+ conf = float(box.conf[0])
42
+ cls_id = int(box.cls[0])
43
+ cls_name = model.names[cls_id]
44
+ st.write(f"- **{cls_name}** (Confidence: {conf:.2f})")