Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,12 @@ from ultralytics import YOLO
|
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
|
6 |
-
#
|
7 |
model_path = "best.pt" # Ensure this matches the exact name of your model file
|
8 |
-
|
|
|
|
|
|
|
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 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
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)}")
|