kadirnar commited on
Commit
534176a
1 Parent(s): 7a9dce1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -1,8 +1,15 @@
 
1
  import gradio as gr
2
  from ultralytics import YOLOv10
3
  import supervision as sv
4
  import spaces
 
 
5
 
 
 
 
 
6
  box_annotator = sv.BoxAnnotator()
7
  category_dict = {
8
  0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
@@ -26,7 +33,8 @@ category_dict = {
26
 
27
  @spaces.GPU(duration=200)
28
  def yolov10_inference(image, model_id, image_size, conf_threshold, iou_threshold):
29
- model = YOLOv10.from_pretrained(f"kadirnar/{model_id}")
 
30
  results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
31
  detections = sv.Detections.from_ultralytics(results)
32
 
@@ -47,14 +55,14 @@ def app():
47
  model_id = gr.Dropdown(
48
  label="Model",
49
  choices=[
50
- "yolov10n",
51
- "yolov10s",
52
- "yolov10m",
53
- "yolov10b",
54
- "yolov10l",
55
- "yolov10x",
56
  ],
57
- value="yolov10m",
58
  )
59
  image_size = gr.Slider(
60
  label="Image Size",
 
1
+
2
  import gradio as gr
3
  from ultralytics import YOLOv10
4
  import supervision as sv
5
  import spaces
6
+ from huggingface_hub import hf_hub_download
7
+
8
 
9
+ def download_models(model_id):
10
+ hf_hub_download("kadirnar/Yolov10", filename=f"{model_id}", local_dir=f"./")
11
+ return f"./{model_id}"
12
+
13
  box_annotator = sv.BoxAnnotator()
14
  category_dict = {
15
  0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
 
33
 
34
  @spaces.GPU(duration=200)
35
  def yolov10_inference(image, model_id, image_size, conf_threshold, iou_threshold):
36
+ model_path = download_models(model_id)
37
+ model = YOLOv10(model_path)
38
  results = model(source=image, imgsz=image_size, iou=iou_threshold, conf=conf_threshold, verbose=False)[0]
39
  detections = sv.Detections.from_ultralytics(results)
40
 
 
55
  model_id = gr.Dropdown(
56
  label="Model",
57
  choices=[
58
+ "yolov10n.pt",
59
+ "yolov10s.pt",
60
+ "yolov10m.pt",
61
+ "yolov10b.pt",
62
+ "yolov10l.pt",
63
+ "yolov10x.pt",
64
  ],
65
+ value="yolov10m.pt",
66
  )
67
  image_size = gr.Slider(
68
  label="Image Size",