greg0rs commited on
Commit
a02bc29
·
verified ·
1 Parent(s): 8f2f9cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -306,7 +306,7 @@ def load_whisperx_models():
306
  if whisperx_model is None:
307
  log("Loading WhisperX models for English-only processing...")
308
  try:
309
- # Load WhisperX model with English-only configuration
310
  whisperx_model = whisperx.load_model("base.en", device="cpu", compute_type="float32", language="en")
311
  log("WhisperX base.en model loaded successfully")
312
 
@@ -314,17 +314,44 @@ def load_whisperx_models():
314
  whisperx_align_model, whisperx_metadata = whisperx.load_align_model(language_code="en", device="cpu")
315
  log("WhisperX English alignment model loaded successfully")
316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  except Exception as e:
318
  log(f"Error loading WhisperX models: {e}")
319
  # Fallback: try with smaller English-only model
320
  try:
321
  log("Trying fallback with tiny.en model...")
322
- whisperx_model = whisperx.load_model("tiny.en", device="cpu", compute_type="float32", language="en")
323
  whisperx_align_model, whisperx_metadata = whisperx.load_align_model(language_code="en", device="cpu")
324
  log("WhisperX models loaded with fallback (tiny.en model)")
325
  except Exception as fallback_error:
326
  log(f"Fallback also failed: {fallback_error}")
327
- raise
 
 
 
 
 
 
 
 
328
 
329
  def convert_webm_to_wav(bts):
330
  p = subprocess.run(["ffmpeg", "-i", "pipe:0", "-f", "wav", "-ar", "16000", "-ac", "1", "pipe:1"],
 
306
  if whisperx_model is None:
307
  log("Loading WhisperX models for English-only processing...")
308
  try:
309
+ # Try loading with base.en first
310
  whisperx_model = whisperx.load_model("base.en", device="cpu", compute_type="float32", language="en")
311
  log("WhisperX base.en model loaded successfully")
312
 
 
314
  whisperx_align_model, whisperx_metadata = whisperx.load_align_model(language_code="en", device="cpu")
315
  log("WhisperX English alignment model loaded successfully")
316
 
317
+ except ImportError as ie:
318
+ log(f"Import error loading WhisperX models: {ie}")
319
+ # Try without ctranslate2 by using int8 compute type
320
+ try:
321
+ log("Trying fallback with int8 compute type...")
322
+ whisperx_model = whisperx.load_model("base.en", device="cpu", compute_type="int8", language="en")
323
+ whisperx_align_model, whisperx_metadata = whisperx.load_align_model(language_code="en", device="cpu")
324
+ log("WhisperX models loaded with int8 compute type")
325
+ except Exception as fallback_error:
326
+ log(f"Int8 fallback also failed: {fallback_error}")
327
+ # Last resort: try tiny model with default compute
328
+ try:
329
+ log("Trying final fallback with tiny.en model and default compute...")
330
+ whisperx_model = whisperx.load_model("tiny.en", device="cpu", language="en")
331
+ whisperx_align_model, whisperx_metadata = whisperx.load_align_model(language_code="en", device="cpu")
332
+ log("WhisperX models loaded with tiny.en and default compute")
333
+ except Exception as final_error:
334
+ log(f"All WhisperX loading attempts failed: {final_error}")
335
+ raise RuntimeError("Unable to load WhisperX models. Please check environment setup.")
336
  except Exception as e:
337
  log(f"Error loading WhisperX models: {e}")
338
  # Fallback: try with smaller English-only model
339
  try:
340
  log("Trying fallback with tiny.en model...")
341
+ whisperx_model = whisperx.load_model("tiny.en", device="cpu", compute_type="int8", language="en")
342
  whisperx_align_model, whisperx_metadata = whisperx.load_align_model(language_code="en", device="cpu")
343
  log("WhisperX models loaded with fallback (tiny.en model)")
344
  except Exception as fallback_error:
345
  log(f"Fallback also failed: {fallback_error}")
346
+ # Final attempt without compute_type specification
347
+ try:
348
+ log("Final attempt with default settings...")
349
+ whisperx_model = whisperx.load_model("tiny.en", device="cpu", language="en")
350
+ whisperx_align_model, whisperx_metadata = whisperx.load_align_model(language_code="en", device="cpu")
351
+ log("WhisperX models loaded with default settings")
352
+ except Exception as final_error:
353
+ log(f"All attempts failed: {final_error}")
354
+ raise RuntimeError("Unable to load WhisperX models in this environment")
355
 
356
  def convert_webm_to_wav(bts):
357
  p = subprocess.run(["ffmpeg", "-i", "pipe:0", "-f", "wav", "-ar", "16000", "-ac", "1", "pipe:1"],