Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -142,9 +142,23 @@ def get_model() -> tuple[MMAudio, FeaturesUtils, SequenceConfig]:
|
|
142 |
|
143 |
net, feature_utils, seq_cfg = get_model()
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
def translate_prompt(text):
|
146 |
try:
|
147 |
if text and any(ord(char) >= 0x3131 and ord(char) <= 0xD7A3 for char in text):
|
|
|
148 |
with torch.no_grad():
|
149 |
translation = translator(text)[0]['translation_text']
|
150 |
return translation
|
@@ -153,6 +167,22 @@ def translate_prompt(text):
|
|
153 |
logging.error(f"Translation error: {e}")
|
154 |
return text
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
def search_pixabay_videos(query, api_key):
|
157 |
try:
|
158 |
base_url = "https://pixabay.com/api/videos/"
|
@@ -171,11 +201,6 @@ def search_pixabay_videos(query, api_key):
|
|
171 |
logging.error(f"Pixabay API error: {e}")
|
172 |
return []
|
173 |
|
174 |
-
@torch.no_grad()
|
175 |
-
def search_videos(query):
|
176 |
-
with torch.cuda.device("cpu"):
|
177 |
-
query = translate_prompt(query)
|
178 |
-
return search_pixabay_videos(query, PIXABAY_API_KEY)
|
179 |
|
180 |
@spaces.GPU
|
181 |
@torch.inference_mode()
|
|
|
142 |
|
143 |
net, feature_utils, seq_cfg = get_model()
|
144 |
|
145 |
+
|
146 |
+
# search_videos ν¨μ μμ
|
147 |
+
@torch.no_grad()
|
148 |
+
def search_videos(query):
|
149 |
+
try:
|
150 |
+
# CPUμμ λ²μ μ€ν
|
151 |
+
query = translate_prompt(query)
|
152 |
+
return search_pixabay_videos(query, PIXABAY_API_KEY)
|
153 |
+
except Exception as e:
|
154 |
+
logging.error(f"Video search error: {e}")
|
155 |
+
return []
|
156 |
+
|
157 |
+
# translate_prompt ν¨μλ μμ
|
158 |
def translate_prompt(text):
|
159 |
try:
|
160 |
if text and any(ord(char) >= 0x3131 and ord(char) <= 0xD7A3 for char in text):
|
161 |
+
# CPUμμ λ²μ μ€ν
|
162 |
with torch.no_grad():
|
163 |
translation = translator(text)[0]['translation_text']
|
164 |
return translation
|
|
|
167 |
logging.error(f"Translation error: {e}")
|
168 |
return text
|
169 |
|
170 |
+
# λλ°μ΄μ€ μ€μ λΆλΆ μμ
|
171 |
+
if torch.cuda.is_available():
|
172 |
+
device = torch.device("cuda")
|
173 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
174 |
+
torch.backends.cudnn.allow_tf32 = True
|
175 |
+
torch.backends.cudnn.benchmark = True
|
176 |
+
else:
|
177 |
+
device = torch.device("cpu")
|
178 |
+
|
179 |
+
# λ²μκΈ° μ€μ μμ
|
180 |
+
translator = pipeline("translation",
|
181 |
+
model="Helsinki-NLP/opus-mt-ko-en",
|
182 |
+
device="cpu") # λͺ
μμ μΌλ‘ CPU μ§μ
|
183 |
+
|
184 |
+
|
185 |
+
|
186 |
def search_pixabay_videos(query, api_key):
|
187 |
try:
|
188 |
base_url = "https://pixabay.com/api/videos/"
|
|
|
201 |
logging.error(f"Pixabay API error: {e}")
|
202 |
return []
|
203 |
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
@spaces.GPU
|
206 |
@torch.inference_mode()
|