Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
import gradio as gr | |
# Load translation pipelines | |
translator_en_to_ha = pipeline('translation', model='facebook/nllb-200-distilled-600M') | |
translator_en_to_ig = pipeline('translation', model='facebook/nllb-200-distilled-600M') | |
translator_en_to_yo = pipeline('translation', model='facebook/nllb-200-distilled-600M') | |
translator_ha_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M') | |
translator_ig_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M') | |
translator_yo_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M') | |
def translate(from_text, language): | |
if language == "English to Hausa": | |
result = translator_en_to_ha(from_text, src_lang="eng_Latn", tgt_lang="hau_Latn")[0]['translation_text'] | |
return result | |
elif language == "English to Igbo": | |
result = translator_en_to_ig(from_text, src_lang="eng_Latn", tgt_lang="ibo_Latn")[0]['translation_text'] | |
return result | |
elif language == "English to Yoruba": | |
result = translator_en_to_yo(from_text, src_lang="eng_Latn", tgt_lang="yor_Latn")[0]['translation_text'] | |
return result | |
elif language == "Hausa to English": | |
result = translator_ha_to_en(from_text, src_lang="hau_Latn", tgt_lang="eng_Latn")[0]['translation_text'] | |
return result | |
elif language == "Igbo to English": | |
result = translator_ig_to_en(from_text, src_lang="ibo_Latn", tgt_lang="eng_Latn")[0]['translation_text'] | |
return result | |
elif language == "Yoruba to English": | |
result = translator_yo_to_en(from_text, src_lang="yor_Latn", tgt_lang="eng_Latn")[0]['translation_text'] | |
return result | |
# Set up Gradio interface with dropdown and simplified output | |
interface = gr.Interface( | |
fn=translate, | |
inputs=[ | |
gr.Textbox(lines=2, placeholder="Text to translate", label="Input Text"), | |
gr.Dropdown(["English to Hausa", "English to Igbo", "English to Yoruba", | |
"Hausa to English", "Igbo to English", "Yoruba to English"], | |
label="Translation Direction", value="English to Hausa") | |
], | |
outputs=gr.Textbox(label="Translation Result") # Single output box for the selected translation | |
) | |
# Launch the interface | |
interface.launch() | |