avans06 commited on
Commit
db65615
1 Parent(s): 90c1d05

Added new options 'EnableBilingual' and 'DetectLineBreaks' to the Translation page.

Browse files

EnableBilingual: Determines whether to enable bilingual translation results (default True).
DetectLineBreaks: Determines whether to enable detecting line breaks in the text. If enabled, it will concatenate lines before translation (default is False).

Increase the default value of the 'no_repeat_ngram_size' option in Translation to 4.
Increase the default value of the 'num_beams' option in Translation to 3.

app.py CHANGED
@@ -40,8 +40,8 @@ from src.whisper.whisperFactory import create_whisper_container
40
  from src.translation.translationModel import TranslationModel
41
  from src.translation.translationLangs import (TranslationLang,
42
  _TO_LANG_CODE_WHISPER, sort_lang_by_whisper_codes,
43
- get_lang_from_whisper_name, get_lang_from_whisper_code, get_lang_from_nllb_name, get_lang_from_m2m100_name, get_lang_from_seamlessTx_name,
44
- get_lang_whisper_names, get_lang_nllb_names, get_lang_m2m100_names, get_lang_seamlessTx_names)
45
  import re
46
  import shutil
47
  import zhconv
@@ -842,6 +842,9 @@ class WhisperTranscriber:
842
 
843
  progress(0, desc="init translate model")
844
  translationLang, translationModel = self.initTranslationModel(inputLangName, inputLang, dataDict)
 
 
 
845
 
846
  result = []
847
  if translationModel and translationModel.translationLang:
@@ -852,13 +855,31 @@ class WhisperTranscriber:
852
 
853
  perf_start_time = time.perf_counter()
854
  translationModel.load_model()
 
 
 
 
 
 
 
855
  for idx, text in enumerate(tqdm.tqdm(inputTexts)):
856
  if not text or re.match("""^[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~\d ]+$""", text.strip()):
 
 
 
857
  result.append(text)
858
  else:
859
- result.append(translationModel.translation(text))
 
 
 
 
 
860
  progress((idx+1)/len(inputTexts), desc=f"Process inputText: {idx+1}/{len(inputTexts)}")
861
 
 
 
 
862
  translationModel.release_vram()
863
  perf_end_time = time.perf_counter()
864
  # Call the finished callback
@@ -932,7 +953,7 @@ class WhisperTranscriber:
932
  elif translateInput == "seamless" and seamlessLangName is not None and len(seamlessLangName) > 0:
933
  selectedModelName = seamlessModelName if seamlessModelName is not None and len(seamlessModelName) > 0 else "seamless-m4t-v2-large/facebook"
934
  selectedModel = next((modelConfig for modelConfig in self.app_config.models["seamless"] if modelConfig.name == selectedModelName), None)
935
- translationLang = get_lang_from_seamlessTx_name(seamlessLangName)
936
 
937
  if translationLang is not None:
938
  translationModel = TranslationModel(modelConfig=selectedModel, whisperLang=inputLang, translationLang=translationLang, batchSize=translationBatchSize, noRepeatNgramSize=translationNoRepeatNgramSize, numBeams=translationNumBeams, torchDtypeFloat16=translationTorchDtypeFloat16, usingBitsandbytes=translationUsingBitsandbytes)
@@ -1034,7 +1055,7 @@ def create_ui(app_config: ApplicationConfig):
1034
  }
1035
  common_seamless_inputs = lambda : {
1036
  gr.Dropdown(label="seamless - Model (for translate)", choices=seamless_models, elem_id="seamlessModelName"),
1037
- gr.Dropdown(label="seamless - Language", choices=sorted(get_lang_seamlessTx_names()), elem_id="seamlessLangName"),
1038
  }
1039
 
1040
  common_translation_inputs = lambda : {
@@ -1243,6 +1264,8 @@ def create_ui(app_config: ApplicationConfig):
1243
  with gr.Column():
1244
  with gr.Accordion("Translation options", open=False):
1245
  inputDict.update(common_translation_inputs())
 
 
1246
  with gr.Column():
1247
  outputs = [gr.Text(label="Translation Text", autoscroll=False, show_copy_button=True, interactive=True, elem_id="outputTranslationText", elem_classes="scroll-show"),]
1248
  if translateModelMd is not None:
 
40
  from src.translation.translationModel import TranslationModel
41
  from src.translation.translationLangs import (TranslationLang,
42
  _TO_LANG_CODE_WHISPER, sort_lang_by_whisper_codes,
43
+ get_lang_from_whisper_name, get_lang_from_whisper_code, get_lang_from_nllb_name, get_lang_from_m2m100_name, get_lang_from_seamlessT_Tx_name,
44
+ get_lang_whisper_names, get_lang_nllb_names, get_lang_m2m100_names, get_lang_seamlessT_Tx_names)
45
  import re
46
  import shutil
47
  import zhconv
 
842
 
843
  progress(0, desc="init translate model")
844
  translationLang, translationModel = self.initTranslationModel(inputLangName, inputLang, dataDict)
845
+
846
+ translationEnbaleBilingual: bool = dataDict.pop("translationEnbaleBilingual")
847
+ translationDetectLineBreaks: bool = dataDict.pop("translationDetectLineBreaks")
848
 
849
  result = []
850
  if translationModel and translationModel.translationLang:
 
855
 
856
  perf_start_time = time.perf_counter()
857
  translationModel.load_model()
858
+
859
+ def doTranslation(text: str):
860
+ if translationEnbaleBilingual:
861
+ result.append(text)
862
+ result.append(translationModel.translation(text))
863
+
864
+ temporaryText = ""
865
  for idx, text in enumerate(tqdm.tqdm(inputTexts)):
866
  if not text or re.match("""^[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~\d ]+$""", text.strip()):
867
+ if temporaryText:
868
+ doTranslation(temporaryText)
869
+ temporaryText = ""
870
  result.append(text)
871
  else:
872
+ if translationDetectLineBreaks and ((not text.rstrip().endswith(".") and not text.rstrip().endswith("。")) or temporaryText):
873
+ if temporaryText:
874
+ temporaryText = temporaryText.rstrip() + " "
875
+ temporaryText += text
876
+ continue
877
+ doTranslation(text)
878
  progress((idx+1)/len(inputTexts), desc=f"Process inputText: {idx+1}/{len(inputTexts)}")
879
 
880
+ if temporaryText:
881
+ doTranslation(temporaryText)
882
+
883
  translationModel.release_vram()
884
  perf_end_time = time.perf_counter()
885
  # Call the finished callback
 
953
  elif translateInput == "seamless" and seamlessLangName is not None and len(seamlessLangName) > 0:
954
  selectedModelName = seamlessModelName if seamlessModelName is not None and len(seamlessModelName) > 0 else "seamless-m4t-v2-large/facebook"
955
  selectedModel = next((modelConfig for modelConfig in self.app_config.models["seamless"] if modelConfig.name == selectedModelName), None)
956
+ translationLang = get_lang_from_seamlessT_Tx_name(seamlessLangName)
957
 
958
  if translationLang is not None:
959
  translationModel = TranslationModel(modelConfig=selectedModel, whisperLang=inputLang, translationLang=translationLang, batchSize=translationBatchSize, noRepeatNgramSize=translationNoRepeatNgramSize, numBeams=translationNumBeams, torchDtypeFloat16=translationTorchDtypeFloat16, usingBitsandbytes=translationUsingBitsandbytes)
 
1055
  }
1056
  common_seamless_inputs = lambda : {
1057
  gr.Dropdown(label="seamless - Model (for translate)", choices=seamless_models, elem_id="seamlessModelName"),
1058
+ gr.Dropdown(label="seamless - Language", choices=sorted(get_lang_seamlessT_Tx_names()), elem_id="seamlessLangName"),
1059
  }
1060
 
