Spaces:
Running
on
Zero
Running
on
Zero
Update smart_breed_matcher.py
Browse files- smart_breed_matcher.py +11 -0
smart_breed_matcher.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import torch
|
2 |
import re
|
3 |
import numpy as np
|
|
|
4 |
from typing import List, Dict, Tuple, Optional
|
5 |
from dataclasses import dataclass
|
6 |
from breed_health_info import breed_health_info
|
@@ -8,6 +9,15 @@ from breed_noise_info import breed_noise_info
|
|
8 |
from dog_database import dog_data
|
9 |
from scoring_calculation_system import UserPreferences
|
10 |
from sentence_transformers import SentenceTransformer, util
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
class SmartBreedMatcher:
|
13 |
def __init__(self, dog_data: List[Tuple]):
|
@@ -857,6 +867,7 @@ class SmartBreedMatcher:
|
|
857 |
'good_with_children': False
|
858 |
}
|
859 |
|
|
|
860 |
def match_user_preference(self, description: str, top_n: int = 10) -> List[Dict]:
|
861 |
try:
|
862 |
# 獲取場景權重
|
|
|
1 |
import torch
|
2 |
import re
|
3 |
import numpy as np
|
4 |
+
import spaces
|
5 |
from typing import List, Dict, Tuple, Optional
|
6 |
from dataclasses import dataclass
|
7 |
from breed_health_info import breed_health_info
|
|
|
9 |
from dog_database import dog_data
|
10 |
from scoring_calculation_system import UserPreferences
|
11 |
from sentence_transformers import SentenceTransformer, util
|
12 |
+
from functools import wraps
|
13 |
+
|
14 |
+
def gpu_init_wrapper(func):
|
15 |
+
@spaces.GPU
|
16 |
+
@wraps(func)
|
17 |
+
def wrapper(*args, **kwargs):
|
18 |
+
return func(*args, **kwargs)
|
19 |
+
return wrapper
|
20 |
+
|
21 |
|
22 |
class SmartBreedMatcher:
|
23 |
def __init__(self, dog_data: List[Tuple]):
|
|
|
867 |
'good_with_children': False
|
868 |
}
|
869 |
|
870 |
+
@gpu_init_wrapper
|
871 |
def match_user_preference(self, description: str, top_n: int = 10) -> List[Dict]:
|
872 |
try:
|
873 |
# 獲取場景權重
|