NANI-Nithin commited on
Commit
31190c1
·
1 Parent(s): 51c88b7

feat: Normalize output from processor.decode in transcribe function for consistent string handling

Browse files
Files changed (1) hide show
  1. app/services/asr.py +7 -3
app/services/asr.py CHANGED
@@ -265,9 +265,13 @@ def transcribe(
265
  **inputs,
266
  max_new_tokens=max_new_tokens,
267
  )
268
- # Cohere's processor.decode expects the generated tensor as-is
269
- # (per the model card), not a single unwrapped sequence.
270
- text = _processor.decode(outputs, skip_special_tokens=True).strip()
 
 
 
 
271
 
272
  return {
273
  "transcript": text,
 
265
  **inputs,
266
  max_new_tokens=max_new_tokens,
267
  )
268
+ # Cohere's processor.decode is given the generated tensor as-is
269
+ # (per the model card). For a batched [1, seq] output it returns a
270
+ # *list* of strings, so normalize to a single string.
271
+ decoded = _processor.decode(outputs, skip_special_tokens=True)
272
+ if isinstance(decoded, (list, tuple)):
273
+ decoded = decoded[0] if decoded else ""
274
+ text = decoded.strip()
275
 
276
  return {
277
  "transcript": text,