Update app.py
Browse files141 unmodified lines1421431441451461471481491501511521531541551561571581591601611621631642 unmodified lines16716816917017117217317417517617717817918018118218318418518618718812 unmodified lines201202203174175176177178204205206141 unmodified lines
net, feature_utils, seq_cfg = get_model()
# search_videos ํจ์ ์์ @torch.no_grad()def search_videos(query): try: # CPU์์ ๋ฒ์ญ ์คํ query = translate_prompt(query) return search_pixabay_videos(query, PIXABAY_API_KEY) except Exception as e: logging.error(f"Video search error: {e}") return []
# translate_prompt ํจ์๋ ์์ def translate_prompt(text): try: if text and any(ord(char) >= 0x3131 and ord(char) <= 0xD7A3 for char in text): # CPU์์ ๋ฒ์ญ ์คํ with torch.no_grad(): translation = translator(text)[0]['translation_text'] return translation2 unmodified lines logging.error(f"Translation error: {e}") return text
# ๋๋ฐ์ด์ค ์ค์ ๋ถ๋ถ ์์ if torch.cuda.is_available(): device = torch.device("cuda") torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = True torch.backends.cudnn.benchmark = Trueelse: device = torch.device("cpu")
# ๋ฒ์ญ๊ธฐ ์ค์ ์์ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu") # ๋ช
์์ ์ผ๋ก CPU ์ง์
def search_pixabay_videos(query, api_key): try: base_url = "https://pixabay.com/api/videos/"12 unmodified lines logging.error(f"Pixabay API error: {e}") return []
@torch.no_grad()def search_videos(query): with torch.cuda.device("cpu"): query = translate_prompt(query) return search_pixabay_videos(query, PIXABAY_API_KEY)
@spaces.GPU@torch.inference_mode()app.py+30-5