DawnC commited on
Commit
c1fe297
1 Parent(s): dca1ea8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -34,6 +34,7 @@ from html_templates import (
34
  from urllib.parse import quote
35
  from ultralytics import YOLO
36
  import traceback
 
37
 
38
  model_yolo = YOLO('yolov8l.pt')
39
 
@@ -150,7 +151,8 @@ def preprocess_image(image):
150
  ])
151
 
152
  return transform(image).unsqueeze(0)
153
-
 
154
  async def predict_single_dog(image):
155
  """
156
  Predicts the dog breed using only the classifier.
@@ -181,8 +183,9 @@ async def predict_single_dog(image):
181
  print(f"{breed}: {prob:.4f}")
182
 
183
  return probabilities[0], breeds[:3], relative_probs
 
184
 
185
-
186
  async def detect_multiple_dogs(image, conf_threshold=0.3, iou_threshold=0.55):
187
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
188
  dogs = []
@@ -263,8 +266,9 @@ def create_breed_comparison(breed1: str, breed2: str) -> dict:
263
  }
264
 
265
  return comparison_data
 
266
 
267
-
268
  async def predict(image):
269
  """
270
  Main prediction function that handles both single and multiple dog detection.
 
34
  from urllib.parse import quote
35
  from ultralytics import YOLO
36
  import traceback
37
+ import spaces
38
 
39
  model_yolo = YOLO('yolov8l.pt')
40
 
 
151
  ])
152
 
153
  return transform(image).unsqueeze(0)
154
+
155
+ @spaces.GPU
156
  async def predict_single_dog(image):
157
  """
158
  Predicts the dog breed using only the classifier.
 
183
  print(f"{breed}: {prob:.4f}")
184
 
185
  return probabilities[0], breeds[:3], relative_probs
186
+
187
 
188
+ @spaces.GPU
189
  async def detect_multiple_dogs(image, conf_threshold=0.3, iou_threshold=0.55):
190
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
191
  dogs = []
 
266
  }
267
 
268
  return comparison_data
269
+
270
 
271
+ @spaces.GPU
272
  async def predict(image):
273
  """
274
  Main prediction function that handles both single and multiple dog detection.