rajnandale commited on
Commit
8cfa67f
·
verified ·
1 Parent(s): 6196e2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import os
2
- os.environ["YOLO_CONFIG_DIR"] = "/tmp"
3
-
4
- import cv2
5
- import torch
6
- import numpy as np
7
- import gradio as gr
8
- from PIL import Image
9
  from ultralytics import YOLO
 
 
 
 
 
 
10
 
11
  model = YOLO("weights/yolov8n.pt")
12
 
@@ -14,10 +13,11 @@ def detect_objects(image):
14
  results = model(image)
15
  return results[0].plot()
16
 
17
- interface = gr.Interface(
18
  fn=detect_objects,
19
- inputs=gr.Image(sources="webcam", type="numpy", label="Live Webcam"),
20
  outputs=gr.Image(type="numpy", label="Detection Output"),
21
- live=True)
22
- interface.launch()
23
 
 
 
1
  import os
 
 
 
 
 
 
 
2
  from ultralytics import YOLO
3
+ import gradio as gr
4
+
5
+ # Optional: Download weights if not present
6
+ if not os.path.exists("weights/yolov8n.pt"):
7
+ from huggingface_hub import hf_hub_download
8
+ hf_hub_download(repo_id="ultralytics/yolov8", filename="yolov8n.pt", local_dir="weights")
9
 
10
  model = YOLO("weights/yolov8n.pt")
11
 
 
13
  results = model(image)
14
  return results[0].plot()
15
 
16
+ interface = gr.Interface(
17
  fn=detect_objects,
18
+ inputs=gr.Image(sources=["upload", "webcam"], type="numpy", label="Input Image"),
19
  outputs=gr.Image(type="numpy", label="Detection Output"),
20
+ live=False # Set to False for upload, True for webcam (browser only)
21
+ )
22
 
23
+ interface.launch()