Update app.py
Browse files
app.py
CHANGED
@@ -18,20 +18,35 @@ def transcribe(audio_file, task):
|
|
18 |
if audio_file is None:
|
19 |
raise gr.Error("No audio file submitted! Please upload an audio file before submitting your request.")
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
demo = gr.Interface(
|
25 |
fn=transcribe,
|
26 |
inputs=[
|
27 |
-
gr.
|
28 |
gr.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
29 |
],
|
30 |
-
outputs="
|
31 |
-
title="Whisper Large V3: Transcribe Audio",
|
32 |
description=(
|
33 |
f"Transcribe audio files with Whisper Large V3 [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}). "
|
34 |
-
"Upload an audio file and choose whether to transcribe or translate."
|
|
|
35 |
),
|
36 |
)
|
37 |
|
|
|
18 |
if audio_file is None:
|
19 |
raise gr.Error("No audio file submitted! Please upload an audio file before submitting your request.")
|
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]
|
27 |
+
end_time = chunk["timestamp"][1]
|
28 |
+
text = chunk["text"]
|
29 |
+
output += f"[{format_timestamp(start_time)} -> {format_timestamp(end_time)}] {text}\n"
|
30 |
+
|
31 |
+
return output
|
32 |
+
|
33 |
+
def format_timestamp(seconds):
|
34 |
+
minutes, seconds = divmod(seconds, 60)
|
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 |
+
gr.File(label="Audio file", file_types=["audio"]),
|
42 |
gr.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
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. "
|
49 |
+
"The output includes timestamps for each transcribed segment."
|
50 |
),
|
51 |
)
|
52 |
|