File size: 790 Bytes
eaa4e30
 
 
 
 
5d6a1b5
eaa4e30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import cv2
import torch

# Load your YOLO model
model = torch.hub.load('ultralytics/yolov5', 'custom', path='yolov8_Medium.pt')

# Function for YOLO detection
def detect_objects(image):
    results = model(image)
    return results

# Streamlit UI
st.title("Motorbike Violation Detection")
uploaded_file = st.file_uploader("Upload an image or video", type=["jpg", "jpeg", "png", "mp4"])

if uploaded_file is not None:
    if uploaded_file.type == "video/mp4":
        # Process video here
        st.video(uploaded_file)
        # Add video processing code
    else:
        # Process image
        image = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), 1)
        results = detect_objects(image)
        st.image(results.render()[0])  # Display results