Abs6187 commited on
Commit
ac3b71f
·
verified ·
1 Parent(s): 26f6a32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
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 YOLOv8 model
7
- model = YOLO("best.pt")
8
 
9
  # Define the prediction function
10
  def predict(image):
11
- results = model(image) # Run YOLOv8 model on the uploaded image
12
- results_img = results[0].plot() # Get image with bounding boxes
 
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 YOLO
25
- st.title("Helmet Detection with YOLOv8")
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