mahmudunnabi commited on
Commit
b2abd28
1 Parent(s): 40c18b0

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +62 -0
  2. languages.py +205 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import warnings
2
+ warnings.filterwarnings('ignore')
3
+
4
+ import gradio as gr
5
+ import langid
6
+ import langcodes
7
+ from transformers import pipeline
8
+ import torch
9
+ from languages import languages
10
+
11
+ # Initialize the translation pipeline
12
+ translator = pipeline(task='translation', model="facebook/nllb-200-distilled-600M", torch_dtype=torch.bfloat16)
13
+
14
+
15
+ # Define the translation function
16
+ def translate_text(text, tgt_lang):
17
+ # Detect source language
18
+ src_lang_code, _ = langid.classify(text)
19
+ tgt_lang_code = languages[tgt_lang]
20
+ src_language_name = langcodes.Language.get(src_lang_code).language_name()
21
+ # Translate text
22
+ text_translated = translator(text, src_lang=src_lang_code, tgt_lang=tgt_lang_code)
23
+ return src_language_name, text_translated[0]['translation_text']
24
+
25
+
26
+ detected_lang = gr.Textbox(label="Detected Source Language")
27
+
28
+ # Create the Gradio interface
29
+ iface = gr.Interface(
30
+ fn=translate_text,
31
+ inputs=[
32
+ gr.Textbox(lines=2, placeholder="Enter text here...", label = "Input Text.."),
33
+ gr.Dropdown(list(languages.keys()), label="Target Language")
34
+ ],
35
+ outputs=[
36
+ detected_lang,
37
+ gr.Textbox(label="Translation"),
38
+
39
+ ],
40
+ allow_flagging = 'never',
41
+ description="Translates text from one language to another using the NLLB model with automatic source language detection."
42
+ )
43
+
44
+ # Add Markdown content
45
+ markdown_content_translation = gr.Markdown(
46
+ """
47
+ <div style='text-align: center; font-family: "Times New Roman";'>
48
+ <h1 style='color: #FF6347;'>Multilingual Machine Translation</h1>
49
+ <h3 style='color: #4682B4;'>Model: facebook/nllb-200-distilled-600M</h3>
50
+ <h3 style='color: #32CD32;'>Made By: Md. Mahmudun Nabi</h3>
51
+ </div>
52
+ """
53
+ )
54
+
55
+ # Combine the Markdown content and the demo interface
56
+ translation_with_markdown = gr.Blocks()
57
+ with translation_with_markdown:
58
+ markdown_content_translation.render()
59
+ iface.render()
60
+ # Launch the Gradio app
61
+ if __name__ == "__main__":
62
+ translation_with_markdown.launch()
languages.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Language details
2
+ languages = {
3
+ "Achinese (Arabic script)": "ace_Arab",
4
+ "Achinese (Latin script)": "ace_Latn",
5
+ "Mesopotamian Arabic": "acm_Arab",
6
+ "Ta'izzi-Adeni Arabic": "acq_Arab",
7
+ "Tunisian Arabic": "aeb_Arab",
8
+ "Afrikaans": "afr_Latn",
9
+ "South Levantine Arabic": "ajp_Arab",
10
+ "Akan": "aka_Latn",
11
+ "Amharic": "amh_Ethi",
12
+ "North Levantine Arabic": "apc_Arab",
13
+ "Standard Arabic": "arb_Arab",
14
+ "Najdi Arabic": "ars_Arab",
15
+ "Moroccan Arabic": "ary_Arab",
16
+ "Egyptian Arabic": "arz_Arab",
17
+ "Assamese": "asm_Beng",
18
+ "Asturian": "ast_Latn",
19
+ "Awadhi": "awa_Deva",
20
+ "Aymara": "ayr_Latn",
21
+ "South Azerbaijani": "azb_Arab",
22
+ "North Azerbaijani": "azj_Latn",
23
+ "Bashkir": "bak_Cyrl",
24
+ "Bambara": "bam_Latn",
25
+ "Balinese": "ban_Latn",
26
+ "Belarusian": "bel_Cyrl",
27
+ "Bemba": "bem_Latn",
28
+ "Bengali": "ben_Beng",
29
+ "Bhojpuri": "bho_Deva",
30
+ "Banjar (Arabic script)": "bjn_Arab",
31
+ "Banjar (Latin script)": "bjn_Latn",
32
+ "Tibetan": "bod_Tibt",
33
+ "Bosnian": "bos_Latn",
34
+ "Buginese": "bug_Latn",
35
+ "Bulgarian": "bul_Cyrl",
36
+ "Catalan": "cat_Latn",
37
+ "Cebuano": "ceb_Latn",
38
+ "Czech": "ces_Latn",
39
+ "Chokwe": "cjk_Latn",
40
+ "Central Kurdish": "ckb_Arab",
41
+ "Crimean Tatar": "crh_Latn",
42
+ "Welsh": "cym_Latn",
43
+ "Danish": "dan_Latn",
44
+ "German": "deu_Latn",
45
+ "Dinka": "dik_Latn",
46
+ "Dyula": "dyu_Latn",
47
+ "Dzongkha": "dzo_Tibt",
48
+ "Greek": "ell_Grek",
49
+ "English": "eng_Latn",
50
+ "Esperanto": "epo_Latn",
51
+ "Estonian": "est_Latn",
52
+ "Basque": "eus_Latn",
53
+ "Ewe": "ewe_Latn",
54
+ "Faroese": "fao_Latn",
55
+ "Persian": "pes_Arab",
56
+ "Fijian": "fij_Latn",
57
+ "Finnish": "fin_Latn",
58
+ "Fon": "fon_Latn",
59
+ "French": "fra_Latn",
60
+ "Friulian": "fur_Latn",
61
+ "Nigerian Fulfulde": "fuv_Latn",
62
+ "Scottish Gaelic": "gla_Latn",
63
+ "Irish": "gle_Latn",
64
+ "Galician": "glg_Latn",
65
+ "Guarani": "grn_Latn",
66
+ "Gujarati": "guj_Gujr",
67
+ "Haitian Creole": "hat_Latn",
68
+ "Hausa": "hau_Latn",
69
+ "Hebrew": "heb_Hebr",
70
+ "Hindi": "hin_Deva",
71
+ "Chhattisgarhi": "hne_Deva",
72
+ "Croatian": "hrv_Latn",
73
+ "Hungarian": "hun_Latn",
74
+ "Armenian": "hye_Armn",
75
+ "Igbo": "ibo_Latn",
76
+ "Ilocano": "ilo_Latn",
77
+ "Indonesian": "ind_Latn",
78
+ "Icelandic": "isl_Latn",
79
+ "Italian": "ita_Latn",
80
+ "Javanese": "jav_Latn",
81
+ "Japanese": "jpn_Jpan",
82
+ "Kabyle": "kab_Latn",
83
+ "Jingpho": "kac_Latn",
84
+ "Kamba": "kam_Latn",
85
+ "Kannada": "kan_Knda",
86
+ "Kashmiri (Arabic script)": "kas_Arab",
87
+ "Kashmiri (Devanagari script)": "kas_Deva",
88
+ "Georgian": "kat_Geor",
89
+ "Central Kanuri (Arabic script)": "knc_Arab",
90
+ "Central Kanuri (Latin script)": "knc_Latn",
91
+ "Kazakh": "kaz_Cyrl",
92
+ "Kabiyè": "kbp_Latn",
93
+ "Kabuverdianu": "kea_Latn",
94
+ "Khmer": "khm_Khmr",
95
+ "Kikuyu": "kik_Latn",
96
+ "Kinyarwanda": "kin_Latn",
97
+ "Kyrgyz": "kir_Cyrl",
98
+ "Kimbundu": "kmb_Latn",
99
+ "Kikongo": "kon_Latn",
100
+ "Korean": "kor_Hang",
101
+ "Northern Kurdish": "kmr_Latn",
102
+ "Lao": "lao_Laoo",
103
+ "Latvian": "lvs_Latn",
104
+ "Ligurian": "lij_Latn",
105
+ "Limburgish": "lim_Latn",
106
+ "Lingala": "lin_Latn",
107
+ "Lithuanian": "lit_Latn",
108
+ "Lombard": "lmo_Latn",
109
+ "Latgalian": "ltg_Latn",
110
+ "Luxembourgish": "ltz_Latn",
111
+ "Luba-Lulua": "lua_Latn",
112
+ "Ganda": "lug_Latn",
113
+ "Luo": "luo_Latn",
114
+ "Mizo": "lus_Latn",
115
+ "Magahi": "mag_Deva",
116
+ "Maithili": "mai_Deva",
117
+ "Malayalam": "mal_Mlym",
118
+ "Marathi": "mar_Deva",
119
+ "Minangkabau": "min_Latn",
120
+ "Macedonian": "mkd_Cyrl",
121
+ "Plateau Malagasy": "plt_Latn",
122
+ "Maltese": "mlt_Latn",
123
+ "Manipuri": "mni_Beng",
124
+ "Mongolian": "khk_Cyrl",
125
+ "Mossi": "mos_Latn",
126
+ "Maori": "mri_Latn",
127
+ "Standard Malay": "zsm_Latn",
128
+ "Burmese": "mya_Mymr",
129
+ "Dutch": "nld_Latn",
130
+ "Norwegian Nynorsk": "nno_Latn",
131
+ "Norwegian Bokmål": "nob_Latn",
132
+ "Nepali": "npi_Deva",
133
+ "Northern Sotho": "nso_Latn",
134
+ "Nuer": "nus_Latn",
135
+ "Nyanja": "nya_Latn",
136
+ "Occitan": "oci_Latn",
137
+ "Oromo": "gaz_Latn",
138
+ "Odia": "ory_Orya",
139
+ "Pangasinan": "pag_Latn",
140
+ "Punjabi (Gurmukhi script)": "pan_Guru",
141
+ "Papiamento": "pap_Latn",
142
+ "Polish": "pol_Latn",
143
+ "Portuguese": "por_Latn",
144
+ "Dari": "prs_Arab",
145
+ "Southern Pashto": "pbt_Arab",
146
+ "Quechua": "quy_Latn",
147
+ "Romanian": "ron_Latn",
148
+ "Rundi": "run_Latn",
149
+ "Russian": "rus_Cyrl",
150
+ "Sango": "sag_Latn",
151
+ "Sanskrit": "san_Deva",
152
+ "Santali": "sat_Beng",
153
+ "Sicilian": "scn_Latn",
154
+ "Shan": "shn_Mymr",
155
+ "Sinhala": "sin_Sinh",
156
+ "Slovak": "slk_Latn",
157
+ "Slovenian": "slv_Latn",
158
+ "Samoan": "smo_Latn",
159
+ "Shona": "sna_Latn",
160
+ "Sindhi": "snd_Arab",
161
+ "Somali": "som_Latn",
162
+ "Southern Sotho": "sot_Latn",
163
+ "Spanish": "spa_Latn",
164
+ "Albanian": "als_Latn",
165
+ "Sardinian": "srd_Latn",
166
+ "Serbian": "srp_Cyrl",
167
+ "Swati": "ssw_Latn",
168
+ "Sundanese": "sun_Latn",
169
+ "Swedish": "swe_Latn",
170
+ "Swahili": "swh_Latn",
171
+ "Silesian": "szl_Latn",
172
+ "Tamil": "tam_Taml",
173
+ "Tatar": "tat_Cyrl",
174
+ "Telugu": "tel_Telu",
175
+ "Tajik": "tgk_Cyrl",
176
+ "Tagalog": "tgl_Latn",
177
+ "Thai": "tha_Thai",
178
+ "Tigrinya": "tir_Ethi",
179
+ "Tamasheq (Latin script)": "taq_Latn",
180
+ "Tamasheq (Tifinagh script)": "taq_Tfng",
181
+ "Tok Pisin": "tpi_Latn",
182
+ "Tswana": "tsn_Latn",
183
+ "Tsonga": "tso_Latn",
184
+ "Turkmen": "tuk_Latn",
185
+ "Tumbuka": "tum_Latn",
186
+ "Turkish": "tur_Latn",
187
+ "Twi": "twi_Latn",
188
+ "Central Atlas Tamazight": "tzm_Tfng",
189
+ "Uyghur": "uig_Arab",
190
+ "Ukrainian": "ukr_Cyrl",
191
+ "Umbundu": "umb_Latn",
192
+ "Urdu": "urd_Arab",
193
+ "Northern Uzbek": "uzn_Latn",
194
+ "Venetian": "vec_Latn",
195
+ "Vietnamese": "vie_Latn",
196
+ "Waray": "war_Latn",
197
+ "Wolof": "wol_Latn",
198
+ "Xhosa": "xho_Latn",
199
+ "Yiddish": "ydd_Hebr",
200
+ "Yoruba": "yor_Latn",
201
+ "Cantonese": "yue_Hant",
202
+ "Simplified Chinese": "zho_Hans",
203
+ "Traditional Chinese": "zho_Hant",
204
+ "Zulu": "zul_Latn"
205
+ }
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ langid
4
+ langcodes
5
+ torch