Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,16 @@
|
|
1 |
import streamlit as st
|
2 |
-
from ultralytics import YOLO
|
3 |
from PIL import Image
|
|
|
4 |
import os
|
5 |
|
6 |
-
# Load the trained
|
7 |
-
model =
|
8 |
|
9 |
# Define the prediction function
|
10 |
def predict(image):
|
11 |
-
|
12 |
-
|
|
|
13 |
return Image.fromarray(results_img)
|
14 |
|
15 |
# Get example images from the images folder
|
@@ -21,8 +22,8 @@ def get_example_images():
|
|
21 |
examples.append(os.path.join(image_folder, filename))
|
22 |
return examples
|
23 |
|
24 |
-
# Streamlit UI for Helmet Detection with
|
25 |
-
st.title("Helmet Detection with
|
26 |
st.markdown("Upload an image to detect helmets.")
|
27 |
|
28 |
# Allow the user to upload an image
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from PIL import Image
|
3 |
+
import torch
|
4 |
import os
|
5 |
|
6 |
+
# Load the trained YOLOv5 model
|
7 |
+
model = torch.hub.load("ultralytics/yolov5", "custom", path="best.pt") # Load custom model
|
8 |
|
9 |
# Define the prediction function
|
10 |
def predict(image):
|
11 |
+
# Perform inference on the uploaded image
|
12 |
+
results = model(image) # Runs YOLOv5 model on the uploaded image
|
13 |
+
results_img = results.render()[0] # Get image with bounding boxes drawn
|
14 |
return Image.fromarray(results_img)
|
15 |
|
16 |
# Get example images from the images folder
|
|
|
22 |
examples.append(os.path.join(image_folder, filename))
|
23 |
return examples
|
24 |
|
25 |
+
# Streamlit UI for Helmet Detection with YOLOv5
|
26 |
+
st.title("Helmet Detection with YOLOv5")
|
27 |
st.markdown("Upload an image to detect helmets.")
|
28 |
|
29 |
# Allow the user to upload an image
|