Abs6187 commited on
Commit
fa01bd3
·
verified ·
1 Parent(s): cb6c73c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -3,8 +3,8 @@ 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):
@@ -21,9 +21,9 @@ 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
29
  uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
@@ -31,10 +31,10 @@ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "pn
31
  if uploaded_image is not None:
32
  # Open the uploaded image using PIL
33
  image = Image.open(uploaded_image)
34
-
35
  # Display the uploaded image
36
  st.image(image, caption="Uploaded Image", use_column_width=True)
37
-
38
  # Run the model prediction
39
  st.subheader("Prediction Results:")
40
  result_image = predict(image)
@@ -47,4 +47,4 @@ if st.checkbox('Show example images'):
47
  example_images = get_example_images()
48
  for example_image in example_images:
49
  img = Image.open(example_image)
50
- st.image(img, caption=os.path.basename(example_image), use_column_width=True)
 
3
  from PIL import Image
4
  import os
5
 
6
+ # Load the trained YOLOv8 model for seatbelt detection
7
+ model = YOLO("best.pt") # Assumes you have a seatbelt-specific trained model
8
 
9
  # Define the prediction function
10
  def predict(image):
 
21
  examples.append(os.path.join(image_folder, filename))
22
  return examples
23
 
24
+ # Streamlit UI for Seatbelt Detection with YOLO
25
+ st.title("Seatbelt Detection with YOLOv8")
26
+ st.markdown("Upload an image to detect seatbelt usage.")
27
 
28
  # Allow the user to upload an image
29
  uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
 
31
  if uploaded_image is not None:
32
  # Open the uploaded image using PIL
33
  image = Image.open(uploaded_image)
34
+
35
  # Display the uploaded image
36
  st.image(image, caption="Uploaded Image", use_column_width=True)
37
+
38
  # Run the model prediction
39
  st.subheader("Prediction Results:")
40
  result_image = predict(image)
 
47
  example_images = get_example_images()
48
  for example_image in example_images:
49
  img = Image.open(example_image)
50
+ st.image(img, caption=os.path.basename(example_image), use_column_width=True)