atalaydenknalbant commited on
Commit
6f78ed1
·
verified ·
1 Parent(s): f075fbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -1,10 +1,10 @@
1
- # Import libraries
2
  import cv2
3
  from ultralytics import YOLO
4
- from huggingface_hub import hf_hub_download # For Hugging Face model download
5
  import gradio as gr
 
 
6
 
7
- # Define constants for ASL letters with color for bounding boxes
8
  ASL_COLORS = {
9
  0: (191, 100, 21), # A
10
  1: (2, 62, 115), # B
@@ -35,13 +35,12 @@ ASL_COLORS = {
35
  }
36
  BOX_PADDING = 2
37
 
38
- # Define the function to download the models dynamically
39
  def download_model(model_id):
40
- # Use Hugging Face's hf_hub_download to download models
41
  model_path = hf_hub_download(repo_id="atalaydenknalbant/asl-yolo-models", filename=model_id, local_dir="./")
42
  return model_path
43
 
44
- # Function for detecting objects (ASL letters) in the image
45
  def detect(image_path, model_id):
46
  """
47
  Output inference image with bounding boxes and ASL letter predictions.
@@ -59,8 +58,8 @@ def detect(image_path, model_id):
59
  return image
60
 
61
  # Predict on image
62
- results = detection_model.predict(source=image, conf=0.2, iou=0.8) # Predict on image
63
- boxes = results[0].boxes # Get bounding boxes
64
 
65
  if len(boxes) == 0:
66
  return image
@@ -102,7 +101,7 @@ def detect(image_path, model_id):
102
 
103
  return image
104
 
105
- # Gradio interface
106
  model_filenames = [
107
  "yolov10s.pt",
108
  "yolov10x.pt",
@@ -112,10 +111,10 @@ model_filenames = [
112
  "yolov9s.pt"
113
  ]
114
 
115
- iface = gr.Interface(fn=detect,
116
  inputs=[gr.Image(label="Upload ASL letter image", type="filepath"),
117
  gr.Dropdown(label="Model", choices=model_filenames, value=model_filenames[0])],
118
  outputs="image")
119
 
120
  # Launch the interface
121
- iface.launch()
 
 
1
  import cv2
2
  from ultralytics import YOLO
3
+ from huggingface_hub import hf_hub_download
4
  import gradio as gr
5
+ import spaces
6
+
7
 
 
8
  ASL_COLORS = {
9
  0: (191, 100, 21), # A
10
  1: (2, 62, 115), # B
 
35
  }
36
  BOX_PADDING = 2
37
 
38
+
39
  def download_model(model_id):
 
40
  model_path = hf_hub_download(repo_id="atalaydenknalbant/asl-yolo-models", filename=model_id, local_dir="./")
41
  return model_path
42
 
43
+ @spaces.GPU
44
  def detect(image_path, model_id):
45
  """
46
  Output inference image with bounding boxes and ASL letter predictions.
 
58
  return image
59
 
60
  # Predict on image
61
+ results = detection_model.predict(source=image, conf=0.2, iou=0.8)
62
+ boxes = results[0].boxes
63
 
64
  if len(boxes) == 0:
65
  return image
 
101
 
102
  return image
103
 
104
+
105
  model_filenames = [
106
  "yolov10s.pt",
107
  "yolov10x.pt",
 
111
  "yolov9s.pt"
112
  ]
113
 
114
+ asl_app = gr.Interface(fn=detect,
115
  inputs=[gr.Image(label="Upload ASL letter image", type="filepath"),
116
  gr.Dropdown(label="Model", choices=model_filenames, value=model_filenames[0])],
117
  outputs="image")
118
 
119
  # Launch the interface
120
+ asl_app.launch()