update more logging
Browse files
app.py
CHANGED
@@ -172,6 +172,10 @@ def nllb_trans(article, target_language):
|
|
172 |
|
173 |
|
174 |
def mbart_trans(article, target_language):
|
|
|
|
|
|
|
|
|
175 |
result_lang = detect_lang(article)
|
176 |
if target_language == "English":
|
177 |
target_lang = "en"
|
@@ -180,14 +184,27 @@ def mbart_trans(article, target_language):
|
|
180 |
|
181 |
if result_lang != target_lang:
|
182 |
if target_language == "English":
|
|
|
|
|
|
|
183 |
return mbart_m2en_model.translate(article, target_lang="en")
|
184 |
else:
|
|
|
|
|
|
|
185 |
return mbart_en2m_model.translate(article, target_lang="zh")
|
186 |
else:
|
|
|
|
|
|
|
187 |
return "Error: You chose the same language as the article detected language. Please reselect language and try again."
|
188 |
|
189 |
|
190 |
def m2m_trans(article, target_language):
|
|
|
|
|
|
|
|
|
191 |
result_lang = detect_lang(article)
|
192 |
if target_language == "English":
|
193 |
target_lang = "en"
|
@@ -195,10 +212,19 @@ def m2m_trans(article, target_language):
|
|
195 |
target_lang = "zh"
|
196 |
if result_lang != target_lang:
|
197 |
if target_language == "English":
|
|
|
|
|
|
|
198 |
return m2m_model.translate(article, target_lang)
|
199 |
elif target_language == "Chinese":
|
|
|
|
|
|
|
200 |
return m2m_model.translate(article, target_lang)
|
201 |
else:
|
|
|
|
|
|
|
202 |
return "Error: You chose the same language as the article detected language. Please reselect language and try again."
|
203 |
|
204 |
|
@@ -228,9 +254,6 @@ with gr.Blocks(theme=myTheme) as demo:
|
|
228 |
trans_btn.click(
|
229 |
fn=translate, inputs=[article, toolkit_select, lang_select], outputs=result
|
230 |
)
|
231 |
-
|
232 |
-
logger.info(f"Chose which translation model: {toolkit_select}")
|
233 |
-
logger.info(f"Language selected: {lang_select}")
|
234 |
-
logger.info(f"Translation Result: {result}")
|
235 |
|
236 |
demo.launch()
|
|
|
172 |
|
173 |
|
174 |
def mbart_trans(article, target_language):
|
175 |
+
logger.info(f"Article to translate : {article}")
|
176 |
+
logger.info(f"Chose which translation model: mbart model")
|
177 |
+
logger.info(f"Language selected: {target_language}")
|
178 |
+
|
179 |
result_lang = detect_lang(article)
|
180 |
if target_language == "English":
|
181 |
target_lang = "en"
|
|
|
184 |
|
185 |
if result_lang != target_lang:
|
186 |
if target_language == "English":
|
187 |
+
logger.info(
|
188 |
+
f'Translated Result: {mbart_m2en_model.translate(article, target_lang="en")}'
|
189 |
+
)
|
190 |
return mbart_m2en_model.translate(article, target_lang="en")
|
191 |
else:
|
192 |
+
logger.info(
|
193 |
+
f'Translated Result: {mbart_m2en_model.translate(article, target_lang="zh")}'
|
194 |
+
)
|
195 |
return mbart_en2m_model.translate(article, target_lang="zh")
|
196 |
else:
|
197 |
+
logger.warn(
|
198 |
+
"Error: You chose the same language as the article detected language. Please reselect language and try again."
|
199 |
+
)
|
200 |
return "Error: You chose the same language as the article detected language. Please reselect language and try again."
|
201 |
|
202 |
|
203 |
def m2m_trans(article, target_language):
|
204 |
+
logger.info(f"Article to translate : {article}")
|
205 |
+
logger.info(f"Chose which translation model: m2m model")
|
206 |
+
logger.info(f"Language selected: {target_language}")
|
207 |
+
|
208 |
result_lang = detect_lang(article)
|
209 |
if target_language == "English":
|
210 |
target_lang = "en"
|
|
|
212 |
target_lang = "zh"
|
213 |
if result_lang != target_lang:
|
214 |
if target_language == "English":
|
215 |
+
logger.info(
|
216 |
+
f"Translation Result: {m2m_model.translate(article, target_lang)}"
|
217 |
+
)
|
218 |
return m2m_model.translate(article, target_lang)
|
219 |
elif target_language == "Chinese":
|
220 |
+
logger.info(
|
221 |
+
f"Translation Result: {m2m_model.translate(article, target_lang)}"
|
222 |
+
)
|
223 |
return m2m_model.translate(article, target_lang)
|
224 |
else:
|
225 |
+
logger.warn(
|
226 |
+
f"Error: You chose the same language as the article detected language. Please reselect language and try again."
|
227 |
+
)
|
228 |
return "Error: You chose the same language as the article detected language. Please reselect language and try again."
|
229 |
|
230 |
|
|
|
254 |
trans_btn.click(
|
255 |
fn=translate, inputs=[article, toolkit_select, lang_select], outputs=result
|
256 |
)
|
257 |
+
|
|
|
|
|
|
|
258 |
|
259 |
demo.launch()
|