seawolf2357 commited on
Commit
c2e93cd
·
verified ·
1 Parent(s): da3da43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -51,19 +51,16 @@ def load_gallery_images():
51
 
52
  return [(os.path.join("gallery", row[2]), f"{row[0]}: {row[1]}") for row in rows]
53
 
54
- # 번역기 초기화를 GPU 함수 내부로 이동
55
- @spaces.GPU(duration=70)
56
- def translate_text_gpu(text):
57
- # 번역기를 함수 내부에서 초기화
58
- translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
59
- if any('\u3131' <= char <= '\u3163' or '\uac00' <= char <= '\ud7a3' for char in text):
60
- translated = translator(text)[0]['translation_text']
61
- return text, translated
62
- return text, text
63
 
64
  # 프롬프트 처리 함수
65
  def process_prompt(prompt):
66
- return translate_text_gpu(prompt)
 
 
 
 
67
 
68
  KEY_JSON = os.getenv("KEY_JSON")
69
  with open(KEY_JSON, 'r') as f:
 
51
 
52
  return [(os.path.join("gallery", row[2]), f"{row[0]}: {row[1]}") for row in rows]
53
 
54
+ # CPU에서 실행되는 번역기 초기화
55
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device=-1)
 
 
 
 
 
 
 
56
 
57
  # 프롬프트 처리 함수
58
  def process_prompt(prompt):
59
+ if any('\u3131' <= char <= '\u3163' or '\uac00' <= char <= '\ud7a3' for char in prompt):
60
+ translated = translator(prompt)[0]['translation_text']
61
+ return prompt, translated
62
+ return prompt, prompt
63
+
64
 
65
  KEY_JSON = os.getenv("KEY_JSON")
66
  with open(KEY_JSON, 'r') as f: