nexusbert commited on
Commit
652b643
·
1 Parent(s): fc4d065

token issue fix

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -106,6 +106,9 @@ def _get_igbo_asr():
106
  logger.warning("HF_TOKEN not set - Igbo ASR model requires authentication")
107
  return None, None
108
 
 
 
 
109
  try:
110
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
111
  logger.info("Lazy-loading Igbo ASR model (gated model)...")
@@ -118,6 +121,7 @@ def _get_igbo_asr():
118
  except Exception as e:
119
  logger.exception(f"Failed to load Igbo ASR model: {e}")
120
  igbo_model, igbo_processor = None, None
 
121
  def _run_whisper(model: WhisperForConditionalGeneration, proc: WhisperProcessor, audio_array: np.ndarray) -> str:
122
  try:
123
  device = next(model.parameters()).device
@@ -177,16 +181,18 @@ def speech_to_text(audio_data: bytes) -> str:
177
  audio_array = preprocess_audio_ffmpeg(audio_data)
178
 
179
  # Try Igbo ASR first for better Igbo detection
180
- igbo_model, igbo_proc = _get_igbo_asr()
181
- if igbo_model is not None and igbo_proc is not None:
 
182
  igbo_text = _run_whisper(igbo_model, igbo_proc, audio_array)
183
  if igbo_text and igbo_text.strip():
184
  logger.info("Using Igbo ASR result")
185
  return igbo_text
186
 
187
  # Fallback to MMS for other languages
188
- mms_model, mms_proc = _get_mms()
189
- if mms_model is not None and mms_proc is not None:
 
190
  mms_text = _run_mms(mms_model, mms_proc, audio_array)
191
  if mms_text and mms_text.strip():
192
  logger.info("Using MMS ASR result")
 
106
  logger.warning("HF_TOKEN not set - Igbo ASR model requires authentication")
107
  return None, None
108
 
109
+
110
+ hf_token = hf_token.strip()
111
+
112
  try:
113
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
114
  logger.info("Lazy-loading Igbo ASR model (gated model)...")
 
121
  except Exception as e:
122
  logger.exception(f"Failed to load Igbo ASR model: {e}")
123
  igbo_model, igbo_processor = None, None
124
+ return None, None
125
  def _run_whisper(model: WhisperForConditionalGeneration, proc: WhisperProcessor, audio_array: np.ndarray) -> str:
126
  try:
127
  device = next(model.parameters()).device
 
181
  audio_array = preprocess_audio_ffmpeg(audio_data)
182
 
183
  # Try Igbo ASR first for better Igbo detection
184
+ igbo_result = _get_igbo_asr()
185
+ if igbo_result[0] is not None and igbo_result[1] is not None:
186
+ igbo_model, igbo_proc = igbo_result
187
  igbo_text = _run_whisper(igbo_model, igbo_proc, audio_array)
188
  if igbo_text and igbo_text.strip():
189
  logger.info("Using Igbo ASR result")
190
  return igbo_text
191
 
192
  # Fallback to MMS for other languages
193
+ mms_result = _get_mms()
194
+ if mms_result[0] is not None and mms_result[1] is not None:
195
+ mms_model, mms_proc = mms_result
196
  mms_text = _run_mms(mms_model, mms_proc, audio_array)
197
  if mms_text and mms_text.strip():
198
  logger.info("Using MMS ASR result")