update radio button labels
Browse files
app.py
CHANGED
@@ -41,26 +41,26 @@ def detect_lang(article, target_lang):
|
|
41 |
return result_lang[0]
|
42 |
|
43 |
|
44 |
-
def opus_trans(article,
|
45 |
"""
|
46 |
Translation by Helsinki-NLP model
|
47 |
|
48 |
Args:
|
49 |
article (string): article that user wishes to translate
|
50 |
result_lang (string): detected language in short form
|
51 |
-
|
52 |
|
53 |
Returns:
|
54 |
-
string: translated piece of article based off
|
55 |
"""
|
56 |
-
if
|
57 |
result_lang = "zh"
|
58 |
-
elif
|
59 |
result_lang = "en"
|
60 |
-
# result_lang = detect_lang(article,
|
61 |
|
62 |
-
task_name = f"translation_{result_lang}_to_{
|
63 |
-
model_name = f"Helsinki-NLP/opus-mt-{result_lang}-{
|
64 |
translator = pipeline(task_name, model=model_name, tokenizer=model_name)
|
65 |
translated = translator(article)[0]["translation_text"]
|
66 |
print(translated)
|
@@ -68,7 +68,7 @@ def opus_trans(article, target_lang):
|
|
68 |
|
69 |
|
70 |
article = gr.Textbox()
|
71 |
-
lang_select = gr.Radio(["
|
72 |
translate = gr.Interface(
|
73 |
opus_trans,
|
74 |
[
|
|
|
41 |
return result_lang[0]
|
42 |
|
43 |
|
44 |
+
def opus_trans(article, target_language):
|
45 |
"""
|
46 |
Translation by Helsinki-NLP model
|
47 |
|
48 |
Args:
|
49 |
article (string): article that user wishes to translate
|
50 |
result_lang (string): detected language in short form
|
51 |
+
target_language (string): language that user wishes to translate article into
|
52 |
|
53 |
Returns:
|
54 |
+
string: translated piece of article based off target_language
|
55 |
"""
|
56 |
+
if target_language == "en":
|
57 |
result_lang = "zh"
|
58 |
+
elif target_language == "zh":
|
59 |
result_lang = "en"
|
60 |
+
# result_lang = detect_lang(article, target_language)
|
61 |
|
62 |
+
task_name = f"translation_{result_lang}_to_{target_language}"
|
63 |
+
model_name = f"Helsinki-NLP/opus-mt-{result_lang}-{target_language}"
|
64 |
translator = pipeline(task_name, model=model_name, tokenizer=model_name)
|
65 |
translated = translator(article)[0]["translation_text"]
|
66 |
print(translated)
|
|
|
68 |
|
69 |
|
70 |
article = gr.Textbox()
|
71 |
+
lang_select = gr.Radio(["English", "Chinese"])
|
72 |
translate = gr.Interface(
|
73 |
opus_trans,
|
74 |
[
|