Spaces:
Runtime error
Runtime error
Harshithtd
commited on
Commit
•
8378a2a
1
Parent(s):
56d0549
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
-
from transformers.pipelines.audio_utils import ffmpeg_read
|
5 |
|
6 |
MODEL_NAME = "openai/whisper-large-v3"
|
7 |
BATCH_SIZE = 8
|
8 |
-
FILE_LIMIT_MB = 1000
|
9 |
|
10 |
device = 0 if torch.cuda.is_available() else "cpu"
|
11 |
|
@@ -16,29 +14,26 @@ pipe = pipeline(
|
|
16 |
device=device,
|
17 |
)
|
18 |
|
19 |
-
def transcribe(
|
20 |
-
if
|
21 |
raise gr.Error("No audio file submitted! Please upload an audio file before submitting your request.")
|
22 |
|
23 |
-
text = pipe(
|
24 |
return text
|
25 |
|
26 |
demo = gr.Interface(
|
27 |
fn=transcribe,
|
28 |
inputs=[
|
29 |
-
gr.Audio(
|
30 |
-
gr.Radio(["transcribe", "translate"], label="Task",
|
31 |
],
|
32 |
outputs="text",
|
33 |
-
layout="horizontal",
|
34 |
-
theme="huggingface",
|
35 |
title="Whisper Large V3: Transcribe Audio",
|
36 |
description=(
|
37 |
"Transcribe audio files with the click of a button! This demo uses the OpenAI Whisper"
|
38 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
39 |
" of arbitrary length."
|
40 |
),
|
41 |
-
allow_flagging="never",
|
42 |
)
|
43 |
|
44 |
demo.launch(enable_queue=True)
|
|
|
1 |
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 |
|
8 |
device = 0 if torch.cuda.is_available() else "cpu"
|
9 |
|
|
|
14 |
device=device,
|
15 |
)
|
16 |
|
17 |
+
def transcribe(audio, task):
|
18 |
+
if audio is None:
|
19 |
raise gr.Error("No audio file submitted! Please upload an audio file before submitting your request.")
|
20 |
|
21 |
+
text = pipe(audio, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
22 |
return text
|
23 |
|
24 |
demo = gr.Interface(
|
25 |
fn=transcribe,
|
26 |
inputs=[
|
27 |
+
gr.Audio(type="filepath", label="Audio file"),
|
28 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
29 |
],
|
30 |
outputs="text",
|
|
|
|
|
31 |
title="Whisper Large V3: Transcribe Audio",
|
32 |
description=(
|
33 |
"Transcribe audio files with the click of a button! This demo uses the OpenAI Whisper"
|
34 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
35 |
" of arbitrary length."
|
36 |
),
|
|
|
37 |
)
|
38 |
|
39 |
demo.launch(enable_queue=True)
|