atalaydenknalbant commited on
Commit
5e9ca47
·
verified ·
1 Parent(s): 636a182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -20
app.py CHANGED
@@ -2,33 +2,21 @@ 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, HfApi
6
  import gradio as gr
7
 
8
  global repo_id
9
 
10
  def download_models(model_id):
11
- hf_hub_download(repo_id, filename = f"{model_id}", local_dir = f"./")
12
  return f"./{model_id}"
13
 
14
- def get_model_filenames(repo_id, file_extension = ".pt"):
15
- api = HfApi()
16
- files = api.list_repo_files(repo_id)
17
- model_filenames = [file for file in files if file.endswith(file_extension)]
18
- return model_filenames
19
-
20
  repo_id = "atalaydenknalbant/asl-yolo-models"
21
- model_filenames = get_model_filenames(repo_id)
22
- print("Model filenames:", model_filenames)
23
-
24
  box_annotator = sv.BoxAnnotator()
25
  category_dict = {0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'E', 5: 'F', 6: 'G', 7: 'H', 8: 'I',
26
  9: 'J', 10: 'K', 11: 'L', 12: 'M', 13: 'N', 14: 'O', 15: 'P', 16: 'Q',
27
  17: 'R', 18: 'S', 19: 'T', 20: 'U', 21: 'V', 22: 'W', 23: 'X', 24: 'Y', 25: 'Z'}
28
 
29
-
30
-
31
-
32
  @spaces.GPU
33
  def yolo_inference(image, model_id, conf_threshold, iou_threshold, max_detection):
34
  model_path = download_models(model_id)
@@ -50,11 +38,8 @@ def app():
50
  with gr.Column():
51
  image = gr.Image(type="pil", label="Image", interactive=True)
52
 
53
- model_id = gr.Dropdown(
54
- label="Model",
55
- choices=model_filenames,
56
- value=model_filenames[0] if model_filenames else "",
57
- )
58
  conf_threshold = gr.Slider(
59
  label="Confidence Threshold",
60
  minimum=0.1,
@@ -142,4 +127,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
  def download_models(model_id):
11
+ hf_hub_download(repo_id, filename=f"{model_id}", local_dir=f"./")
12
  return f"./{model_id}"
13
 
 
 
 
 
 
 
14
  repo_id = "atalaydenknalbant/asl-yolo-models"
 
 
 
15
  box_annotator = sv.BoxAnnotator()
16
  category_dict = {0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'E', 5: 'F', 6: 'G', 7: 'H', 8: 'I',
17
  9: 'J', 10: 'K', 11: 'L', 12: 'M', 13: 'N', 14: 'O', 15: 'P', 16: 'Q',
18
  17: 'R', 18: 'S', 19: 'T', 20: 'U', 21: 'V', 22: 'W', 23: 'X', 24: 'Y', 25: 'Z'}
19
 
 
 
 
20
  @spaces.GPU
21
  def yolo_inference(image, model_id, conf_threshold, iou_threshold, max_detection):
22
  model_path = download_models(model_id)
 
38
  with gr.Column():
39
  image = gr.Image(type="pil", label="Image", interactive=True)
40
 
41
+ model_id = gr.Textbox(label="Model ID", placeholder="Enter model filename (.pt)")
42
+
 
 
 
43
  conf_threshold = gr.Slider(
44
  label="Confidence Threshold",
45
  minimum=0.1,
 
127
  with gr.Column():
128
  app()
129
 
130
+ gradio_app.launch(debug=True)