Spaces:
Running
Running
seawolf2357
commited on
Update app.py
Browse files
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 |
-
#
|
55 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
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:
|