Kiransubedi545 commited on
Commit
eadd655
·
verified ·
1 Parent(s): b205cf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
2
  import os
3
- from helmet_detect_alert import detect_and_alert, detect_from_images, MODEL_PATHS
 
 
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) # Convert PIL to NumPy
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: