scfive commited on
Commit
8873f80
·
verified ·
1 Parent(s): 3357e99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -2,13 +2,20 @@ import streamlit as st
2
  from ultralytics import YOLO
3
  from PIL import Image
4
  import numpy as np
 
5
 
6
- # Correct path to the model file in the root directory
7
- model_path = "best.pt" # Ensure this matches the exact name of your model file
 
 
 
 
 
 
8
  try:
9
  model = YOLO(model_path)
10
- except FileNotFoundError:
11
- st.error(f"Model file not found: {model_path}. Please ensure 'best.pt' is uploaded to the root directory.")
12
 
13
  # Streamlit app
14
  st.title("YOLOv11 Object Detection")
@@ -27,4 +34,4 @@ if uploaded_file:
27
  st.write("Detection Results:")
28
  st.image(results[0].plot(), caption="Detections", use_column_width=True)
29
  except Exception as e:
30
- st.error(f"Error during prediction: {str(e)}")
 
2
  from ultralytics import YOLO
3
  from PIL import Image
4
  import numpy as np
5
+ import os
6
 
7
+ # Define the model path
8
+ model_path = "best.pt" # Assumes `best.pt` is in the root directory
9
+
10
+ # Verify file existence
11
+ if not os.path.exists(model_path):
12
+ st.error(f"Model file not found at: {model_path}. Current directory files: {os.listdir()}")
13
+
14
+ # Load the YOLO model
15
  try:
16
  model = YOLO(model_path)
17
+ except Exception as e:
18
+ st.error(f"Error loading model: {e}")
19
 
20
  # Streamlit app
21
  st.title("YOLOv11 Object Detection")
 
34
  st.write("Detection Results:")
35
  st.image(results[0].plot(), caption="Detections", use_column_width=True)
36
  except Exception as e:
37
+ st.error(f"E