Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,7 @@ from transformers import pipeline
|
|
3 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
4 |
import gradio as gr
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
MODEL_NAME = "ovieyra21/whisper-small-curso"
|
9 |
BATCH_SIZE = 8
|
10 |
|
11 |
device = 0 if torch.cuda.is_available() else "cpu"
|
@@ -17,6 +15,7 @@ pipe = pipeline(
|
|
17 |
device=device,
|
18 |
)
|
19 |
|
|
|
20 |
# Copied from https://github.com/openai/whisper/blob/c09a7ae299c4c34c5839a76380ae407e7d785914/whisper/utils.py#L50
|
21 |
def format_timestamp(seconds: float, always_include_hours: bool = False, decimal_marker: str = "."):
|
22 |
if seconds is not None:
|
@@ -37,6 +36,7 @@ def format_timestamp(seconds: float, always_include_hours: bool = False, decimal
|
|
37 |
# we have a malformed timestamp so just return it as is
|
38 |
return seconds
|
39 |
|
|
|
40 |
def transcribe(file, task, return_timestamps):
|
41 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=return_timestamps)
|
42 |
text = outputs["text"]
|
@@ -70,10 +70,11 @@ mic_transcribe = gr.Interface(
|
|
70 |
),
|
71 |
allow_flagging="never",
|
72 |
)
|
|
|
73 |
file_transcribe = gr.Interface(
|
74 |
fn=transcribe,
|
75 |
inputs=[
|
76 |
-
gr.inputs.Audio(source="upload", optional=True, label="Audio file", type="
|
77 |
gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
78 |
gr.inputs.Checkbox(default=False, label="Return timestamps"),
|
79 |
],
|
@@ -97,6 +98,4 @@ file_transcribe = gr.Interface(
|
|
97 |
with demo:
|
98 |
gr.TabbedInterface([mic_transcribe, file_transcribe], ["Transcribe Microphone", "Transcribe Audio File"])
|
99 |
|
100 |
-
|
101 |
-
|
102 |
demo.launch(enable_queue=True)
|
|
|
3 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
4 |
import gradio as gr
|
5 |
|
6 |
+
MODEL_NAME = "openai/whisper-small"
|
|
|
|
|
7 |
BATCH_SIZE = 8
|
8 |
|
9 |
device = 0 if torch.cuda.is_available() else "cpu"
|
|
|
15 |
device=device,
|
16 |
)
|
17 |
|
18 |
+
|
19 |
# Copied from https://github.com/openai/whisper/blob/c09a7ae299c4c34c5839a76380ae407e7d785914/whisper/utils.py#L50
|
20 |
def format_timestamp(seconds: float, always_include_hours: bool = False, decimal_marker: str = "."):
|
21 |
if seconds is not None:
|
|
|
36 |
# we have a malformed timestamp so just return it as is
|
37 |
return seconds
|
38 |
|
39 |
+
|
40 |
def transcribe(file, task, return_timestamps):
|
41 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=return_timestamps)
|
42 |
text = outputs["text"]
|
|
|
70 |
),
|
71 |
allow_flagging="never",
|
72 |
)
|
73 |
+
|
74 |
file_transcribe = gr.Interface(
|
75 |
fn=transcribe,
|
76 |
inputs=[
|
77 |
+
gr.inputs.Audio(source="upload", optional=True, label="Audio file", type="filepath"),
|
78 |
gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
79 |
gr.inputs.Checkbox(default=False, label="Return timestamps"),
|
80 |
],
|
|
|
98 |
with demo:
|
99 |
gr.TabbedInterface([mic_transcribe, file_transcribe], ["Transcribe Microphone", "Transcribe Audio File"])
|
100 |
|
|
|
|
|
101 |
demo.launch(enable_queue=True)
|