xieli commited on
Commit
066d2f4
·
1 Parent(s): 5bdad28

feat: fix asr

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -170,6 +170,27 @@ def process_audio_with_gpu(audio_input, text_input, target_text, task_type, task
170
  logger.error(f"❌ Audio processing failed: {e}")
171
  raise
172
  # GPU automatically deallocated when function exits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  # Save audio to temporary directory
175
  def save_audio(audio_type, audio_data, sr, tmp_dir):
@@ -450,27 +471,6 @@ class EditxTab:
450
  value = None if len(choices) == 0 else choices[0]
451
  return gr.Dropdown(label="Sub-task", choices=choices, value=value)
452
 
453
- @spaces.GPU(duration=30)
454
- def transcribe_audio(self, audio_input, current_text):
455
- """Transcribe audio using Whisper ASR when prompt text is empty"""
456
- global whisper_asr
457
- # Only transcribe if current text is empty
458
- if current_text and current_text.strip():
459
- return current_text # Keep existing text
460
- if not audio_input:
461
- return "" # No audio to transcribe
462
- if whisper_asr is None:
463
- initialize_whisper()
464
-
465
- try:
466
- # Transcribe audio
467
- transcribed_text = whisper_asr(audio_input)
468
- self.logger.info(f"Audio transcribed: {transcribed_text}")
469
- return transcribed_text
470
- except Exception as e:
471
- self.logger.error(f"Failed to transcribe audio: {e}")
472
- return ""
473
-
474
 
475
  def launch_demo(args, editx_tab):
476
  """Launch the gradio demo"""
 
170
  logger.error(f"❌ Audio processing failed: {e}")
171
  raise
172
  # GPU automatically deallocated when function exits
173
+
174
+ @spaces.GPU(duration=30)
175
+ def transcribe_audio(self, audio_input, current_text):
176
+ """Transcribe audio using Whisper ASR when prompt text is empty"""
177
+ global whisper_asr
178
+ # Only transcribe if current text is empty
179
+ if current_text and current_text.strip():
180
+ return current_text # Keep existing text
181
+ if not audio_input:
182
+ return "" # No audio to transcribe
183
+ if whisper_asr is None:
184
+ initialize_whisper()
185
+
186
+ try:
187
+ # Transcribe audio
188
+ transcribed_text = whisper_asr(audio_input)
189
+ self.logger.info(f"Audio transcribed: {transcribed_text}")
190
+ return transcribed_text
191
+ except Exception as e:
192
+ self.logger.error(f"Failed to transcribe audio: {e}")
193
+ return ""
194
 
195
  # Save audio to temporary directory
196
  def save_audio(audio_type, audio_data, sr, tmp_dir):
 
471
  value = None if len(choices) == 0 else choices[0]
472
  return gr.Dropdown(label="Sub-task", choices=choices, value=value)
473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
 
475
  def launch_demo(args, editx_tab):
476
  """Launch the gradio demo"""