v-e-n-o-m commited on
Commit
f1ea267
·
1 Parent(s): e65b477
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -20,7 +20,12 @@ app = FastAPI()
20
  model_name = "ihanif/whisper-medium-urdu"
21
  try:
22
  logger.info(f"Loading processor for {model_name}")
23
- processor = WhisperProcessor.from_pretrained(model_name, language="urdu", task="transcribe")
 
 
 
 
 
24
  logger.info(f"Loading model for {model_name}")
25
  model = WhisperForConditionalGeneration.from_pretrained(model_name, low_cpu_mem_usage=True)
26
  except Exception as e:
@@ -84,11 +89,10 @@ async def transcribe_audio(file: UploadFile = File(...)):
84
  return generated_ids
85
 
86
  try:
87
- async with asyncio.timeout(60): # 60-second timeout
88
- generated_ids = await generate_transcription()
89
  except asyncio.TimeoutError:
90
  logger.error("Transcription timed out after 60 seconds")
91
- return {"error": "Transcription took too long. Try a smaller model or upgrade your Space."}
92
 
93
  transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
94
  total_time = time.time() - start_time
 
20
  model_name = "ihanif/whisper-medium-urdu"
21
  try:
22
  logger.info(f"Loading processor for {model_name}")
23
+ processor = WhisperProcessor.from_pretrained(
24
+ model_name,
25
+ language="urdu",
26
+ task="transcribe",
27
+ clean_up_tokenization_spaces=True # Suppress FutureWarning
28
+ )
29
  logger.info(f"Loading model for {model_name}")
30
  model = WhisperForConditionalGeneration.from_pretrained(model_name, low_cpu_mem_usage=True)
31
  except Exception as e:
 
89
  return generated_ids
90
 
91
  try:
92
+ generated_ids = await asyncio.wait_for(generate_transcription(), timeout=60) # 60-second timeout
 
93
  except asyncio.TimeoutError:
94
  logger.error("Transcription timed out after 60 seconds")
95
+ return {"error": "Transcription took too long. Try a smaller model (e.g., whisper-small) or upgrade to a paid Hugging Face Space with GPU."}
96
 
97
  transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
98
  total_time = time.time() - start_time