log capture yield
Browse files
app.py
CHANGED
|
@@ -12,6 +12,15 @@ import torch
|
|
| 12 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 13 |
import yt_dlp
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
logging.basicConfig(level=logging.INFO)
|
| 16 |
|
| 17 |
# Clone and install faster-whisper from GitHub
|
|
@@ -319,7 +328,7 @@ with gr.Blocks() as iface:
|
|
| 319 |
with gr.Row():
|
| 320 |
start_time = gr.Number(label="Start Time (seconds)", value=0)
|
| 321 |
end_time = gr.Number(label="End Time (seconds)", value=0)
|
| 322 |
-
verbose = gr.Checkbox(label="Verbose Output", value=
|
| 323 |
|
| 324 |
transcribe_button = gr.Button("Transcribe")
|
| 325 |
|
|
@@ -339,17 +348,42 @@ with gr.Blocks() as iface:
|
|
| 339 |
|
| 340 |
pipeline_type.change(update_model_dropdown, inputs=pipeline_type, outputs=model_id)
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
transcribe_button.click(
|
| 343 |
-
|
| 344 |
inputs=[input_source, pipeline_type, model_id, dtype, batch_size, download_method, start_time, end_time, verbose],
|
| 345 |
outputs=[metrics_output, transcription_output, transcription_file]
|
| 346 |
)
|
| 347 |
|
| 348 |
gr.Examples(
|
| 349 |
examples=[
|
| 350 |
-
["https://www.youtube.com/watch?v=daQ_hqA6HDo", "faster-batched", "cstr/whisper-large-v3-turbo-int8_float32", "int8", 16, "yt-dlp", 0, None,
|
| 351 |
["https://mcdn.podbean.com/mf/web/dir5wty678b6g4vg/HoP_453_-_The_Price_is_Right_-_Law_and_Economics_in_the_Second_Scholastic5yxzh.mp3", "faster-sequenced", "deepdml/faster-whisper-large-v3-turbo-ct2", "float16", 1, "ffmpeg", 0, 300, True],
|
| 352 |
-
["path/to/local/audio.mp3", "transformers", "openai/whisper-large-v3", "float16", 16, "yt-dlp", 60, 180,
|
| 353 |
],
|
| 354 |
inputs=[input_source, pipeline_type, model_id, dtype, batch_size, download_method, start_time, end_time, verbose],
|
| 355 |
)
|
|
|
|
| 12 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 13 |
import yt_dlp
|
| 14 |
|
| 15 |
+
class LogCapture(io.StringIO):
|
| 16 |
+
def __init__(self, callback):
|
| 17 |
+
super().__init__()
|
| 18 |
+
self.callback = callback
|
| 19 |
+
|
| 20 |
+
def write(self, s):
|
| 21 |
+
super().write(s)
|
| 22 |
+
self.callback(s)
|
| 23 |
+
|
| 24 |
logging.basicConfig(level=logging.INFO)
|
| 25 |
|
| 26 |
# Clone and install faster-whisper from GitHub
|
|
|
|
| 328 |
with gr.Row():
|
| 329 |
start_time = gr.Number(label="Start Time (seconds)", value=0)
|
| 330 |
end_time = gr.Number(label="End Time (seconds)", value=0)
|
| 331 |
+
verbose = gr.Checkbox(label="Verbose Output", value=True) # Set to True by default
|
| 332 |
|
| 333 |
transcribe_button = gr.Button("Transcribe")
|
| 334 |
|
|
|
|
| 348 |
|
| 349 |
pipeline_type.change(update_model_dropdown, inputs=pipeline_type, outputs=model_id)
|
| 350 |
|
| 351 |
+
def transcribe_with_progress(*args):
|
| 352 |
+
args = list(args)
|
| 353 |
+
verbose_index = 8 # Assuming verbose is the 9th argument (index 8)
|
| 354 |
+
args[verbose_index] = True # Force verbose to True
|
| 355 |
+
|
| 356 |
+
log_output = ""
|
| 357 |
+
def log_callback(message):
|
| 358 |
+
nonlocal log_output
|
| 359 |
+
log_output += message
|
| 360 |
+
yield log_output, "", None
|
| 361 |
+
|
| 362 |
+
logger = logging.getLogger()
|
| 363 |
+
logger.setLevel(logging.INFO)
|
| 364 |
+
log_capture = LogCapture(log_callback)
|
| 365 |
+
logger.addHandler(logging.StreamHandler(log_capture))
|
| 366 |
+
|
| 367 |
+
try:
|
| 368 |
+
for progress in transcribe_audio(*args):
|
| 369 |
+
yield log_output + progress, "", None
|
| 370 |
+
finally:
|
| 371 |
+
logger.removeHandler(log_capture)
|
| 372 |
+
|
| 373 |
+
final_transcription = "This is the final transcription." # Replace with actual transcription
|
| 374 |
+
yield log_output, final_transcription, None # You might want to yield the actual file here instead of None
|
| 375 |
+
|
| 376 |
transcribe_button.click(
|
| 377 |
+
transcribe_with_progress,
|
| 378 |
inputs=[input_source, pipeline_type, model_id, dtype, batch_size, download_method, start_time, end_time, verbose],
|
| 379 |
outputs=[metrics_output, transcription_output, transcription_file]
|
| 380 |
)
|
| 381 |
|
| 382 |
gr.Examples(
|
| 383 |
examples=[
|
| 384 |
+
["https://www.youtube.com/watch?v=daQ_hqA6HDo", "faster-batched", "cstr/whisper-large-v3-turbo-int8_float32", "int8", 16, "yt-dlp", 0, None, True],
|
| 385 |
["https://mcdn.podbean.com/mf/web/dir5wty678b6g4vg/HoP_453_-_The_Price_is_Right_-_Law_and_Economics_in_the_Second_Scholastic5yxzh.mp3", "faster-sequenced", "deepdml/faster-whisper-large-v3-turbo-ct2", "float16", 1, "ffmpeg", 0, 300, True],
|
| 386 |
+
["path/to/local/audio.mp3", "transformers", "openai/whisper-large-v3", "float16", 16, "yt-dlp", 60, 180, True]
|
| 387 |
],
|
| 388 |
inputs=[input_source, pipeline_type, model_id, dtype, batch_size, download_method, start_time, end_time, verbose],
|
| 389 |
)
|