UmarBaba1/NaijaLanguagesTranslator
0
1 2from transformers import pipeline3import gradio as gr4 5# Load translation pipelines6translator_en_to_ha = pipeline('translation', model='facebook/nllb-200-distilled-600M')7translator_en_to_ig = pipeline('translation', model='facebook/nllb-200-distilled-600M')8translator_en_to_yo = pipeline('translation', model='facebook/nllb-200-distilled-600M')9 10translator_ha_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')11translator_ig_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')12translator_yo_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')13 14def translate(from_text, language):15 if language == "English to Hausa":16 result = translator_en_to_ha(from_text, src_lang="eng_Latn", tgt_lang="hau_Latn")[0]['translation_text']17 return result18 elif language == "English to Igbo":19 result = translator_en_to_ig(from_text, src_lang="eng_Latn", tgt_lang="ibo_Latn")[0]['translation_text']20 return result21 elif language == "English to Yoruba":22 result = translator_en_to_yo(from_text, src_lang="eng_Latn", tgt_lang="yor_Latn")[0]['translation_text']23 return result24 elif language == "Hausa to English":25 result = translator_ha_to_en(from_text, src_lang="hau_Latn", tgt_lang="eng_Latn")[0]['translation_text']26 return result27 elif language == "Igbo to English":28 result = translator_ig_to_en(from_text, src_lang="ibo_Latn", tgt_lang="eng_Latn")[0]['translation_text']29 return result30 elif language == "Yoruba to English":31 result = translator_yo_to_en(from_text, src_lang="yor_Latn", tgt_lang="eng_Latn")[0]['translation_text']32 return result33 34# Set up Gradio interface with dropdown and simplified output35interface = gr.Interface(36 fn=translate,37 inputs=[38 gr.Textbox(lines=2, placeholder="Text to translate", label="Input Text"),39 gr.Dropdown(["English to Hausa", "English to Igbo", "English to Yoruba",40 "Hausa to English", "Igbo to English", "Yoruba to English"],41 label="Translation Direction", value="English to Hausa")42 ],43 outputs=gr.Textbox(label="Translation Result") # Single output box for the selected translation44)45 46# Launch the interface47interface.launch()48 