File size: 1,079 Bytes
bdfe3f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import streamlit as st
from ultralytics import YOLO
import numpy as np
import cv2
from PIL import Image

st.title("πŸ” Suspicious Activity Detection with YOLOv11")

# Load the model
@st.cache_resource
def load_model():
    return YOLO("yolo11l.pt")

model = load_model()

uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])

if uploaded_file:
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)

    if st.button("Detect Activity"):
        img_array = np.array(image.convert("RGB"))[..., ::-1]  # Convert to BGR
        results = model.predict(img_array)

        for r in results:
            plotted = r.plot()
            st.image(plotted, caption="Detections", use_column_width=True)

            st.subheader("Detected Objects:")
            for box in r.boxes:
                conf = float(box.conf[0])
                cls = int(box.cls[0])
                cls_name = model.names[cls]
                st.write(f"- {cls_name} (Confidence: {conf:.2f})")