TheKnight115 commited on
Commit
eaa4e30
·
verified ·
1 Parent(s): fd30311

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -1,11 +1,26 @@
1
- from ultralytics import YOLO
2
- model = YOLO("yolov8m.pt")
3
-
4
- cap = cv2.VideoCapture(tfile.name)
5
- while cap.isOpened():
6
- ret, frame = cap.read()
7
- if not ret:
8
- break
9
- results = model(frame)
10
- annotated_frame = results[0].plot()
11
- stframe.image(annotated_frame, channels="BGR")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import torch
4
+
5
+ # Load your YOLO model
6
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='path/to/yolov8_motorbike_detect_v2_Check.pt')
7
+
8
+ # Function for YOLO detection
9
+ def detect_objects(image):
10
+ results = model(image)
11
+ return results
12
+
13
+ # Streamlit UI
14
+ st.title("Motorbike Violation Detection")
15
+ uploaded_file = st.file_uploader("Upload an image or video", type=["jpg", "jpeg", "png", "mp4"])
16
+
17
+ if uploaded_file is not None:
18
+ if uploaded_file.type == "video/mp4":
19
+ # Process video here
20
+ st.video(uploaded_file)
21
+ # Add video processing code
22
+ else:
23
+ # Process image
24
+ image = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), 1)
25
+ results = detect_objects(image)
26
+ st.image(results.render()[0]) # Display results