Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,30 @@ from ultralytics import YOLO
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
import os
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
if not os.path.exists(
|
| 12 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Load the YOLO model
|
| 15 |
try:
|
| 16 |
-
model = YOLO(
|
| 17 |
except Exception as e:
|
| 18 |
st.error(f"Error loading model: {e}")
|
| 19 |
|
|
@@ -34,4 +47,4 @@ if uploaded_file:
|
|
| 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"
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
import os
|
| 6 |
+
import requests
|
| 7 |
|
| 8 |
+
# Google Drive file ID for best.pt
|
| 9 |
+
FILE_ID = "1VE4I-_OMoC-wzzo-udzhJ896-WdFwJjU"
|
| 10 |
+
FILE_URL = f"https://drive.google.com/uc?id={FILE_ID}"
|
| 11 |
+
MODEL_PATH = "best.pt"
|
| 12 |
|
| 13 |
+
# Download the model if not already present
|
| 14 |
+
if not os.path.exists(MODEL_PATH):
|
| 15 |
+
st.info("Downloading model file from Google Drive...")
|
| 16 |
+
try:
|
| 17 |
+
response = requests.get(FILE_URL, stream=True)
|
| 18 |
+
response.raise_for_status()
|
| 19 |
+
with open(MODEL_PATH, "wb") as f:
|
| 20 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 21 |
+
if chunk:
|
| 22 |
+
f.write(chunk)
|
| 23 |
+
st.success("Model file downloaded successfully!")
|
| 24 |
+
except Exception as e:
|
| 25 |
+
st.error(f"Error downloading model: {e}")
|
| 26 |
|
| 27 |
# Load the YOLO model
|
| 28 |
try:
|
| 29 |
+
model = YOLO(MODEL_PATH)
|
| 30 |
except Exception as e:
|
| 31 |
st.error(f"Error loading model: {e}")
|
| 32 |
|
|
|
|
| 47 |
st.write("Detection Results:")
|
| 48 |
st.image(results[0].plot(), caption="Detections", use_column_width=True)
|
| 49 |
except Exception as e:
|
| 50 |
+
st.error(f"Error during prediction: {e}")
|