Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,11 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
MODEL_NAME = "openai/whisper-large-v3"
|
6 |
BATCH_SIZE = 8
|
7 |
|
@@ -20,7 +25,6 @@ def transcribe(audio_file, task):
|
|
20 |
|
21 |
result = pipe(audio_file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)
|
22 |
|
23 |
-
# Format the output with timestamps
|
24 |
output = ""
|
25 |
for chunk in result["chunks"]:
|
26 |
start_time = chunk["timestamp"][0]
|
@@ -35,14 +39,16 @@ def format_timestamp(seconds):
|
|
35 |
hours, minutes = divmod(minutes, 60)
|
36 |
return f"{int(hours):02d}:{int(minutes):02d}:{seconds:.2f}"
|
37 |
|
|
|
|
|
|
|
|
|
|
|
38 |
demo = gr.Interface(
|
39 |
fn=transcribe,
|
40 |
-
inputs=[
|
41 |
-
|
42 |
-
|
43 |
-
],
|
44 |
-
outputs=gr.Textbox(label="Transcription with Timestamps"),
|
45 |
-
title="Whisper Large V3: Transcribe Audio with Timestamps",
|
46 |
description=(
|
47 |
f"Transcribe audio files with Whisper Large V3 [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}). "
|
48 |
"Upload an audio file and choose whether to transcribe or translate. "
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
# Add version control
|
6 |
+
import pkg_resources
|
7 |
+
gradio_version = pkg_resources.get_distribution("gradio").version
|
8 |
+
print(f"Gradio version: {gradio_version}")
|
9 |
+
|
10 |
MODEL_NAME = "openai/whisper-large-v3"
|
11 |
BATCH_SIZE = 8
|
12 |
|
|
|
25 |
|
26 |
result = pipe(audio_file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)
|
27 |
|
|
|
28 |
output = ""
|
29 |
for chunk in result["chunks"]:
|
30 |
start_time = chunk["timestamp"][0]
|
|
|
39 |
hours, minutes = divmod(minutes, 60)
|
40 |
return f"{int(hours):02d}:{int(minutes):02d}:{seconds:.2f}"
|
41 |
|
42 |
+
# Use specific Gradio components
|
43 |
+
audio_input = gr.components.File(label="Audio file", file_types=["audio"])
|
44 |
+
task_input = gr.components.Radio(["transcribe", "translate"], label="Task", default="transcribe")
|
45 |
+
output = gr.components.Textbox(label="Transcription with Timestamps")
|
46 |
+
|
47 |
demo = gr.Interface(
|
48 |
fn=transcribe,
|
49 |
+
inputs=[audio_input, task_input],
|
50 |
+
outputs=output,
|
51 |
+
title=f"Whisper Large V3: Transcribe Audio with Timestamps (Gradio v{gradio_version})",
|
|
|
|
|
|
|
52 |
description=(
|
53 |
f"Transcribe audio files with Whisper Large V3 [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}). "
|
54 |
"Upload an audio file and choose whether to transcribe or translate. "
|