Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
from ultralytics import YOLO
|
| 5 |
|
| 6 |
# Load YOLOv8 model
|
|
@@ -8,14 +10,13 @@ model_path = MODEL_PATHS["YOLOv8n"]
|
|
| 8 |
model = YOLO(model_path)
|
| 9 |
|
| 10 |
# ---------- Detection Functions ----------
|
| 11 |
-
|
| 12 |
def detect_image_fn(image, confidence):
|
| 13 |
if image is None:
|
| 14 |
return None
|
| 15 |
-
image_np = np.array(image)
|
| 16 |
results = model.predict(image_np, conf=confidence, verbose=False)
|
| 17 |
annotated = results[0].plot()
|
| 18 |
-
return annotated
|
| 19 |
|
| 20 |
def detect_video_fn(video_file, confidence):
|
| 21 |
if video_file is None:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from helmet_detect_alert import detect_and_alert, MODEL_PATHS
|
| 6 |
from ultralytics import YOLO
|
| 7 |
|
| 8 |
# Load YOLOv8 model
|
|
|
|
| 10 |
model = YOLO(model_path)
|
| 11 |
|
| 12 |
# ---------- Detection Functions ----------
|
|
|
|
| 13 |
def detect_image_fn(image, confidence):
|
| 14 |
if image is None:
|
| 15 |
return None
|
| 16 |
+
image_np = np.array(image)
|
| 17 |
results = model.predict(image_np, conf=confidence, verbose=False)
|
| 18 |
annotated = results[0].plot()
|
| 19 |
+
return Image.fromarray(annotated)
|
| 20 |
|
| 21 |
def detect_video_fn(video_file, confidence):
|
| 22 |
if video_file is None:
|