atalaydenknalbant commited on
Commit
f0e3b6f
·
verified ·
1 Parent(s): e4caec0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -2,22 +2,27 @@ import spaces
2
  import supervision as sv
3
  import PIL.Image as Image
4
  from ultralytics import YOLO
5
- from huggingface_hub import hf_hub_download, list_repo_files
6
  import gradio as gr
7
 
8
  global repo_id
9
 
10
  repo_id = "atalaydenknalbant/asl-yolo-models"
11
 
12
- def download_models(repo_id, model_id, file_extension=".pt"):
13
- # Get list of files in the repository without using HfApi
14
- files = list_repo_files(repo_id)
15
- # Filter for model filenames with the given extension
16
- model_filenames = [file for file in files if file.endswith(file_extension)]
17
-
 
 
 
 
 
18
  # Download the selected model
19
  hf_hub_download(repo_id, filename=model_id, local_dir=f"./")
20
- return model_filenames, f"./{model_id}"
21
 
22
  box_annotator = sv.BoxAnnotator()
23
  category_dict = {0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'E', 5: 'F', 6: 'G', 7: 'H', 8: 'I',
@@ -26,8 +31,8 @@ category_dict = {0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'E', 5: 'F', 6: 'G', 7: 'H',
26
 
27
  @spaces.GPU
28
  def yolo_inference(image, model_id, conf_threshold, iou_threshold, max_detection):
29
- # Download models and get filenames within the same function
30
- model_filenames, model_path = download_models(repo_id, model_id)
31
 
32
  model = YOLO(model_path)
33
  results = model(source=image, imgsz=640, iou=iou_threshold, conf=conf_threshold, verbose=False, max_det=max_detection)[0]
@@ -42,9 +47,6 @@ def yolo_inference(image, model_id, conf_threshold, iou_threshold, max_detection
42
  return annotated_image
43
 
44
  def app():
45
- # Fetch the model filenames directly in the app
46
- model_filenames, _ = download_models(repo_id, "")
47
-
48
  with gr.Blocks():
49
  with gr.Row():
50
  with gr.Column():
@@ -142,4 +144,4 @@ with gradio_app:
142
  with gr.Column():
143
  app()
144
 
145
- gradio_app.launch(debug=True)
 
2
  import supervision as sv
3
  import PIL.Image as Image
4
  from ultralytics import YOLO
5
+ from huggingface_hub import hf_hub_download
6
  import gradio as gr
7
 
8
  global repo_id
9
 
10
  repo_id = "atalaydenknalbant/asl-yolo-models"
11
 
12
+ # Model filenames directly provided, since they are known
13
+ model_filenames = [
14
+ "yolov10s.pt",
15
+ "yolov10x.pt",
16
+ "yolov8s.pt",
17
+ "yolov8x.pt",
18
+ "yolov9e.pt",
19
+ "yolov9s.pt"
20
+ ]
21
+
22
+ def download_models(repo_id, model_id):
23
  # Download the selected model
24
  hf_hub_download(repo_id, filename=model_id, local_dir=f"./")
25
+ return f"./{model_id}"
26
 
27
  box_annotator = sv.BoxAnnotator()
28
  category_dict = {0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'E', 5: 'F', 6: 'G', 7: 'H', 8: 'I',
 
31
 
32
  @spaces.GPU
33
  def yolo_inference(image, model_id, conf_threshold, iou_threshold, max_detection):
34
+ # Download models
35
+ model_path = download_models(repo_id, model_id)
36
 
37
  model = YOLO(model_path)
38
  results = model(source=image, imgsz=640, iou=iou_threshold, conf=conf_threshold, verbose=False, max_det=max_detection)[0]
 
47
  return annotated_image
48
 
49
  def app():
 
 
 
50
  with gr.Blocks():
51
  with gr.Row():
52
  with gr.Column():
 
144
  with gr.Column():
145
  app()
146
 
147
+ gradio_app.launch()