DawnC commited on
Commit
92ab6e7
1 Parent(s): af92408

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -35,6 +35,7 @@ from urllib.parse import quote
35
  from ultralytics import YOLO
36
  import traceback
37
  import spaces
 
38
 
39
  # model_yolo = YOLO('yolov8l.pt')
40
 
@@ -533,6 +534,12 @@ dog_breeds = ["Afghan_Hound", "African_Hunting_Dog", "Airedale", "American_Staff
533
  "Wire-Haired_Fox_Terrier"]
534
 
535
 
 
 
 
 
 
 
536
  class MultiHeadAttention(nn.Module):
537
 
538
  def __init__(self, in_dim, num_heads=8):
@@ -612,7 +619,7 @@ def preprocess_image(image):
612
 
613
  return transform(image).unsqueeze(0)
614
 
615
- @spaces.GPU
616
  async def predict_single_dog(image):
617
  """
618
  Predicts the dog breed using only the classifier.
@@ -645,7 +652,7 @@ async def predict_single_dog(image):
645
 
646
  return probabilities[0], breeds[:3], relative_probs
647
 
648
- @spaces.GPU
649
  async def detect_multiple_dogs(image, conf_threshold=0.3, iou_threshold=0.55):
650
 
651
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
@@ -728,7 +735,7 @@ def create_breed_comparison(breed1: str, breed2: str) -> dict:
728
 
729
  return comparison_data
730
 
731
- @spaces.GPU
732
  async def predict(image):
733
  """
734
  Main prediction function that handles both single and multiple dog detection.
 
35
  from ultralytics import YOLO
36
  import traceback
37
  import spaces
38
+ from functools import wraps
39
 
40
  # model_yolo = YOLO('yolov8l.pt')
41
 
 
534
  "Wire-Haired_Fox_Terrier"]
535
 
536
 
537
+ def gpu_wrapper(f):
538
+ @wraps(f)
539
+ async def wrapped(*args, **kwargs):
540
+ return await spaces.GPU(f)(*args, **kwargs)
541
+ return wrapped
542
+
543
  class MultiHeadAttention(nn.Module):
544
 
545
  def __init__(self, in_dim, num_heads=8):
 
619
 
620
  return transform(image).unsqueeze(0)
621
 
622
+ @gpu_wrapper
623
  async def predict_single_dog(image):
624
  """
625
  Predicts the dog breed using only the classifier.
 
652
 
653
  return probabilities[0], breeds[:3], relative_probs
654
 
655
+ @gpu_wrapper
656
  async def detect_multiple_dogs(image, conf_threshold=0.3, iou_threshold=0.55):
657
 
658
  results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
 
735
 
736
  return comparison_data
737
 
738
+ @gpu_wrapper
739
  async def predict(image):
740
  """
741
  Main prediction function that handles both single and multiple dog detection.