Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,44 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# Load translation pipelines
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
result =
|
| 17 |
-
return result
|
| 18 |
-
elif language == "
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
result
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
result =
|
| 29 |
-
return result
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
# Launch the interface
|
| 47 |
-
interface.launch()
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def translate(from_text, language):
|
| 5 |
+
# Load translation pipelines lazily
|
| 6 |
+
if language == "English to Hausa":
|
| 7 |
+
translator_en_to_ha = pipeline('translation', model='facebook/nllb-200-distilled-600M')
|
| 8 |
+
result = translator_en_to_ha(from_text, src_lang="eng_Latn", tgt_lang="hau_Latn")[0]['translation_text']
|
| 9 |
+
return result
|
| 10 |
+
elif language == "English to Igbo":
|
| 11 |
+
translator_en_to_ig = pipeline('translation', model='facebook/nllb-200-distilled-600M')
|
| 12 |
+
result = translator_en_to_ig(from_text, src_lang="eng_Latn", tgt_lang="ibo_Latn")[0]['translation_text']
|
| 13 |
+
return result
|
| 14 |
+
elif language == "English to Yoruba":
|
| 15 |
+
translator_en_to_yo = pipeline('translation', model='facebook/nllb-200-distilled-600M')
|
| 16 |
+
result = translator_en_to_yo(from_text, src_lang="eng_Latn", tgt_lang="yor_Latn")[0]['translation_text']
|
| 17 |
+
return result
|
| 18 |
+
elif language == "Hausa to English":
|
| 19 |
+
translator_ha_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')
|
| 20 |
+
result = translator_ha_to_en(from_text, src_lang="hau_Latn", tgt_lang="eng_Latn")[0]['translation_text']
|
| 21 |
+
return result
|
| 22 |
+
elif language == "Igbo to English":
|
| 23 |
+
translator_ig_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')
|
| 24 |
+
result = translator_ig_to_en(from_text, src_lang="ibo_Latn", tgt_lang="eng_Latn")[0]['translation_text']
|
| 25 |
+
return result
|
| 26 |
+
elif language == "Yoruba to English":
|
| 27 |
+
translator_yo_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')
|
| 28 |
+
result = translator_yo_to_en(from_text, src_lang="yor_Latn", tgt_lang="eng_Latn")[0]['translation_text']
|
| 29 |
+
return result
|
| 30 |
+
|
| 31 |
+
# Set up Gradio interface with dropdown and simplified output
|
| 32 |
+
interface = gr.Interface(
|
| 33 |
+
fn=translate,
|
| 34 |
+
inputs=[
|
| 35 |
+
gr.Textbox(lines=2, placeholder="Text to translate", label="Input Text"),
|
| 36 |
+
gr.Dropdown(["English to Hausa", "English to Igbo", "English to Yoruba",
|
| 37 |
+
"Hausa to English", "Igbo to English", "Yoruba to English"],
|
| 38 |
+
label="Translation Direction", value="English to Hausa")
|
| 39 |
+
],
|
| 40 |
+
outputs=gr.Textbox(label="Translation Result") # Single output box for the selected translation
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Launch the interface
|
| 44 |
+
interface.launch()
|
|
|
|
|
|
|
|
|