Noumida commited on
Commit
42cd95b
·
verified ·
1 Parent(s): dca9a76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -9
app.py CHANGED
@@ -1,3 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from __future__ import annotations
2
  import torch
3
  import torchaudio
@@ -24,17 +43,23 @@ print("✅ Language ID Model loaded.")
24
 
25
 
26
  # --- Language Mappings ---
 
27
  LID_TO_ASR_LANG_MAP = {
 
28
  "asm_Beng": "as", "ben_Beng": "bn", "brx_Deva": "br", "doi_Deva": "doi",
29
  "guj_Gujr": "gu", "hin_Deva": "hi", "kan_Knda": "kn", "kas_Arab": "ks",
30
  "kas_Deva": "ks", "gom_Deva": "kok", "mai_Deva": "mai", "mal_Mlym": "ml",
31
  "mni_Beng": "mni", "mar_Deva": "mr", "nep_Deva": "ne", "ory_Orya": "or",
32
  "pan_Guru": "pa", "san_Deva": "sa", "sat_Olck": "sat", "snd_Arab": "sd",
33
  "tam_Taml": "ta", "tel_Telu": "te", "urd_Arab": "ur",
34
- "pan": "pa" # <-- ADDED THIS FIX FOR PUNJABI
 
 
 
 
35
  }
36
 
37
- ASR_CODE_TO_NAME = { "as": "Assamese", "bn": "Bengali", "br": "Bodo", "doi": "Dogri", "gu": "Gujarati", "hi": "Hindi", "kn": "Kannada", "ks": "Kashmiri", "kok": "Konkani", "mai": "Maithili", "ml": "Malayalam", "mni": "Manipuri", "mr": "Marathi", "ne": "Nepali", "or": "Odia", "pa": "Punjabi", "sa": "Sanskrit", "sat": "Santali", "sd": "Sindhi", "ta": "Tamil", "te": "Telugu", "ur": "Urdu"}
38
 
39
 
40
  @spaces.GPU
@@ -60,12 +85,8 @@ def transcribe_audio_with_lid(audio_path):
60
  asr_lang_code = LID_TO_ASR_LANG_MAP.get(detected_lid_code)
61
 
62
  if not asr_lang_code:
63
- # Fallback for simple codes like 'pan' from other LID models
64
- if detected_lid_code in LID_TO_ASR_LANG_MAP:
65
- asr_lang_code = LID_TO_ASR_LANG_MAP[detected_lid_code]
66
- else:
67
- detected_lang_str = f"Detected '{detected_lid_code}', which is not supported by the ASR model."
68
- return detected_lang_str, "N/A", "N/A"
69
 
70
  detected_lang_str = f"Detected Language: {ASR_CODE_TO_NAME.get(asr_lang_code, 'Unknown')}"
71
 
@@ -104,4 +125,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
104
  )
105
 
106
  if __name__ == "__main__":
107
- demo.queue().launch()
 
 
1
+ You've found another mapping inconsistency. My apologies for that. This error is happening for the same reason as the Punjabi issue, just with a different language.
2
+
3
+ The Language ID (LID) model is correctly identifying the language as Hindi and outputting the simple code **`hin`**. However, our mapping dictionary was only looking for the more complex code `hin_Deva`.
4
+
5
+ -----
6
+
7
+ ### \#\# The Correction
8
+
9
+ The solution is to make our `LID_TO_ASR_LANG_MAP` more robust by including mappings for both the simple three-letter codes (like `hin`) and the complex ones (`hin_Deva`). This will ensure that no matter which code the LID model outputs, it will be correctly mapped to the two-letter code expected by the ASR model.
10
+
11
+ I have updated the dictionary below to be comprehensive.
12
+
13
+ -----
14
+
15
+ ### **Final Corrected Code**
16
+
17
+ Here is the complete script with the updated and more robust mapping dictionary.
18
+
19
+ ```python
20
  from __future__ import annotations
21
  import torch
22
  import torchaudio
 
43
 
44
 
45
  # --- Language Mappings ---
46
+ # Updated to be more robust, handling both simple and complex LID codes.
47
  LID_TO_ASR_LANG_MAP = {
48
+ # MMS-style codes (e.g., hin_Deva)
49
  "asm_Beng": "as", "ben_Beng": "bn", "brx_Deva": "br", "doi_Deva": "doi",
50
  "guj_Gujr": "gu", "hin_Deva": "hi", "kan_Knda": "kn", "kas_Arab": "ks",
51
  "kas_Deva": "ks", "gom_Deva": "kok", "mai_Deva": "mai", "mal_Mlym": "ml",
52
  "mni_Beng": "mni", "mar_Deva": "mr", "nep_Deva": "ne", "ory_Orya": "or",
53
  "pan_Guru": "pa", "san_Deva": "sa", "sat_Olck": "sat", "snd_Arab": "sd",
54
  "tam_Taml": "ta", "tel_Telu": "te", "urd_Arab": "ur",
55
+ # Simple 3-letter codes (e.g., hin) as a fallback
56
+ "as": "as", "ben": "bn", "brx": "br", "doi": "doi", "guj": "gu", "hin": "hi",
57
+ "kan": "kn", "kas": "ks", "kok": "kok", "mai": "mai", "mal": "ml", "mni": "mni",
58
+ "mar": "mr", "nep": "ne", "ory": "or", "pan": "pa", "san": "sa", "sat": "sat",
59
+ "snd": "sd", "tam": "ta", "tel": "te", "urd": "ur", "eng": "en"
60
  }
61
 
62
+ ASR_CODE_TO_NAME = { "as": "Assamese", "bn": "Bengali", "br": "Bodo", "doi": "Dogri", "gu": "Gujarati", "hi": "Hindi", "kn": "Kannada", "ks": "Kashmiri", "kok": "Konkani", "mai": "Maithili", "ml": "Malayalam", "mni": "Manipuri", "mr": "Marathi", "ne": "Nepali", "or": "Odia", "pa": "Punjabi", "sa": "Sanskrit", "sat": "Santali", "sd": "Sindhi", "ta": "Tamil", "te": "Telugu", "ur": "Urdu", "en": "English"}
63
 
64
 
65
  @spaces.GPU
 
85
  asr_lang_code = LID_TO_ASR_LANG_MAP.get(detected_lid_code)
86
 
87
  if not asr_lang_code:
88
+ detected_lang_str = f"Detected '{detected_lid_code}', which is not supported by the ASR model."
89
+ return detected_lang_str, "N/A", "N/A"
 
 
 
 
90
 
91
  detected_lang_str = f"Detected Language: {ASR_CODE_TO_NAME.get(asr_lang_code, 'Unknown')}"
92
 
 
125
  )
126
 
127
  if __name__ == "__main__":
128
+ demo.queue().launch()
129
+ ```