Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,21 @@ from ultralytics import YOLO
|
|
6 |
from huggingface_hub import hf_hub_download
|
7 |
import os
|
8 |
|
9 |
-
# Verify
|
10 |
-
REPO_ID = "StephanST/WALDO30" #
|
11 |
-
MODEL_FILENAME = "WALDO30_yolov8m_640x640.pt"
|
12 |
|
13 |
# Download the model from Hugging Face
|
14 |
try:
|
15 |
model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
|
|
|
16 |
except Exception as e:
|
17 |
raise RuntimeError(f"Failed to download model from Hugging Face. Verify `repo_id` and `filename`. Error: {e}")
|
18 |
|
19 |
# Load the YOLOv8 model
|
20 |
try:
|
21 |
-
model = YOLO(model_path) #
|
|
|
22 |
except Exception as e:
|
23 |
raise RuntimeError(f"Failed to load the YOLO model. Verify the model file at `{model_path}`. Error: {e}")
|
24 |
|
@@ -54,19 +56,30 @@ def detect_on_video(video):
|
|
54 |
except Exception as e:
|
55 |
raise RuntimeError(f"Error during video processing: {e}")
|
56 |
|
57 |
-
# Gradio Interface
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
video_output = gr.Video(label="Detected Video")
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
if __name__ == "__main__":
|
72 |
app.launch()
|
|
|
6 |
from huggingface_hub import hf_hub_download
|
7 |
import os
|
8 |
|
9 |
+
# Verify paths and Hugging Face repository details
|
10 |
+
REPO_ID = "StephanST/WALDO30" # Replace with the correct repo ID if different
|
11 |
+
MODEL_FILENAME = "WALDO30_yolov8m_640x640.pt" # Replace if the filename is different
|
12 |
|
13 |
# Download the model from Hugging Face
|
14 |
try:
|
15 |
model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
|
16 |
+
print(f"Model downloaded successfully to: {model_path}")
|
17 |
except Exception as e:
|
18 |
raise RuntimeError(f"Failed to download model from Hugging Face. Verify `repo_id` and `filename`. Error: {e}")
|
19 |
|
20 |
# Load the YOLOv8 model
|
21 |
try:
|
22 |
+
model = YOLO(model_path) # Load the YOLOv8 model
|
23 |
+
print("Model loaded successfully!")
|
24 |
except Exception as e:
|
25 |
raise RuntimeError(f"Failed to load the YOLO model. Verify the model file at `{model_path}`. Error: {e}")
|
26 |
|
|
|
56 |
except Exception as e:
|
57 |
raise RuntimeError(f"Error during video processing: {e}")
|
58 |
|
59 |
+
# Gradio Interface using Blocks
|
60 |
+
with gr.Blocks() as app:
|
61 |
+
gr.Markdown("# WALDO30 YOLOv8 Object Detection")
|
62 |
+
gr.Markdown("Upload an image or video to see object detection results using the WALDO30 YOLOv8 model.")
|
|
|
63 |
|
64 |
+
# Image processing block
|
65 |
+
with gr.Row():
|
66 |
+
with gr.Column():
|
67 |
+
image_input = gr.Image(type="pil", label="Upload Image")
|
68 |
+
image_button = gr.Button("Detect on Image")
|
69 |
+
with gr.Column():
|
70 |
+
image_output = gr.Image(type="pil", label="Detected Image")
|
71 |
+
|
72 |
+
# Video processing block
|
73 |
+
with gr.Row():
|
74 |
+
with gr.Column():
|
75 |
+
video_input = gr.Video(label="Upload Video")
|
76 |
+
video_button = gr.Button("Detect on Video")
|
77 |
+
with gr.Column():
|
78 |
+
video_output = gr.Video(label="Detected Video")
|
79 |
+
|
80 |
+
# Set up events
|
81 |
+
image_button.click(detect_on_image, inputs=image_input, outputs=image_output)
|
82 |
+
video_button.click(detect_on_video, inputs=video_input, outputs=video_output)
|
83 |
|
84 |
if __name__ == "__main__":
|
85 |
app.launch()
|