logic change
Browse files
app.py
CHANGED
@@ -77,10 +77,6 @@ class myTheme(Base):
|
|
77 |
)
|
78 |
|
79 |
|
80 |
-
def on_select(evt: gr.SelectData): # SelectData is a subclass of EventData
|
81 |
-
return evt.value
|
82 |
-
|
83 |
-
|
84 |
def detect_lang(article):
|
85 |
"""
|
86 |
Language Detection using library langid
|
@@ -109,6 +105,7 @@ def opus_trans(article, target_language):
|
|
109 |
Returns:
|
110 |
string: translated piece of article based off target_language
|
111 |
"""
|
|
|
112 |
result_lang = detect_lang(article)
|
113 |
|
114 |
if target_language == "English":
|
@@ -135,24 +132,25 @@ def nllb_trans(article, target_language):
|
|
135 |
pass
|
136 |
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
myTheme = myTheme()
|
139 |
|
140 |
with gr.Blocks(theme=myTheme) as demo:
|
141 |
article = gr.Textbox(label="Article")
|
142 |
-
toolkit_select = gr.
|
143 |
lang_select = gr.Radio(["English", "Chinese"], label="Select Desired Language")
|
144 |
result = gr.Textbox(label="Translated Result")
|
145 |
trans_btn = gr.Button("Translate")
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
# if selected == "OPUS":
|
151 |
-
# print(" chosen OPUS")
|
152 |
-
|
153 |
-
# trans_btn.click(fn=opus_trans, inputs=[article, lang_select], outputs=result)
|
154 |
-
# elif selected == "NLLB":
|
155 |
-
# print(" chosen NLLB")
|
156 |
-
# trans_btn = gr.Button("Translate")
|
157 |
-
# trans_btn.click(fn=nllb_trans, inputs=[article, lang_select], outputs=result)
|
158 |
demo.launch()
|
|
|
77 |
)
|
78 |
|
79 |
|
|
|
|
|
|
|
|
|
80 |
def detect_lang(article):
|
81 |
"""
|
82 |
Language Detection using library langid
|
|
|
105 |
Returns:
|
106 |
string: translated piece of article based off target_language
|
107 |
"""
|
108 |
+
|
109 |
result_lang = detect_lang(article)
|
110 |
|
111 |
if target_language == "English":
|
|
|
132 |
pass
|
133 |
|
134 |
|
135 |
+
def translate(article, toolkit, target_language):
|
136 |
+
if toolkit == "OPUS":
|
137 |
+
translated = opus_trans(article, target_language)
|
138 |
+
elif toolkit == "NLLB":
|
139 |
+
pass
|
140 |
+
|
141 |
+
return translated
|
142 |
+
|
143 |
+
|
144 |
myTheme = myTheme()
|
145 |
|
146 |
with gr.Blocks(theme=myTheme) as demo:
|
147 |
article = gr.Textbox(label="Article")
|
148 |
+
toolkit_select = gr.Radio(["OPUS", "NLLB"], label="Select Translation Model")
|
149 |
lang_select = gr.Radio(["English", "Chinese"], label="Select Desired Language")
|
150 |
result = gr.Textbox(label="Translated Result")
|
151 |
trans_btn = gr.Button("Translate")
|
152 |
+
trans_btn.click(
|
153 |
+
fn=translate, inputs=[article, toolkit_select, lang_select], outputs=result
|
154 |
+
)
|
155 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
demo.launch()
|