Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -102,16 +102,32 @@ COUNTRY_LOCATIONS = {
|
|
102 |
|
103 |
MAJOR_COUNTRIES = list(COUNTRY_LOCATIONS.keys())
|
104 |
|
|
|
|
|
|
|
|
|
105 |
def translate_query(query, country):
|
106 |
try:
|
107 |
-
#
|
|
|
|
|
|
|
|
|
|
|
108 |
if country == "South Korea":
|
109 |
-
return query[:255]
|
110 |
|
111 |
if country in COUNTRY_LANGUAGES:
|
112 |
query = query[:100]
|
113 |
target_lang = COUNTRY_LANGUAGES[country]
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
translated = hf_client.text_generation(
|
117 |
prompt,
|
@@ -242,9 +258,11 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
242 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
243 |
progress(0, desc="๊ฒ์ ์์...")
|
244 |
|
245 |
-
# ๋ฒ์ญ
|
246 |
translated_query = translate_query(query, country)
|
247 |
-
if
|
|
|
|
|
248 |
translated_display_text = f"๊ฒ์์ด: {query}"
|
249 |
elif translated_query != query:
|
250 |
translated_display_text = f"์๋ณธ ๊ฒ์์ด: {query}\n๋ฒ์ญ๋ ๊ฒ์์ด: {translated_query}"
|
|
|
102 |
|
103 |
MAJOR_COUNTRIES = list(COUNTRY_LOCATIONS.keys())
|
104 |
|
105 |
+
def is_english(text):
|
106 |
+
# ์์ด๋ก๋ง ๊ตฌ์ฑ๋์ด ์๋์ง ํ์ธ
|
107 |
+
return all(ord(char) < 128 for char in text.replace(' ', ''))
|
108 |
+
|
109 |
def translate_query(query, country):
|
110 |
try:
|
111 |
+
# ์์ด ์
๋ ฅ์ธ ๊ฒฝ์ฐ ๋ฒ์ญํ์ง ์๊ณ ๊ทธ๋๋ก ์ฌ์ฉ
|
112 |
+
if is_english(query):
|
113 |
+
print(f"English query detected, using original: {query}")
|
114 |
+
return query[:255]
|
115 |
+
|
116 |
+
# ํ๊ธ ์
๋ ฅ์ด๊ณ South Korea๊ฐ ์ ํ๋ ๊ฒฝ์ฐ
|
117 |
if country == "South Korea":
|
118 |
+
return query[:255]
|
119 |
|
120 |
if country in COUNTRY_LANGUAGES:
|
121 |
query = query[:100]
|
122 |
target_lang = COUNTRY_LANGUAGES[country]
|
123 |
+
|
124 |
+
# ๋ฒ์ญ ํ๋กฌํํธ ๊ฐ์
|
125 |
+
prompt = f"""Translate this text to {target_lang} language.
|
126 |
+
For Japanese, use Kanji and Kana.
|
127 |
+
For Chinese, use Simplified Chinese.
|
128 |
+
For Korean, use Hangul.
|
129 |
+
Only output the translated text without any explanation.
|
130 |
+
Text to translate: {query}"""
|
131 |
|
132 |
translated = hf_client.text_generation(
|
133 |
prompt,
|
|
|
258 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
259 |
progress(0, desc="๊ฒ์ ์์...")
|
260 |
|
261 |
+
# ๋ฒ์ญ ๋ฐ ํ์ ํ
์คํธ ์ฒ๋ฆฌ
|
262 |
translated_query = translate_query(query, country)
|
263 |
+
if is_english(query):
|
264 |
+
translated_display_text = f"์์ด ๊ฒ์์ด: {query}"
|
265 |
+
elif country == "South Korea":
|
266 |
translated_display_text = f"๊ฒ์์ด: {query}"
|
267 |
elif translated_query != query:
|
268 |
translated_display_text = f"์๋ณธ ๊ฒ์์ด: {query}\n๋ฒ์ญ๋ ๊ฒ์์ด: {translated_query}"
|