UmarBaba1 commited on
Commit
2a5c515
·
verified ·
1 Parent(s): 95c04d8

Upload 2 files

Browse files
Files changed (2) hide show
  1. applica.py +47 -0
  2. requirements.txt +4 -0
applica.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+
5
+ # Load translation pipelines
6
+ translator_en_to_ha = pipeline('translation', model='facebook/nllb-200-distilled-600M')
7
+ translator_en_to_ig = pipeline('translation', model='facebook/nllb-200-distilled-600M')
8
+ translator_en_to_yo = pipeline('translation', model='facebook/nllb-200-distilled-600M')
9
+
10
+ translator_ha_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')
11
+ translator_ig_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')
12
+ translator_yo_to_en = pipeline('translation', model='facebook/nllb-200-distilled-600M')
13
+
14
+ def 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 result
18
+ 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 result
21
+ 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 result
24
+ 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 result
27
+ 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 result
30
+ 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 result
33
+
34
+ # Set up Gradio interface with dropdown and simplified output
35
+ interface = 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 translation
44
+ )
45
+
46
+ # Launch the interface
47
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ transformers==4.30.2
3
+ gradio==3.36.1
4
+ torch