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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -3,9 +3,12 @@ from ultralytics import YOLO
3
  from PIL import Image
4
  import numpy as np
5
 
6
- # Load the YOLO model directly from the root directory
7
  model_path = "best.pt" # Ensure this matches the exact name of your model file
8
- model = YOLO(model_path)
 
 
 
9
 
10
  # Streamlit app
11
  st.title("YOLOv11 Object Detection")
@@ -19,8 +22,9 @@ if uploaded_file:
19
 
20
  # Perform prediction
21
  with st.spinner("Processing..."):
22
- results = model.predict(np.array(image))
23
-
24
- # Display results
25
- st.write("Detection Results:")
26
- st.image(results[0].plot(), caption="Detections", use_column_width=True)
 
 
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")
 
22
 
23
  # Perform prediction
24
  with st.spinner("Processing..."):
25
+ try:
26
+ results = model.predict(np.array(image))
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)}")