siddhm11 Claude Opus 5 commited on
Commit
ae335b1
·
1 Parent(s): b1f9886

Sync backend to GitHub ad58940: fix Whisper language detection

Browse files

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NoNHrDfqGj7BLKagHkRM3Z

Files changed (1) hide show
  1. backend/routers/prompts.py +16 -0
backend/routers/prompts.py CHANGED
@@ -267,6 +267,15 @@ LANGUAGE_NAMES = {
267
  "gu": "Gujarati", "kn": "Kannada", "pa": "Punjabi", "ml": "Malayalam",
268
  }
269
 
 
 
 
 
 
 
 
 
 
270
 
271
  # Distinctive romanised-Hindi tokens. Deliberately excludes anything that is
272
  # also an ordinary English word — "me", "to", "is", "so", "the", "hi", "an" —
@@ -941,6 +950,13 @@ def _transcription_parts(transcription) -> tuple[str, str]:
941
  else:
942
  language = "unknown"
943
 
 
 
 
 
 
 
 
944
  # Whisper can call Hindi speech Urdu. Preserve the existing product choice
945
  # while refusing unsupported/hallucinated labels as a source-language hint.
946
  if language == "ur":
 
267
  "gu": "Gujarati", "kn": "Kannada", "pa": "Punjabi", "ml": "Malayalam",
268
  }
269
 
270
+ # Reverse of the plain-name entries above, lower-cased, for normalising the
271
+ # language names Whisper returns. "ur" maps to the name "Hindi" too, so the
272
+ # comprehension is ordered to let the real code for each name win: "hindi" →
273
+ # "hi", "urdu" → "ur".
274
+ _LANGUAGE_CODES_BY_NAME = {
275
+ **{name.lower(): code for code, name in LANGUAGE_NAMES.items() if code not in ("ur", "hi-Latn")},
276
+ "urdu": "ur",
277
+ }
278
+
279
 
280
  # Distinctive romanised-Hindi tokens. Deliberately excludes anything that is
281
  # also an ordinary English word — "me", "to", "is", "so", "the", "hi", "an" —
 
950
  else:
951
  language = "unknown"
952
 
953
+ # Groq's verbose_json returns the language as a capitalised English name
954
+ # ("English", "Hindi", "Urdu"), not the ISO code the rest of this module
955
+ # keys on. Checked against the code table alone, every real transcript
956
+ # came back "unknown", so the enhancer never got the source-language hint
957
+ # and the Urdu→Hindi mapping below never fired.
958
+ language = _LANGUAGE_CODES_BY_NAME.get(language.strip().lower(), language)
959
+
960
  # Whisper can call Hindi speech Urdu. Preserve the existing product choice
961
  # while refusing unsupported/hallucinated labels as a source-language hint.
962
  if language == "ur":