1061
  common_translation_inputs = lambda : {
 
1264
  with gr.Column():
1265
  with gr.Accordion("Translation options", open=False):
1266
  inputDict.update(common_translation_inputs())
1267
+ inputDict.update({ gr.Checkbox(label="Translation - Enbale bilingual", value=True, info="Determines whether to enable bilingual translation results", elem_id="translationEnbaleBilingual"),
1268
+ gr.Checkbox(label="Translation - Detect line breaks", value=False, info="Determines whether to enable detecting line breaks in the text. If enabled, it will concatenate lines before translation", elem_id="translationDetectLineBreaks"),})
1269
  with gr.Column():
1270
  outputs = [gr.Text(label="Translation Text", autoscroll=False, show_copy_button=True, interactive=True, elem_id="outputTranslationText", elem_classes="scroll-show"),]
1271
  if translateModelMd is not None:
config.json5 CHANGED
@@ -419,9 +419,9 @@
419
  // Translation - The maximum batch size.
420
  "translation_batch_size": 2,
421
  // Translation - Prevent repetitions of ngrams with this size (set 0 to disable).
422
- "translation_no_repeat_ngram_size": 3,
423
  // Translation - Beam size (1 for greedy search).
424
- "translation_num_beams": 2,
425
  // Translation - Torch Dtype float16, Load the float32 translation model with float16 when the system supports GPU (reducing VRAM usage, not applicable to quantized models, such as Ctranslate2, GPTQ, GGUF).
426
  "translation_torch_dtype_float16": true,
427
  // Translation - Using Bitsandbytes, Load the float32 translation model into mixed-8bit or 4bit precision quantized model(not applicable to quantized models, such as Ctranslate2, GPTQ, GGUF).
 
419
  // Translation - The maximum batch size.
420
  "translation_batch_size": 2,
421
  // Translation - Prevent repetitions of ngrams with this size (set 0 to disable).
422
+ "translation_no_repeat_ngram_size": 4,
423
  // Translation - Beam size (1 for greedy search).
424
+ "translation_num_beams": 3,
425
  // Translation - Torch Dtype float16, Load the float32 translation model with float16 when the system supports GPU (reducing VRAM usage, not applicable to quantized models, such as Ctranslate2, GPTQ, GGUF).
426
  "translation_torch_dtype_float16": true,
427
  // Translation - Using Bitsandbytes, Load the float32 translation model into mixed-8bit or 4bit precision quantized model(not applicable to quantized models, such as Ctranslate2, GPTQ, GGUF).
src/config.py CHANGED
@@ -80,8 +80,8 @@ class ApplicationConfig:
80
  diarization_process_timeout: int = 60,
81
  # Translation
82
  translation_batch_size: int = 2,
83
- translation_no_repeat_ngram_size: int = 3,
84
- translation_num_beams: int = 2,
85
  translation_torch_dtype_float16: bool = True,
86
  translation_using_bitsandbytes: str = None,
87
  # Whisper Segments Filter
 
80
  diarization_process_timeout: int = 60,
81
  # Translation
82
  translation_batch_size: int = 2,
83
+ translation_no_repeat_ngram_size: int = 4,
84
+ translation_num_beams: int = 3,
85
  translation_torch_dtype_float16: bool = True,
86
  translation_using_bitsandbytes: str = None,
87
  # Whisper Segments Filter
src/translation/translationLangs.py CHANGED
@@ -13,7 +13,8 @@ class TranslationLang():
13
  self.nllb = Lang(code, name)
14
  self.whisper = None
15
  self.m2m100 = None
16
- self.seamlessTx = None
 
17
 
18
  def Whisper(self, code: str, *names: str):
19
  self.whisper = Lang(code, *names)
@@ -25,8 +26,14 @@ class TranslationLang():
25
  self.m2m100 = Lang(code, name)
26
  return self
27
 
28
- def SeamlessTx(self, code: str, name: str):
29
- self.seamlessTx = Lang(code, name)
 
 
 
 
 
 
30
  return self
31
 
32
  def __repr__(self):
@@ -37,8 +44,10 @@ class TranslationLang():
37
  result += f"WHISPER={self.whisper} "
38
  if self.m2m100:
39
  result += f"M2M100={self.m2m100} "
40
- if self.seamlessTx:
41
- result += f"SeamlessTx={self.seamlessTx} "
 
 
42
  return f"Language {result}"
43
 
44
  """
@@ -60,6 +69,15 @@ af:Afrikaans, am:Amharic, ar:Arabic, ast:Asturian, az:Azerbaijani, ba:Bashkir, b
60
  https://huggingface.co/facebook/m2m100_1.2B
61
 
62
  The available languages for m2m100 and whisper are almost identical. Most of the codes correspond to the ISO 639-1 standard. For detailed information, please refer to the official documentation provided.
 
 
 
 
 
 
 
 
 
63
  """
64
  TranslationLangs = [
65
  TranslationLang("ace_Arab", "Acehnese (Arabic script)"),
@@ -67,177 +85,177 @@ TranslationLangs = [
67
  TranslationLang("acm_Arab", "Mesopotamian Arabic").Whisper("ar", "Arabic"),
68
  TranslationLang("acq_Arab", "Ta’izzi-Adeni Arabic").Whisper("ar", "Arabic"),
69
  TranslationLang("aeb_Arab", "Tunisian Arabic"),
70
- TranslationLang("afr_Latn", "Afrikaans").Whisper("af", "Afrikaans").SeamlessTx("afr", "Afrikaans"),
71
  TranslationLang("ajp_Arab", "South Levantine Arabic").Whisper("ar", "Arabic"),
72
  TranslationLang("aka_Latn", "Akan"),
73
- TranslationLang("amh_Ethi", "Amharic").Whisper("am", "Amharic").SeamlessTx("amh", "Amharic"),
74
  TranslationLang("apc_Arab", "North Levantine Arabic").Whisper("ar", "Arabic"),
75
- TranslationLang("arb_Arab", "Modern Standard Arabic").Whisper("ar", "Arabic").SeamlessTx("arb", "Modern Standard Arabic"),
76
  TranslationLang("arb_Latn", "Modern Standard Arabic (Romanized)"),
77
  TranslationLang("ars_Arab", "Najdi Arabic").Whisper("ar", "Arabic"),
78
- TranslationLang("ary_Arab", "Moroccan Arabic").Whisper("ar", "Arabic").SeamlessTx("ary", "Moroccan Arabic"),
79
- TranslationLang("arz_Arab", "Egyptian Arabic").Whisper("ar", "Arabic").SeamlessTx("arz", "Egyptian Arabic"),
80
- TranslationLang("asm_Beng", "Assamese").Whisper("as", "Assamese").SeamlessTx("asm", "Assamese"),
81
- TranslationLang("ast_Latn", "Asturian").M2M100("ast", "Asturian"),
82
  TranslationLang("awa_Deva", "Awadhi"),
83
  TranslationLang("ayr_Latn", "Central Aymara"),
84
  TranslationLang("azb_Arab", "South Azerbaijani").Whisper("az", "Azerbaijani"),
85
- TranslationLang("azj_Latn", "North Azerbaijani").Whisper("az", "Azerbaijani").SeamlessTx("azj", "North Azerbaijani"),
86
  TranslationLang("bak_Cyrl", "Bashkir").Whisper("ba", "Bashkir"),
87
  TranslationLang("bam_Latn", "Bambara"),
88
  TranslationLang("ban_Latn", "Balinese"),
89
- TranslationLang("bel_Cyrl", "Belarusian").Whisper("be", "Belarusian").SeamlessTx("bel", "Belarusian"),
90
  TranslationLang("bem_Latn", "Bemba"),
91
- TranslationLang("ben_Beng", "Bengali").Whisper("bn", "Bengali").SeamlessTx("ben", "Bengali"),
92
  TranslationLang("bho_Deva", "Bhojpuri"),
93
  TranslationLang("bjn_Arab", "Banjar (Arabic script)"),
94
  TranslationLang("bjn_Latn", "Banjar (Latin script)"),
95
  TranslationLang("bod_Tibt", "Standard Tibetan").Whisper("bo", "Tibetan"),
96
- TranslationLang("bos_Latn", "Bosnian").Whisper("bs", "Bosnian").SeamlessTx("bos", "Bosnian"),
97
  TranslationLang("bug_Latn", "Buginese"),
98
- TranslationLang("bul_Cyrl", "Bulgarian").Whisper("bg", "Bulgarian").SeamlessTx("bul", "Bulgarian"),
99
- TranslationLang("cat_Latn", "Catalan").Whisper("ca", "Catalan", "valencian").SeamlessTx("cat", "Catalan"),
100
- TranslationLang("ceb_Latn", "Cebuano").M2M100("ceb", "Cebuano").SeamlessTx("ceb", "Cebuano"),
101
- TranslationLang("ces_Latn", "Czech").Whisper("cs", "Czech").SeamlessTx("ces", "Czech"),
102
  TranslationLang("cjk_Latn", "Chokwe"),
103
- TranslationLang("ckb_Arab", "Central Kurdish").SeamlessTx("ckb", "Central Kurdish"),
104
  TranslationLang("crh_Latn", "Crimean Tatar"),
105
- TranslationLang("cym_Latn", "Welsh").Whisper("cy", "Welsh").SeamlessTx("cym", "Welsh"),
106
- TranslationLang("dan_Latn", "Danish").Whisper("da", "Danish").SeamlessTx("dan", "Danish"),
107
- TranslationLang("deu_Latn", "German").Whisper("de", "German").SeamlessTx("deu", "German"),
108
  TranslationLang("dik_Latn", "Southwestern Dinka"),
109
  TranslationLang("dyu_Latn", "Dyula"),
110
  TranslationLang("dzo_Tibt", "Dzongkha"),
111
- TranslationLang("ell_Grek", "Greek").Whisper("el", "Greek").SeamlessTx("ell", "Greek"),
112
- TranslationLang("eng_Latn", "English").Whisper("en", "English").SeamlessTx("eng", "English"),
113
  TranslationLang("epo_Latn", "Esperanto"),
114
- TranslationLang("est_Latn", "Estonian").Whisper("et", "Estonian").SeamlessTx("est", "Estonian"),
115
- TranslationLang("eus_Latn", "Basque").Whisper("eu", "Basque").SeamlessTx("eus", "Basque"),
116
  TranslationLang("ewe_Latn", "Ewe"),
117
  TranslationLang("fao_Latn", "Faroese").Whisper("fo", "Faroese"),
118
  TranslationLang("fij_Latn", "Fijian"),
119
- TranslationLang("fin_Latn", "Finnish").Whisper("fi", "Finnish").SeamlessTx("fin", "Finnish"),
120
  TranslationLang("fon_Latn", "Fon"),
121
- TranslationLang("fra_Latn", "French").Whisper("fr", "French").SeamlessTx("fra", "French"),
122
  TranslationLang("fur_Latn", "Friulian"),
123
- TranslationLang("fuv_Latn", "Nigerian Fulfulde").M2M100("ff", "Fulah").SeamlessTx("fuv", "Nigerian Fulfulde"),
124
  TranslationLang("gla_Latn", "Scottish Gaelic").M2M100("gd", "Scottish Gaelic"),
125
- TranslationLang("gle_Latn", "Irish").M2M100("ga", "Irish").SeamlessTx("gle", "Irish"),
126
- TranslationLang("glg_Latn", "Galician").Whisper("gl", "Galician").SeamlessTx("glg", "Galician"),
127
  TranslationLang("grn_Latn", "Guarani"),
128
- TranslationLang("guj_Gujr", "Gujarati").Whisper("gu", "Gujarati").SeamlessTx("guj", "Gujarati"),
129
  TranslationLang("hat_Latn", "Haitian Creole").Whisper("ht", "Haitian creole", "haitian"),
130
  TranslationLang("hau_Latn", "Hausa").Whisper("ha", "Hausa"),
131
- TranslationLang("heb_Hebr", "Hebrew").Whisper("he", "Hebrew").SeamlessTx("heb", "Hebrew"),
132
- TranslationLang("hin_Deva", "Hindi").Whisper("hi", "Hindi").SeamlessTx("hin", "Hindi"),
133
  TranslationLang("hne_Deva", "Chhattisgarhi"),
134
- TranslationLang("hrv_Latn", "Croatian").Whisper("hr", "Croatian").SeamlessTx("hrv", "Croatian"),
135
- TranslationLang("hun_Latn", "Hungarian").Whisper("hu", "Hungarian").SeamlessTx("hun", "Hungarian"),
136
- TranslationLang("hye_Armn", "Armenian").Whisper("hy", "Armenian").SeamlessTx("hye", "Armenian"),
137
- TranslationLang("ibo_Latn", "Igbo").M2M100("ig", "Igbo").SeamlessTx("ibo", "Igbo"),
138
  TranslationLang("ilo_Latn", "Ilocano").M2M100("ilo", "Iloko"),
139
- TranslationLang("ind_Latn", "Indonesian").Whisper("id", "Indonesian").SeamlessTx("ind", "Indonesian"),
140
- TranslationLang("isl_Latn", "Icelandic").Whisper("is", "Icelandic").SeamlessTx("isl", "Icelandic"),
141
- TranslationLang("ita_Latn", "Italian").Whisper("it", "Italian").SeamlessTx("ita", "Italian"),
142
- TranslationLang("jav_Latn", "Javanese").Whisper("jw", "Javanese").M2M100("jv", "Javanese").SeamlessTx("jav", "Javanese"),
143
- TranslationLang("jpn_Jpan", "Japanese").Whisper("ja", "Japanese").SeamlessTx("jpn", "Japanese"),
144
  TranslationLang("kab_Latn", "Kabyle"),
145
  TranslationLang("kac_Latn", "Jingpho"),
146
- TranslationLang("kam_Latn", "Kamba"),
147
- TranslationLang("kan_Knda", "Kannada").Whisper("kn", "Kannada").SeamlessTx("kan", "Kannada"),
148
  TranslationLang("kas_Arab", "Kashmiri (Arabic script)"),
149
  TranslationLang("kas_Deva", "Kashmiri (Devanagari script)"),
150
- TranslationLang("kat_Geor", "Georgian").Whisper("ka", "Georgian").SeamlessTx("kat", "Georgian"),
151
  TranslationLang("knc_Arab", "Central Kanuri (Arabic script)"),
152
  TranslationLang("knc_Latn", "Central Kanuri (Latin script)"),
153
- TranslationLang("kaz_Cyrl", "Kazakh").Whisper("kk", "Kazakh").SeamlessTx("kaz", "Kazakh"),
154
  TranslationLang("kbp_Latn", "Kabiyè"),
155
- TranslationLang("kea_Latn", "Kabuverdianu"),
156
- TranslationLang("khm_Khmr", "Khmer").Whisper("km", "Khmer").SeamlessTx("khm", "Khmer"),
157
  TranslationLang("kik_Latn", "Kikuyu"),
158
  TranslationLang("kin_Latn", "Kinyarwanda"),
159
- TranslationLang("kir_Cyrl", "Kyrgyz").SeamlessTx("kir", "Kyrgyz"),
160
  TranslationLang("kmb_Latn", "Kimbundu"),
161
  TranslationLang("kmr_Latn", "Northern Kurdish"),
162
  TranslationLang("kon_Latn", "Kikongo"),
163
- TranslationLang("kor_Hang", "Korean").Whisper("ko", "Korean").SeamlessTx("kor", "Korean"),
164
- TranslationLang("lao_Laoo", "Lao").Whisper("lo", "Lao").SeamlessTx("lao", "Lao"),
165
  TranslationLang("lij_Latn", "Ligurian"),
166
  TranslationLang("lim_Latn", "Limburgish"),
167
  TranslationLang("lin_Latn", "Lingala").Whisper("ln", "Lingala"),
168
- TranslationLang("lit_Latn", "Lithuanian").Whisper("lt", "Lithuanian").SeamlessTx("lit", "Lithuanian"),
169
  TranslationLang("lmo_Latn", "Lombard"),
170
  TranslationLang("ltg_Latn", "Latgalian"),
171
- TranslationLang("ltz_Latn", "Luxembourgish").Whisper("lb", "Luxembourgish", "letzeburgesch"),
172
  TranslationLang("lua_Latn", "Luba-Kasai"),
173
- TranslationLang("lug_Latn", "Ganda").M2M100("lg", "Ganda").SeamlessTx("lug", "Ganda"),
174
- TranslationLang("luo_Latn", "Luo").SeamlessTx("luo", "Luo"),
175
  TranslationLang("lus_Latn", "Mizo"),
176
- TranslationLang("lvs_Latn", "Standard Latvian").Whisper("lv", "Latvian").SeamlessTx("lvs", "Standard Latvian"),
177
  TranslationLang("mag_Deva", "Magahi"),
178
- TranslationLang("mai_Deva", "Maithili").SeamlessTx("mai", "Maithili"),
179
- TranslationLang("mal_Mlym", "Malayalam").Whisper("ml", "Malayalam").SeamlessTx("mal", "Malayalam"),
180
- TranslationLang("mar_Deva", "Marathi").Whisper("mr", "Marathi").SeamlessTx("mar", "Marathi"),
181
  TranslationLang("min_Arab", "Minangkabau (Arabic script)"),
182
  TranslationLang("min_Latn", "Minangkabau (Latin script)"),
183
- TranslationLang("mkd_Cyrl", "Macedonian").Whisper("mk", "Macedonian").SeamlessTx("mkd", "Macedonian"),
184
  TranslationLang("plt_Latn", "Plateau Malagasy").Whisper("mg", "Malagasy"),
185
- TranslationLang("mlt_Latn", "Maltese").Whisper("mt", "Maltese").SeamlessTx("mlt", "Maltese"),
186
- TranslationLang("mni_Beng", "Meitei (Bengali script)").SeamlessTx("mni", "Meitei"),
187
- TranslationLang("khk_Cyrl", "Halh Mongolian").Whisper("mn", "Mongolian").SeamlessTx("khk", "Halh Mongolian"),
188
  TranslationLang("mos_Latn", "Mossi"),
189
  TranslationLang("mri_Latn", "Maori").Whisper("mi", "Maori"),
190
- TranslationLang("mya_Mymr", "Burmese").Whisper("my", "Myanmar", "burmese").SeamlessTx("mya", "Burmese"),
191
- TranslationLang("nld_Latn", "Dutch").Whisper("nl", "Dutch", "flemish").SeamlessTx("nld", "Dutch"),
192
- TranslationLang("nno_Latn", "Norwegian Nynorsk").Whisper("nn", "Nynorsk").SeamlessTx("nno", "Norwegian Nynorsk"),
193
- TranslationLang("nob_Latn", "Norwegian Bokmål").Whisper("no", "Norwegian").SeamlessTx("nob", "Norwegian Bokmål"),
194
- TranslationLang("npi_Deva", "Nepali").Whisper("ne", "Nepali").SeamlessTx("npi", "Nepali"),
195
  TranslationLang("nso_Latn", "Northern Sotho").M2M100("ns", "Northern Sotho"),
196
  TranslationLang("nus_Latn", "Nuer"),
197
- TranslationLang("nya_Latn", "Nyanja").SeamlessTx("nya", "Nyanja"),
198
- TranslationLang("oci_Latn", "Occitan").Whisper("oc", "Occitan"),
199
- TranslationLang("gaz_Latn", "West Central Oromo").SeamlessTx("gaz", "West Central Oromo"),
200
- TranslationLang("ory_Orya", "Odia").M2M100("or", "Oriya").SeamlessTx("ory", "Odia"),
201
  TranslationLang("pag_Latn", "Pangasinan"),
202
- TranslationLang("pan_Guru", "Eastern Panjabi").Whisper("pa", "Punjabi", "panjabi").SeamlessTx("pan", "Punjabi"),
203
  TranslationLang("pap_Latn", "Papiamento"),
204
- TranslationLang("pes_Arab", "Western Persian").Whisper("fa", "Persian").SeamlessTx("pes", "Western Persian"),
205
- TranslationLang("pol_Latn", "Polish").Whisper("pl", "Polish").SeamlessTx("pol", "Polish"),
206
- TranslationLang("por_Latn", "Portuguese").Whisper("pt", "Portuguese").SeamlessTx("por", "Portuguese"),
207
  TranslationLang("prs_Arab", "Dari"),
208
- TranslationLang("pbt_Arab", "Southern Pashto").Whisper("ps", "Pashto", "pushto").SeamlessTx("pbt", "Southern Pashto"),
209
  TranslationLang("quy_Latn", "Ayacucho Quechua"),
210
- TranslationLang("ron_Latn", "Romanian").Whisper("ro", "Romanian", "moldavian", "moldovan").SeamlessTx("ron", "Romanian"),
211
  TranslationLang("run_Latn", "Rundi"),
212
- TranslationLang("rus_Cyrl", "Russian").Whisper("ru", "Russian").SeamlessTx("rus", "Russian"),
213
  TranslationLang("sag_Latn", "Sango"),
214
  TranslationLang("san_Deva", "Sanskrit").Whisper("sa", "Sanskrit"),
215
  TranslationLang("sat_Olck", "Santali"),
216
  TranslationLang("scn_Latn", "Sicilian"),
217
  TranslationLang("shn_Mymr", "Shan"),
218
  TranslationLang("sin_Sinh", "Sinhala").Whisper("si", "Sinhala", "sinhalese"),
219
- TranslationLang("slk_Latn", "Slovak").Whisper("sk", "Slovak").SeamlessTx("slk", "Slovak"),
220
- TranslationLang("slv_Latn", "Slovenian").Whisper("sl", "Slovenian").SeamlessTx("slv", "Slovenian"),
221
  TranslationLang("smo_Latn", "Samoan"),
222
- TranslationLang("sna_Latn", "Shona").Whisper("sn", "Shona").SeamlessTx("sna", "Shona"),
223
- TranslationLang("snd_Arab", "Sindhi").Whisper("sd", "Sindhi").SeamlessTx("snd", "Sindhi"),
224
- TranslationLang("som_Latn", "Somali").Whisper("so", "Somali").SeamlessTx("som", "Somali"),
225
  TranslationLang("sot_Latn", "Southern Sotho"),
226
- TranslationLang("spa_Latn", "Spanish").Whisper("es", "Spanish", "castilian").SeamlessTx("spa", "Spanish"),
227
  TranslationLang("als_Latn", "Tosk Albanian").Whisper("sq", "Albanian"),
228
  TranslationLang("srd_Latn", "Sardinian"),
229
- TranslationLang("srp_Cyrl", "Serbian").Whisper("sr", "Serbian").SeamlessTx("srp", "Serbian"),
230
  TranslationLang("ssw_Latn", "Swati").M2M100("ss", "Swati"),
231
  TranslationLang("sun_Latn", "Sundanese").Whisper("su", "Sundanese"),
232
- TranslationLang("swe_Latn", "Swedish").Whisper("sv", "Swedish").SeamlessTx("swe", "Swedish"),
233
- TranslationLang("swh_Latn", "Swahili").Whisper("sw", "Swahili").SeamlessTx("swh", "Swahili"),
234
  TranslationLang("szl_Latn", "Silesian"),
235
- TranslationLang("tam_Taml", "Tamil").Whisper("ta", "Tamil").SeamlessTx("tam", "Tamil"),
236
  TranslationLang("tat_Cyrl", "Tatar").Whisper("tt", "Tatar"),
237
- TranslationLang("tel_Telu", "Telugu").Whisper("te", "Telugu").SeamlessTx("tel", "Telugu"),
238
- TranslationLang("tgk_Cyrl", "Tajik").Whisper("tg", "Tajik").SeamlessTx("tgk", "Tajik"),
239
- TranslationLang("tgl_Latn", "Tagalog").Whisper("tl", "Tagalog").SeamlessTx("tgl", "Tagalog"),
240
- TranslationLang("tha_Thai", "Thai").Whisper("th", "Thai").SeamlessTx("tha", "Thai"),
241
  TranslationLang("tir_Ethi", "Tigrinya"),
242
  TranslationLang("taq_Latn", "Tamasheq (Latin script)"),
243
  TranslationLang("taq_Tfng", "Tamasheq (Tifinagh script)"),
@@ -246,26 +264,26 @@ TranslationLangs = [
246
  TranslationLang("tso_Latn", "Tsonga"),
247
  TranslationLang("tuk_Latn", "Turkmen").Whisper("tk", "Turkmen"),
248
  TranslationLang("tum_Latn", "Tumbuka"),
249
- TranslationLang("tur_Latn", "Turkish").Whisper("tr", "Turkish").SeamlessTx("tur", "Turkish"),
250
  TranslationLang("twi_Latn", "Twi"),
251
  TranslationLang("tzm_Tfng", "Central Atlas Tamazight"),
252
  TranslationLang("uig_Arab", "Uyghur"),
253
- TranslationLang("ukr_Cyrl", "Ukrainian").Whisper("uk", "Ukrainian").SeamlessTx("ukr", "Ukrainian"),
254
  TranslationLang("umb_Latn", "Umbundu"),
255
- TranslationLang("urd_Arab", "Urdu").Whisper("ur", "Urdu").SeamlessTx("urd", "Urdu"),
256
- TranslationLang("uzn_Latn", "Northern Uzbek").Whisper("uz", "Uzbek").SeamlessTx("uzn", "Northern Uzbek"),
257
  TranslationLang("vec_Latn", "Venetian"),
258
- TranslationLang("vie_Latn", "Vietnamese").Whisper("vi", "Vietnamese").SeamlessTx("vie", "Vietnamese"),
259
  TranslationLang("war_Latn", "Waray"),
260
  TranslationLang("wol_Latn", "Wolof").M2M100("wo", "Wolof"),
261
- TranslationLang("xho_Latn", "Xhosa").M2M100("xh", "Xhosa"),
262
  TranslationLang("ydd_Hebr", "Eastern Yiddish").Whisper("yi", "Yiddish"),
263
- TranslationLang("yor_Latn", "Yoruba").Whisper("yo", "Yoruba").SeamlessTx("yor", "Yoruba"),
264
- TranslationLang("yue_Hant", "Yue Chinese").Whisper("yue", "cantonese").M2M100("zh", "Chinese (zh-yue)").SeamlessTx("yue", "Cantonese"),
265
- TranslationLang("zho_Hans", "Chinese (Simplified)").Whisper("zh", "Chinese (Simplified)", "Chinese", "mandarin").SeamlessTx("cmn", "Mandarin Chinese (Simplified)"),
266
- TranslationLang("zho_Hant", "Chinese (Traditional)").Whisper("zh", "Chinese (Traditional)").SeamlessTx("cmn_Hant", "Mandarin Chinese (Traditional)"),
267
- TranslationLang("zsm_Latn", "Standard Malay").Whisper("ms", "Malay").SeamlessTx("zsm", "Standard Malay"),
268
- TranslationLang("zul_Latn", "Zulu").M2M100("zu", "Zulu").SeamlessTx("zul", "Zulu"),
269
  # TranslationLang(None, None).Whisper("br", "Breton"), # Both whisper and m2m100 support the Breton language, but nllb does not have this language.
270
  ]
271
 
@@ -276,7 +294,7 @@ _TO_LANG_NAME_M2M100 = {name.lower(): language for language in TranslationLangs
276
 
277
  _TO_LANG_NAME_WHISPER = {name.lower(): language for language in TranslationLangs if language.whisper is not None for name in language.whisper.names}
278
 
279
- _TO_LANG_NAME_SeamlessTx = {name.lower(): language for language in TranslationLangs if language.seamlessTx is not None for name in language.seamlessTx.names}
280
 
281
  _TO_LANG_CODE_WHISPER = {language.whisper.code.lower(): language for language in TranslationLangs if language.whisper is not None and len(language.whisper.code) > 0}
282
 
@@ -293,9 +311,9 @@ def get_lang_from_whisper_name(whisperName, default=None) -> TranslationLang:
293
  """Return the TranslationLang from the lang_name_whisper name."""
294
  return _TO_LANG_NAME_WHISPER.get(whisperName.lower() if whisperName else None, default)
295
 
296
- def get_lang_from_seamlessTx_name(seamlessTxName, default=None) -> TranslationLang:
297
- """Return the TranslationLang from the lang_name_seamlessTx name."""
298
- return _TO_LANG_NAME_SeamlessTx.get(seamlessTxName.lower() if seamlessTxName else None, default)
299
 
300
  def get_lang_from_whisper_code(whisperCode, default=None) -> TranslationLang:
301
  """Return the TranslationLang from the lang_code_whisper."""
@@ -309,9 +327,9 @@ def get_lang_m2m100_names(codes = []):
309
  """Return a list of m2m100 language names."""
310
  return list({name.lower(): None for language in TranslationLangs if language.m2m100 is not None and (len(codes) == 0 or any(code in language.m2m100.code for code in codes)) for name in language.m2m100.names}.keys())
311
 
312
- def get_lang_seamlessTx_names(codes = []):
313
- """Return a list of seamlessTx language names."""
314
- return list({name.lower(): None for language in TranslationLangs if language.seamlessTx is not None and (len(codes) == 0 or any(code in language.seamlessTx.code for code in codes)) for name in language.seamlessTx.names}.keys())
315
 
316
  def get_lang_whisper_names():
317
  """Return a list of whisper language names."""
 
13
  self.nllb = Lang(code, name)
14
  self.whisper = None
15
  self.m2m100 = None
16
+ self.seamlessT_Tx = None
17
+ self.seamlessS_Sp = None
18
 
19
  def Whisper(self, code: str, *names: str):
20
  self.whisper = Lang(code, *names)
 
26
  self.m2m100 = Lang(code, name)
27
  return self
28
 
29
+ def SeamlessT_Tx(self, code: str, name: str):
30
+ self.seamlessT_Tx = Lang(code, name)
31
+ if self.seamlessS_Sp is None:
32
+ self.seamlessS_Sp = self.seamlessT_Tx
33
+ return self
34
+
35
+ def SeamlessS_Sp(self, code: str, name: str):
36
+ self.seamlessS_Sp = Lang(code, name)
37
  return self
38
 
39
  def __repr__(self):
 
44
  result += f"WHISPER={self.whisper} "
45
  if self.m2m100:
46
  result += f"M2M100={self.m2m100} "
47
+ if self.seamlessT_Tx:
48
+ result += f"SeamlessTx={self.seamlessT_Tx} "
49
+ if self.seamlessS_Sp:
50
+ result += f"seamlessSp={self.seamlessS_Sp} "
51
  return f"Language {result}"
52
 
53
  """
 
69
  https://huggingface.co/facebook/m2m100_1.2B
70
 
71
  The available languages for m2m100 and whisper are almost identical. Most of the codes correspond to the ISO 639-1 standard. For detailed information, please refer to the official documentation provided.
72
+
73
+ [seamless]
74
+ Source:Sp
75
+ afr:Afrikaans, amh:Amharic, arb:Modern Standard Arabic, ary:Moroccan Arabic, arz:Egyptian Arabic, asm:Assamese, ast:Asturian, azj:North Azerbaijani, bel:Belarusian, ben:Bengali, bos:Bosnian, bul:Bulgarian, cat:Catalan, ceb:Cebuano, ces:Czech, ckb:Central Kurdish, cmn:Mandarin Chinese, cmn_Hant:Mandarin Chinese, cym:Welsh, dan:Danish, deu:German, ell:Greek, eng:English, est:Estonian, eus:Basque, fin:Finnish, fra:French, fuv:Nigerian Fulfulde, gaz:West Central Oromo, gle:Irish, glg:Galician, guj:Gujarati, heb:Hebrew, hin:Hindi, hrv:Croatian, hun:Hungarian, hye:Armenian, ibo:Igbo, ind:Indonesian, isl:Icelandic, ita:Italian, jav:Javanese, jpn:Japanese, kam:Kamba, kan:Kannada, kat:Georgian, kaz:Kazakh, kea:Kabuverdianu, khk:Halh Mongolian, khm:Khmer, kir:Kyrgyz, kor:Korean, lao:Lao, lit:Lithuanian, ltz:Luxembourgish, lug:Ganda, luo:Luo, lvs:Standard Latvian, mai:Maithili, mal:Malayalam, mar:Marathi, mkd:Macedonian, mlt:Maltese, mni:Meitei, mya:Burmese, nld:Dutch, nno:Norwegian Nynorsk, nob:Norwegian Bokmål, npi:Nepali, nya:Nyanja, oci:Occitan, ory:Odia, pan:Punjabi, pbt:Southern Pashto, pes:Western Persian, pol:Polish, por:Portuguese, ron:Romanian, rus:Russian, slk:Slovak, slv:Slovenian, sna:Shona, snd:Sindhi, som:Somali, spa:Spanish, srp:Serbian, swe:Swedish, swh:Swahili, tam:Tamil, tel:Telugu, tgk:Tajik, tgl:Tagalog, tha:Thai, tur:Turkish, ukr:Ukrainian, urd:Urdu, uzn:Northern Uzbek, vie:Vietnamese, xho:Xhosa, yor:Yoruba, yue:Cantonese, zlm:Colloquial Malay, zul:Zulu,
76
+ Target:Tx
77
+ afr:Afrikaans, amh:Amharic, arb:Modern Standard Arabic, ary:Moroccan Arabic, arz:Egyptian Arabic, asm:Assamese, azj:North Azerbaijani, bel:Belarusian, ben:Bengali, bos:Bosnian, bul:Bulgarian, cat:Catalan, ceb:Cebuano, ces:Czech, ckb:Central Kurdish, cmn:Mandarin Chinese, cmn_Hant:Mandarin Chinese, cym:Welsh, dan:Danish, deu:German, ell:Greek, eng:English, est:Estonian, eus:Basque, fin:Finnish, fra:French, fuv:Nigerian Fulfulde, gaz:West Central Oromo, gle:Irish, glg:Galician, guj:Gujarati, heb:Hebrew, hin:Hindi, hrv:Croatian, hun:Hungarian, hye:Armenian, ibo:Igbo, ind:Indonesian, isl:Icelandic, ita:Italian, jav:Javanese, jpn:Japanese, kan:Kannada, kat:Georgian, kaz:Kazakh, khk:Halh Mongolian, khm:Khmer, kir:Kyrgyz, kor:Korean, lao:Lao, lit:Lithuanian, lug:Ganda, luo:Luo, lvs:Standard Latvian, mai:Maithili, mal:Malayalam, mar:Marathi, mkd:Macedonian, mlt:Maltese, mni:Meitei, mya:Burmese, nld:Dutch, nno:Norwegian Nynorsk, nob:Norwegian Bokmål, npi:Nepali, nya:Nyanja, ory:Odia, pan:Punjabi, pbt:Southern Pashto, pes:Western Persian, pol:Polish, por:Portuguese, ron:Romanian, rus:Russian, slk:Slovak, slv:Slovenian, sna:Shona, snd:Sindhi, som:Somali, spa:Spanish, srp:Serbian, swe:Swedish, swh:Swahili, tam:Tamil, tel:Telugu, tgk:Tajik, tgl:Tagalog, tha:Thai, tur:Turkish, ukr:Ukrainian, urd:Urdu, uzn:Northern Uzbek, vie:Vietnamese, yor:Yoruba, yue:Cantonese, zsm:Standard Malay(Source Tx only), zul:Zulu,
78
+ Source:Sp, Tx / Target:Sp, Tx
79
+ arb:Modern Standard Arabic, ben:Bengali, cat:Catalan, ces:Czech, cmn:Mandarin Chinese, cmn_Hant:Mandarin Chinese, cym:Welsh, dan:Danish, deu:German, eng:English, est:Estonian, fin:Finnish, fra:French, hin:Hindi, ind:Indonesian, ita:Italian, jpn:Japanese, kor:Korean, mlt:Maltese, nld:Dutch, pes:Western Persian, pol:Polish, por:Portuguese, ron:Romanian, rus:Russian, slk:Slovak, spa:Spanish, swe:Swedish, swh:Swahili, tel:Telugu, tgl:Tagalog, tha:Thai, tur:Turkish, ukr:Ukrainian, urd:Urdu, uzn:Northern Uzbek, vie:Vietnamese,
80
+ https://huggingface.co/facebook/seamless-m4t-v2-large
81
  """
82
  TranslationLangs = [
83
  TranslationLang("ace_Arab", "Acehnese (Arabic script)"),
 
85
  TranslationLang("acm_Arab", "Mesopotamian Arabic").Whisper("ar", "Arabic"),
86
  TranslationLang("acq_Arab", "Ta’izzi-Adeni Arabic").Whisper("ar", "Arabic"),
87
  TranslationLang("aeb_Arab", "Tunisian Arabic"),
88
+ TranslationLang("afr_Latn", "Afrikaans").Whisper("af", "Afrikaans").SeamlessT_Tx("afr", "Afrikaans"),
89
  TranslationLang("ajp_Arab", "South Levantine Arabic").Whisper("ar", "Arabic"),
90
  TranslationLang("aka_Latn", "Akan"),
91
+ TranslationLang("amh_Ethi", "Amharic").Whisper("am", "Amharic").SeamlessT_Tx("amh", "Amharic"),
92
  TranslationLang("apc_Arab", "North Levantine Arabic").Whisper("ar", "Arabic"),
93
+ TranslationLang("arb_Arab", "Modern Standard Arabic").Whisper("ar", "Arabic").SeamlessT_Tx("arb", "Modern Standard Arabic"),
94
  TranslationLang("arb_Latn", "Modern Standard Arabic (Romanized)"),
95
  TranslationLang("ars_Arab", "Najdi Arabic").Whisper("ar", "Arabic"),
96
+ TranslationLang("ary_Arab", "Moroccan Arabic").Whisper("ar", "Arabic").SeamlessT_Tx("ary", "Moroccan Arabic"),
97
+ TranslationLang("arz_Arab", "Egyptian Arabic").Whisper("ar", "Arabic").SeamlessT_Tx("arz", "Egyptian Arabic"),
98
+ TranslationLang("asm_Beng", "Assamese").Whisper("as", "Assamese").SeamlessT_Tx("asm", "Assamese"),
99
+ TranslationLang("ast_Latn", "Asturian").M2M100("ast", "Asturian").SeamlessS_Sp("ast", "Asturian"),
100
  TranslationLang("awa_Deva", "Awadhi"),
101
  TranslationLang("ayr_Latn", "Central Aymara"),
102
  TranslationLang("azb_Arab", "South Azerbaijani").Whisper("az", "Azerbaijani"),
103
+ TranslationLang("azj_Latn", "North Azerbaijani").Whisper("az", "Azerbaijani").SeamlessT_Tx("azj", "North Azerbaijani"),
104
  TranslationLang("bak_Cyrl", "Bashkir").Whisper("ba", "Bashkir"),
105
  TranslationLang("bam_Latn", "Bambara"),
106
  TranslationLang("ban_Latn", "Balinese"),
107
+ TranslationLang("bel_Cyrl", "Belarusian").Whisper("be", "Belarusian").SeamlessT_Tx("bel", "Belarusian"),
108
  TranslationLang("bem_Latn", "Bemba"),
109
+ TranslationLang("ben_Beng", "Bengali").Whisper("bn", "Bengali").SeamlessT_Tx("ben", "Bengali"),
110
  TranslationLang("bho_Deva", "Bhojpuri"),
111
  TranslationLang("bjn_Arab", "Banjar (Arabic script)"),
112
  TranslationLang("bjn_Latn", "Banjar (Latin script)"),
113
  TranslationLang("bod_Tibt", "Standard Tibetan").Whisper("bo", "Tibetan"),
114
+ TranslationLang("bos_Latn", "Bosnian").Whisper("bs", "Bosnian").SeamlessT_Tx("bos", "Bosnian"),
115
  TranslationLang("bug_Latn", "Buginese"),
116
+ TranslationLang("bul_Cyrl", "Bulgarian").Whisper("bg", "Bulgarian").SeamlessT_Tx("bul", "Bulgarian"),
117
+ TranslationLang("cat_Latn", "Catalan").Whisper("ca", "Catalan", "valencian").SeamlessT_Tx("cat", "Catalan"),
118
+ TranslationLang("ceb_Latn", "Cebuano").M2M100("ceb", "Cebuano").SeamlessT_Tx("ceb", "Cebuano"),
119
+ TranslationLang("ces_Latn", "Czech").Whisper("cs", "Czech").SeamlessT_Tx("ces", "Czech"),
120
  TranslationLang("cjk_Latn", "Chokwe"),
121
+ TranslationLang("ckb_Arab", "Central Kurdish").SeamlessT_Tx("ckb", "Central Kurdish"),
122
  TranslationLang("crh_Latn", "Crimean Tatar"),
123
+ TranslationLang("cym_Latn", "Welsh").Whisper("cy", "Welsh").SeamlessT_Tx("cym", "Welsh"),
124
+ TranslationLang("dan_Latn", "Danish").Whisper("da", "Danish").SeamlessT_Tx("dan", "Danish"),
125
+ TranslationLang("deu_Latn", "German").Whisper("de", "German").SeamlessT_Tx("deu", "German"),
126
  TranslationLang("dik_Latn", "Southwestern Dinka"),
127
  TranslationLang("dyu_Latn", "Dyula"),
128
  TranslationLang("dzo_Tibt", "Dzongkha"),
129
+ TranslationLang("ell_Grek", "Greek").Whisper("el", "Greek").SeamlessT_Tx("ell", "Greek"),
130
+ TranslationLang("eng_Latn", "English").Whisper("en", "English").SeamlessT_Tx("eng", "English"),
131
  TranslationLang("epo_Latn", "Esperanto"),
132
+ TranslationLang("est_Latn", "Estonian").Whisper("et", "Estonian").SeamlessT_Tx("est", "Estonian"),
133
+ TranslationLang("eus_Latn", "Basque").Whisper("eu", "Basque").SeamlessT_Tx("eus", "Basque"),
134
  TranslationLang("ewe_Latn", "Ewe"),
135
  TranslationLang("fao_Latn", "Faroese").Whisper("fo", "Faroese"),
136
  TranslationLang("fij_Latn", "Fijian"),
137
+ TranslationLang("fin_Latn", "Finnish").Whisper("fi", "Finnish").SeamlessT_Tx("fin", "Finnish"),
138
  TranslationLang("fon_Latn", "Fon"),
139
+ TranslationLang("fra_Latn", "French").Whisper("fr", "French").SeamlessT_Tx("fra", "French"),
140
  TranslationLang("fur_Latn", "Friulian"),
141
+ TranslationLang("fuv_Latn", "Nigerian Fulfulde").M2M100("ff", "Fulah").SeamlessT_Tx("fuv", "Nigerian Fulfulde"),
142
  TranslationLang("gla_Latn", "Scottish Gaelic").M2M100("gd", "Scottish Gaelic"),
143
+ TranslationLang("gle_Latn", "Irish").M2M100("ga", "Irish").SeamlessT_Tx("gle", "Irish"),
144
+ TranslationLang("glg_Latn", "Galician").Whisper("gl", "Galician").SeamlessT_Tx("glg", "Galician"),
145
  TranslationLang("grn_Latn", "Guarani"),
146
+ TranslationLang("guj_Gujr", "Gujarati").Whisper("gu", "Gujarati").SeamlessT_Tx("guj", "Gujarati"),
147
  TranslationLang("hat_Latn", "Haitian Creole").Whisper("ht", "Haitian creole", "haitian"),
148
  TranslationLang("hau_Latn", "Hausa").Whisper("ha", "Hausa"),
149
+ TranslationLang("heb_Hebr", "Hebrew").Whisper("he", "Hebrew").SeamlessT_Tx("heb", "Hebrew"),
150
+ TranslationLang("hin_Deva", "Hindi").Whisper("hi", "Hindi").SeamlessT_Tx("hin", "Hindi"),
151
  TranslationLang("hne_Deva", "Chhattisgarhi"),
152
+ TranslationLang("hrv_Latn", "Croatian").Whisper("hr", "Croatian").SeamlessT_Tx("hrv", "Croatian"),
153
+ TranslationLang("hun_Latn", "Hungarian").Whisper("hu", "Hungarian").SeamlessT_Tx("hun", "Hungarian"),
154
+ TranslationLang("hye_Armn", "Armenian").Whisper("hy", "Armenian").SeamlessT_Tx("hye", "Armenian"),
155
+ TranslationLang("ibo_Latn", "Igbo").M2M100("ig", "Igbo").SeamlessT_Tx("ibo", "Igbo"),
156
  TranslationLang("ilo_Latn", "Ilocano").M2M100("ilo", "Iloko"),
157
+ TranslationLang("ind_Latn", "Indonesian").Whisper("id", "Indonesian").SeamlessT_Tx("ind", "Indonesian"),
158
+ TranslationLang("isl_Latn", "Icelandic").Whisper("is", "Icelandic").SeamlessT_Tx("isl", "Icelandic"),
159
+ TranslationLang("ita_Latn", "Italian").Whisper("it", "Italian").SeamlessT_Tx("ita", "Italian"),
160
+ TranslationLang("jav_Latn", "Javanese").Whisper("jw", "Javanese").M2M100("jv", "Javanese").SeamlessT_Tx("jav", "Javanese"),
161
+ TranslationLang("jpn_Jpan", "Japanese").Whisper("ja", "Japanese").SeamlessT_Tx("jpn", "Japanese"),
162
  TranslationLang("kab_Latn", "Kabyle"),
163
  TranslationLang("kac_Latn", "Jingpho"),
164
+ TranslationLang("kam_Latn", "Kamba").SeamlessS_Sp("kam", "Kamba"),
165
+ TranslationLang("kan_Knda", "Kannada").Whisper("kn", "Kannada").SeamlessT_Tx("kan", "Kannada"),
166
  TranslationLang("kas_Arab", "Kashmiri (Arabic script)"),
167
  TranslationLang("kas_Deva", "Kashmiri (Devanagari script)"),
168
+ TranslationLang("kat_Geor", "Georgian").Whisper("ka", "Georgian").SeamlessT_Tx("kat", "Georgian"),
169
  TranslationLang("knc_Arab", "Central Kanuri (Arabic script)"),
170
  TranslationLang("knc_Latn", "Central Kanuri (Latin script)"),
171
+ TranslationLang("kaz_Cyrl", "Kazakh").Whisper("kk", "Kazakh").SeamlessT_Tx("kaz", "Kazakh"),
172
  TranslationLang("kbp_Latn", "Kabiyè"),
173
+ TranslationLang("kea_Latn", "Kabuverdianu").SeamlessS_Sp("kea", "Kabuverdianu"),
174
+ TranslationLang("khm_Khmr", "Khmer").Whisper("km", "Khmer").SeamlessT_Tx("khm", "Khmer"),
175
  TranslationLang("kik_Latn", "Kikuyu"),
176
  TranslationLang("kin_Latn", "Kinyarwanda"),
177
+ TranslationLang("kir_Cyrl", "Kyrgyz").SeamlessT_Tx("kir", "Kyrgyz"),
178
  TranslationLang("kmb_Latn", "Kimbundu"),
179
  TranslationLang("kmr_Latn", "Northern Kurdish"),
180
  TranslationLang("kon_Latn", "Kikongo"),
181
+ TranslationLang("kor_Hang", "Korean").Whisper("ko", "Korean").SeamlessT_Tx("kor", "Korean"),
182
+ TranslationLang("lao_Laoo", "Lao").Whisper("lo", "Lao").SeamlessT_Tx("lao", "Lao"),
183
  TranslationLang("lij_Latn", "Ligurian"),
184
  TranslationLang("lim_Latn", "Limburgish"),
185
  TranslationLang("lin_Latn", "Lingala").Whisper("ln", "Lingala"),
186
+ TranslationLang("lit_Latn", "Lithuanian").Whisper("lt", "Lithuanian").SeamlessT_Tx("lit", "Lithuanian"),
187
  TranslationLang("lmo_Latn", "Lombard"),
188
  TranslationLang("ltg_Latn", "Latgalian"),
189
+ TranslationLang("ltz_Latn", "Luxembourgish").Whisper("lb", "Luxembourgish", "letzeburgesch").SeamlessS_Sp("ltz", "Luxembourgish"),
190
  TranslationLang("lua_Latn", "Luba-Kasai"),
191
+ TranslationLang("lug_Latn", "Ganda").M2M100("lg", "Ganda").SeamlessT_Tx("lug", "Ganda"),
192
+ TranslationLang("luo_Latn", "Luo").SeamlessT_Tx("luo", "Luo"),
193
  TranslationLang("lus_Latn", "Mizo"),
194
+ TranslationLang("lvs_Latn", "Standard Latvian").Whisper("lv", "Latvian").SeamlessT_Tx("lvs", "Standard Latvian"),
195
  TranslationLang("mag_Deva", "Magahi"),
196
+ TranslationLang("mai_Deva", "Maithili").SeamlessT_Tx("mai", "Maithili"),
197
+ TranslationLang("mal_Mlym", "Malayalam").Whisper("ml", "Malayalam").SeamlessT_Tx("mal", "Malayalam"),
198
+ TranslationLang("mar_Deva", "Marathi").Whisper("mr", "Marathi").SeamlessT_Tx("mar", "Marathi"),
199
  TranslationLang("min_Arab", "Minangkabau (Arabic script)"),
200
  TranslationLang("min_Latn", "Minangkabau (Latin script)"),
201
+ TranslationLang("mkd_Cyrl", "Macedonian").Whisper("mk", "Macedonian").SeamlessT_Tx("mkd", "Macedonian"),
202
  TranslationLang("plt_Latn", "Plateau Malagasy").Whisper("mg", "Malagasy"),
203
+ TranslationLang("mlt_Latn", "Maltese").Whisper("mt", "Maltese").SeamlessT_Tx("mlt", "Maltese"),
204
+ TranslationLang("mni_Beng", "Meitei (Bengali script)").SeamlessT_Tx("mni", "Meitei"),
205
+ TranslationLang("khk_Cyrl", "Halh Mongolian").Whisper("mn", "Mongolian").SeamlessT_Tx("khk", "Halh Mongolian"),
206
  TranslationLang("mos_Latn", "Mossi"),
207
  TranslationLang("mri_Latn", "Maori").Whisper("mi", "Maori"),
208
+ TranslationLang("mya_Mymr", "Burmese").Whisper("my", "Myanmar", "burmese").SeamlessT_Tx("mya", "Burmese"),
209
+ TranslationLang("nld_Latn", "Dutch").Whisper("nl", "Dutch", "flemish").SeamlessT_Tx("nld", "Dutch"),
210
+ TranslationLang("nno_Latn", "Norwegian Nynorsk").Whisper("nn", "Nynorsk").SeamlessT_Tx("nno", "Norwegian Nynorsk"),
211
+ TranslationLang("nob_Latn", "Norwegian Bokmål").Whisper("no", "Norwegian").SeamlessT_Tx("nob", "Norwegian Bokmål"),
212
+ TranslationLang("npi_Deva", "Nepali").Whisper("ne", "Nepali").SeamlessT_Tx("npi", "Nepali"),
213
  TranslationLang("nso_Latn", "Northern Sotho").M2M100("ns", "Northern Sotho"),
214
  TranslationLang("nus_Latn", "Nuer"),
215
+ TranslationLang("nya_Latn", "Nyanja").SeamlessT_Tx("nya", "Nyanja"),
216
+ TranslationLang("oci_Latn", "Occitan").Whisper("oc", "Occitan").SeamlessS_Sp("oci", "Occitan"),
217
+ TranslationLang("gaz_Latn", "West Central Oromo").SeamlessT_Tx("gaz", "West Central Oromo"),
218
+ TranslationLang("ory_Orya", "Odia").M2M100("or", "Oriya").SeamlessT_Tx("ory", "Odia"),
219
  TranslationLang("pag_Latn", "Pangasinan"),
220
+ TranslationLang("pan_Guru", "Eastern Panjabi").Whisper("pa", "Punjabi", "panjabi").SeamlessT_Tx("pan", "Punjabi"),
221
  TranslationLang("pap_Latn", "Papiamento"),
222
+ TranslationLang("pes_Arab", "Western Persian").Whisper("fa", "Persian").SeamlessT_Tx("pes", "Western Persian"),
223
+ TranslationLang("pol_Latn", "Polish").Whisper("pl", "Polish").SeamlessT_Tx("pol", "Polish"),
224
+ TranslationLang("por_Latn", "Portuguese").Whisper("pt", "Portuguese").SeamlessT_Tx("por", "Portuguese"),
225
  TranslationLang("prs_Arab", "Dari"),
226
+ TranslationLang("pbt_Arab", "Southern Pashto").Whisper("ps", "Pashto", "pushto").SeamlessT_Tx("pbt", "Southern Pashto"),
227
  TranslationLang("quy_Latn", "Ayacucho Quechua"),
228
+ TranslationLang("ron_Latn", "Romanian").Whisper("ro", "Romanian", "moldavian", "moldovan").SeamlessT_Tx("ron", "Romanian"),
229
  TranslationLang("run_Latn", "Rundi"),
230
+ TranslationLang("rus_Cyrl", "Russian").Whisper("ru", "Russian").SeamlessT_Tx("rus", "Russian"),
231
  TranslationLang("sag_Latn", "Sango"),
232
  TranslationLang("san_Deva", "Sanskrit").Whisper("sa", "Sanskrit"),
233
  TranslationLang("sat_Olck", "Santali"),
234
  TranslationLang("scn_Latn", "Sicilian"),
235
  TranslationLang("shn_Mymr", "Shan"),
236
  TranslationLang("sin_Sinh", "Sinhala").Whisper("si", "Sinhala", "sinhalese"),
237
+ TranslationLang("slk_Latn", "Slovak").Whisper("sk", "Slovak").SeamlessT_Tx("slk", "Slovak"),
238
+ TranslationLang("slv_Latn", "Slovenian").Whisper("sl", "Slovenian").SeamlessT_Tx("slv", "Slovenian"),
239
  TranslationLang("smo_Latn", "Samoan"),
240
+ TranslationLang("sna_Latn", "Shona").Whisper("sn", "Shona").SeamlessT_Tx("sna", "Shona"),
241
+ TranslationLang("snd_Arab", "Sindhi").Whisper("sd", "Sindhi").SeamlessT_Tx("snd", "Sindhi"),
242
+ TranslationLang("som_Latn", "Somali").Whisper("so", "Somali").SeamlessT_Tx("som", "Somali"),
243
  TranslationLang("sot_Latn", "Southern Sotho"),
244
+ TranslationLang("spa_Latn", "Spanish").Whisper("es", "Spanish", "castilian").SeamlessT_Tx("spa", "Spanish"),
245
  TranslationLang("als_Latn", "Tosk Albanian").Whisper("sq", "Albanian"),
246
  TranslationLang("srd_Latn", "Sardinian"),
247
+ TranslationLang("srp_Cyrl", "Serbian").Whisper("sr", "Serbian").SeamlessT_Tx("srp", "Serbian"),
248
  TranslationLang("ssw_Latn", "Swati").M2M100("ss", "Swati"),
249
  TranslationLang("sun_Latn", "Sundanese").Whisper("su", "Sundanese"),
250
+ TranslationLang("swe_Latn", "Swedish").Whisper("sv", "Swedish").SeamlessT_Tx("swe", "Swedish"),
251
+ TranslationLang("swh_Latn", "Swahili").Whisper("sw", "Swahili").SeamlessT_Tx("swh", "Swahili"),
252
  TranslationLang("szl_Latn", "Silesian"),
253
+ TranslationLang("tam_Taml", "Tamil").Whisper("ta", "Tamil").SeamlessT_Tx("tam", "Tamil"),
254
  TranslationLang("tat_Cyrl", "Tatar").Whisper("tt", "Tatar"),
255
+ TranslationLang("tel_Telu", "Telugu").Whisper("te", "Telugu").SeamlessT_Tx("tel", "Telugu"),
256
+ TranslationLang("tgk_Cyrl", "Tajik").Whisper("tg", "Tajik").SeamlessT_Tx("tgk", "Tajik"),
257
+ TranslationLang("tgl_Latn", "Tagalog").Whisper("tl", "Tagalog").SeamlessT_Tx("tgl", "Tagalog"),
258
+ TranslationLang("tha_Thai", "Thai").Whisper("th", "Thai").SeamlessT_Tx("tha", "Thai"),
259
  TranslationLang("tir_Ethi", "Tigrinya"),
260
  TranslationLang("taq_Latn", "Tamasheq (Latin script)"),
261
  TranslationLang("taq_Tfng", "Tamasheq (Tifinagh script)"),
 
264
  TranslationLang("tso_Latn", "Tsonga"),
265
  TranslationLang("tuk_Latn", "Turkmen").Whisper("tk", "Turkmen"),
266
  TranslationLang("tum_Latn", "Tumbuka"),
267
+ TranslationLang("tur_Latn", "Turkish").Whisper("tr", "Turkish").SeamlessT_Tx("tur", "Turkish"),
268
  TranslationLang("twi_Latn", "Twi"),
269
  TranslationLang("tzm_Tfng", "Central Atlas Tamazight"),
270
  TranslationLang("uig_Arab", "Uyghur"),
271
+ TranslationLang("ukr_Cyrl", "Ukrainian").Whisper("uk", "Ukrainian").SeamlessT_Tx("ukr", "Ukrainian"),
272
  TranslationLang("umb_Latn", "Umbundu"),
273
+ TranslationLang("urd_Arab", "Urdu").Whisper("ur", "Urdu").SeamlessT_Tx("urd", "Urdu"),
274
+ TranslationLang("uzn_Latn", "Northern Uzbek").Whisper("uz", "Uzbek").SeamlessT_Tx("uzn", "Northern Uzbek"),
275
  TranslationLang("vec_Latn", "Venetian"),
276
+ TranslationLang("vie_Latn", "Vietnamese").Whisper("vi", "Vietnamese").SeamlessT_Tx("vie", "Vietnamese"),
277
  TranslationLang("war_Latn", "Waray"),
278
  TranslationLang("wol_Latn", "Wolof").M2M100("wo", "Wolof"),
279
+ TranslationLang("xho_Latn", "Xhosa").M2M100("xh", "Xhosa").SeamlessS_Sp("xho", "Xhosa"),
280
  TranslationLang("ydd_Hebr", "Eastern Yiddish").Whisper("yi", "Yiddish"),
281
+ TranslationLang("yor_Latn", "Yoruba").Whisper("yo", "Yoruba").SeamlessT_Tx("yor", "Yoruba"),
282
+ TranslationLang("yue_Hant", "Yue Chinese").Whisper("yue", "cantonese").M2M100("zh", "Chinese (zh-yue)").SeamlessT_Tx("yue", "Cantonese"),
283
+ TranslationLang("zho_Hans", "Chinese (Simplified)").Whisper("zh", "Chinese (Simplified)", "Chinese", "mandarin").SeamlessT_Tx("cmn", "Mandarin Chinese (Simplified)"),
284
+ TranslationLang("zho_Hant", "Chinese (Traditional)").Whisper("zh", "Chinese (Traditional)").SeamlessT_Tx("cmn_Hant", "Mandarin Chinese (Traditional)"),
285
+ TranslationLang("zsm_Latn", "Standard Malay").Whisper("ms", "Malay").SeamlessT_Tx("zsm", "Standard Malay").SeamlessS_Sp("zlm", "Colloquial Malay"), #msa:Malay (macrolanguage), zsm:Standard Malay, zlm:Malay (individual language),
286
+ TranslationLang("zul_Latn", "Zulu").M2M100("zu", "Zulu").SeamlessT_Tx("zul", "Zulu"),
287
  # TranslationLang(None, None).Whisper("br", "Breton"), # Both whisper and m2m100 support the Breton language, but nllb does not have this language.
288
  ]
289
 
 
294
 
295
  _TO_LANG_NAME_WHISPER = {name.lower(): language for language in TranslationLangs if language.whisper is not None for name in language.whisper.names}
296
 
297
+ _TO_LANG_NAME_SeamlessTx = {name.lower(): language for language in TranslationLangs if language.seamlessT_Tx is not None for name in language.seamlessT_Tx.names}
298
 
299
  _TO_LANG_CODE_WHISPER = {language.whisper.code.lower(): language for language in TranslationLangs if language.whisper is not None and len(language.whisper.code) > 0}
300
 
 
311
  """Return the TranslationLang from the lang_name_whisper name."""
312
  return _TO_LANG_NAME_WHISPER.get(whisperName.lower() if whisperName else None, default)
313
 
314
+ def get_lang_from_seamlessT_Tx_name(seamlessT_TxName, default=None) -> TranslationLang:
315
+ """Return the TranslationLang from the lang_name_seamlessT_Tx name."""
316
+ return _TO_LANG_NAME_SeamlessTx.get(seamlessT_TxName.lower() if seamlessT_TxName else None, default)
317
 
318
  def get_lang_from_whisper_code(whisperCode, default=None) -> TranslationLang:
319
  """Return the TranslationLang from the lang_code_whisper."""
 
327
  """Return a list of m2m100 language names."""
328
  return list({name.lower(): None for language in TranslationLangs if language.m2m100 is not None and (len(codes) == 0 or any(code in language.m2m100.code for code in codes)) for name in language.m2m100.names}.keys())
329
 
330
+ def get_lang_seamlessT_Tx_names(codes = []):
331
+ """Return a list of seamlessT_Tx language names."""
332
+ return list({name.lower(): None for language in TranslationLangs if language.seamlessT_Tx is not None and (len(codes) == 0 or any(code in language.seamlessT_Tx.code for code in codes)) for name in language.seamlessT_Tx.names}.keys())
333
 
334
  def get_lang_whisper_names():
335
  """Return a list of whisper language names."""
src/translation/translationModel.py CHANGED
@@ -404,10 +404,10 @@ class TranslationModel:
404
  result = output[0]['generated_text']
405
  elif "seamless" in self.modelPath:
406
  if self.device != "cpu":
407
- text_inputs = self.transProcessor(text = text, src_lang=self.whisperLang.seamlessTx.code, return_tensors="pt").to(self.device)
408
  else:
409
- text_inputs = self.transProcessor(text = text, src_lang=self.whisperLang.seamlessTx.code, return_tensors="pt")
410
- output_tokens = self.transModel.generate(**text_inputs, tgt_lang=self.translationLang.seamlessTx.code, generate_speech=False, no_repeat_ngram_size=self.noRepeatNgramSize, num_beams=self.numBeams)
411
  result = self.transProcessor.decode(output_tokens[0].tolist()[0], skip_special_tokens=True)
412
  else: #M2M100 & NLLB
413
  output = self.transTranslator(text, max_length=max_length, batch_size=self.batchSize, no_repeat_ngram_size=self.noRepeatNgramSize, num_beams=self.numBeams)
 
404
  result = output[0]['generated_text']
405
  elif "seamless" in self.modelPath:
406
  if self.device != "cpu":
407
+ text_inputs = self.transProcessor(text = text, src_lang=self.whisperLang.seamlessT_Tx.code, return_tensors="pt").to(self.device)
408
  else:
409
+ text_inputs = self.transProcessor(text = text, src_lang=self.whisperLang.seamlessT_Tx.code, return_tensors="pt")
410
+ output_tokens = self.transModel.generate(**text_inputs, tgt_lang=self.translationLang.seamlessT_Tx.code, generate_speech=False, no_repeat_ngram_size=self.noRepeatNgramSize, num_beams=self.numBeams)
411
  result = self.transProcessor.decode(output_tokens[0].tolist()[0], skip_special_tokens=True)
412
  else: #M2M100 & NLLB
413
  output = self.transTranslator(text, max_length=max_length, batch_size=self.batchSize, no_repeat_ngram_size=self.noRepeatNgramSize, num_beams=self.numBeams)