Spaces:
Sleeping
Sleeping
File size: 2,300 Bytes
2a5c515 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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()
|