Spaces:
Running
Running
fix bench
Browse files
app.py
CHANGED
|
@@ -528,13 +528,14 @@ def get_model_options(pipeline_type):
|
|
| 528 |
# Dictionary to store loaded models
|
| 529 |
loaded_models = {}
|
| 530 |
|
| 531 |
-
def transcribe_audio(audio_input, audio_url, proxy_url, proxy_username, proxy_password, pipeline_type, model_id, dtype, batch_size, download_method, start_time=None, end_time=None, verbose=False, include_timecodes=False):
|
| 532 |
"""
|
| 533 |
Transcribes audio from a given source using the specified pipeline and model.
|
| 534 |
|
| 535 |
Args:
|
| 536 |
audio_input (str): Path to uploaded audio file or recorded audio.
|
| 537 |
audio_url (str): URL of audio.
|
|
|
|
| 538 |
proxy_url (str): Proxy URL if needed.
|
| 539 |
proxy_username (str): Proxy username.
|
| 540 |
proxy_password (str): Proxy password.
|
|
@@ -573,7 +574,7 @@ def transcribe_audio(audio_input, audio_url, proxy_url, proxy_username, proxy_pa
|
|
| 573 |
is_temp_file = False
|
| 574 |
elif audio_url is not None and len(audio_url.strip()) > 0:
|
| 575 |
# audio_url is provided
|
| 576 |
-
audio_path, is_temp_file = download_audio(audio_url, download_method, proxy_url, proxy_username, proxy_password)
|
| 577 |
if not audio_path:
|
| 578 |
error_msg = f"Error downloading audio from {audio_url} using method {download_method}. Check logs for details."
|
| 579 |
logging.error(error_msg)
|
|
@@ -639,10 +640,15 @@ def transcribe_audio(audio_input, audio_url, proxy_url, proxy_username, proxy_pa
|
|
| 639 |
|
| 640 |
# Perform the transcription
|
| 641 |
start_time_perf = time.time()
|
|
|
|
|
|
|
| 642 |
if pipeline_type == "faster-batched":
|
| 643 |
segments, info = model_or_pipeline.transcribe(audio_path, batch_size=batch_size)
|
|
|
|
|
|
|
| 644 |
elif pipeline_type == "faster-sequenced":
|
| 645 |
segments, info = model_or_pipeline.transcribe(audio_path)
|
|
|
|
| 646 |
else:
|
| 647 |
result = model_or_pipeline(audio_path)
|
| 648 |
segments = result["chunks"]
|
|
@@ -661,8 +667,6 @@ def transcribe_audio(audio_input, audio_url, proxy_url, proxy_username, proxy_pa
|
|
| 661 |
yield verbose_messages + metrics_output, "", None
|
| 662 |
|
| 663 |
# Compile the transcription text
|
| 664 |
-
transcription = ""
|
| 665 |
-
|
| 666 |
for segment in segments:
|
| 667 |
if pipeline_type in ["faster-batched", "faster-sequenced"]:
|
| 668 |
if include_timecodes:
|
|
|
|
| 528 |
# Dictionary to store loaded models
|
| 529 |
loaded_models = {}
|
| 530 |
|
| 531 |
+
def transcribe_audio(audio_input, audio_url, use_tor, proxy_url, proxy_username, proxy_password, pipeline_type, model_id, dtype, batch_size, download_method, start_time=None, end_time=None, verbose=False, include_timecodes=False):
|
| 532 |
"""
|
| 533 |
Transcribes audio from a given source using the specified pipeline and model.
|
| 534 |
|
| 535 |
Args:
|
| 536 |
audio_input (str): Path to uploaded audio file or recorded audio.
|
| 537 |
audio_url (str): URL of audio.
|
| 538 |
+
use_tor (bool): Whether to use Tor for downloading.
|
| 539 |
proxy_url (str): Proxy URL if needed.
|
| 540 |
proxy_username (str): Proxy username.
|
| 541 |
proxy_password (str): Proxy password.
|
|
|
|
| 574 |
is_temp_file = False
|
| 575 |
elif audio_url is not None and len(audio_url.strip()) > 0:
|
| 576 |
# audio_url is provided
|
| 577 |
+
audio_path, is_temp_file = download_audio(audio_url, download_method, use_tor, proxy_url, proxy_username, proxy_password)
|
| 578 |
if not audio_path:
|
| 579 |
error_msg = f"Error downloading audio from {audio_url} using method {download_method}. Check logs for details."
|
| 580 |
logging.error(error_msg)
|
|
|
|
| 640 |
|
| 641 |
# Perform the transcription
|
| 642 |
start_time_perf = time.time()
|
| 643 |
+
transcription = ""
|
| 644 |
+
|
| 645 |
if pipeline_type == "faster-batched":
|
| 646 |
segments, info = model_or_pipeline.transcribe(audio_path, batch_size=batch_size)
|
| 647 |
+
# Since segments is a generator, we need to iterate over it to complete transcription
|
| 648 |
+
segments = list(segments) # Exhaust the generator
|
| 649 |
elif pipeline_type == "faster-sequenced":
|
| 650 |
segments, info = model_or_pipeline.transcribe(audio_path)
|
| 651 |
+
segments = list(segments) # Exhaust the generator
|
| 652 |
else:
|
| 653 |
result = model_or_pipeline(audio_path)
|
| 654 |
segments = result["chunks"]
|
|
|
|
| 667 |
yield verbose_messages + metrics_output, "", None
|
| 668 |
|
| 669 |
# Compile the transcription text
|
|
|
|
|
|
|
| 670 |
for segment in segments:
|
| 671 |
if pipeline_type in ["faster-batched", "faster-sequenced"]:
|
| 672 |
if include_timecodes:
|