Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
eng2bem = pipeline(
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
# Define functions
|
| 9 |
def translate(direction, text):
|
| 10 |
if not text.strip():
|
| 11 |
return ""
|
|
@@ -16,7 +27,6 @@ def translate(direction, text):
|
|
| 16 |
result = bem2eng(text)
|
| 17 |
return result[0]["translation_text"]
|
| 18 |
|
| 19 |
-
# Build Gradio UI
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
gr.Markdown(
|
| 22 |
"""
|
|
@@ -48,5 +58,4 @@ with gr.Blocks() as demo:
|
|
| 48 |
fn=translate, inputs=[direction, input_text], outputs=output_text
|
| 49 |
)
|
| 50 |
|
| 51 |
-
# Launch for HF Spaces
|
| 52 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# English → Bemba
|
| 5 |
+
eng2bem = pipeline(
|
| 6 |
+
"translation",
|
| 7 |
+
model="kreasof-ai/nllb-200-600M-eng2bem",
|
| 8 |
+
src_lang="eng_Latn",
|
| 9 |
+
tgt_lang="bem_Latn"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# Bemba → English
|
| 13 |
+
bem2eng = pipeline(
|
| 14 |
+
"translation",
|
| 15 |
+
model="kreasof-ai/nllb-200-600M-bem2eng-bigc-tatoeba",
|
| 16 |
+
src_lang="bem_Latn",
|
| 17 |
+
tgt_lang="eng_Latn"
|
| 18 |
+
)
|
| 19 |
|
|
|
|
| 20 |
def translate(direction, text):
|
| 21 |
if not text.strip():
|
| 22 |
return ""
|
|
|
|
| 27 |
result = bem2eng(text)
|
| 28 |
return result[0]["translation_text"]
|
| 29 |
|
|
|
|
| 30 |
with gr.Blocks() as demo:
|
| 31 |
gr.Markdown(
|
| 32 |
"""
|
|
|
|
| 58 |
fn=translate, inputs=[direction, input_text], outputs=output_text
|
| 59 |
)
|
| 60 |
|
|
|
|
| 61 |
demo.launch()
|