Spaces:
Running
on
T4
Running
on
T4
Commit
•
7097513
1
Parent(s):
4314e4c
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
|
|
4 |
import pytube as pt
|
5 |
from transformers import pipeline
|
6 |
|
7 |
-
MODEL_NAME = "openai/whisper-
|
8 |
|
9 |
device = 0 if torch.cuda.is_available() else "cpu"
|
10 |
|
@@ -21,7 +21,7 @@ transcribe_token_id = all_special_ids[-5]
|
|
21 |
translate_token_id = all_special_ids[-6]
|
22 |
|
23 |
|
24 |
-
def transcribe(microphone, file_upload,
|
25 |
warn_output = ""
|
26 |
if (microphone is not None) and (file_upload is not None):
|
27 |
warn_output = (
|
@@ -34,7 +34,7 @@ def transcribe(microphone, file_upload, do_translate):
|
|
34 |
|
35 |
file = microphone if microphone is not None else file_upload
|
36 |
|
37 |
-
pipe.model.config.forced_decoder_ids = [[2,
|
38 |
|
39 |
text = pipe(file)["text"]
|
40 |
|
@@ -50,13 +50,13 @@ def _return_yt_html_embed(yt_url):
|
|
50 |
return HTML_str
|
51 |
|
52 |
|
53 |
-
def yt_transcribe(yt_url,
|
54 |
yt = pt.YouTube(yt_url)
|
55 |
html_embed_str = _return_yt_html_embed(yt_url)
|
56 |
stream = yt.streams.filter(only_audio=True)[0]
|
57 |
stream.download(filename="audio.mp3")
|
58 |
|
59 |
-
pipe.model.config.forced_decoder_ids = [[2,
|
60 |
|
61 |
text = pipe("audio.mp3")["text"]
|
62 |
|
@@ -70,7 +70,7 @@ mf_transcribe = gr.Interface(
|
|
70 |
inputs=[
|
71 |
gr.inputs.Audio(source="microphone", type="filepath", optional=True),
|
72 |
gr.inputs.Audio(source="upload", type="filepath", optional=True),
|
73 |
-
gr.
|
74 |
],
|
75 |
outputs="text",
|
76 |
layout="horizontal",
|
@@ -86,7 +86,10 @@ mf_transcribe = gr.Interface(
|
|
86 |
|
87 |
yt_transcribe = gr.Interface(
|
88 |
fn=yt_transcribe,
|
89 |
-
inputs=[
|
|
|
|
|
|
|
90 |
outputs=["html", "text"],
|
91 |
layout="horizontal",
|
92 |
theme="huggingface",
|
@@ -102,4 +105,5 @@ yt_transcribe = gr.Interface(
|
|
102 |
with demo:
|
103 |
gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
|
104 |
|
105 |
-
demo.launch(enable_queue=True
|
|
|
|
4 |
import pytube as pt
|
5 |
from transformers import pipeline
|
6 |
|
7 |
+
MODEL_NAME = "openai/whisper-large-v2"
|
8 |
|
9 |
device = 0 if torch.cuda.is_available() else "cpu"
|
10 |
|
|
|
21 |
translate_token_id = all_special_ids[-6]
|
22 |
|
23 |
|
24 |
+
def transcribe(microphone, file_upload, task):
|
25 |
warn_output = ""
|
26 |
if (microphone is not None) and (file_upload is not None):
|
27 |
warn_output = (
|
|
|
34 |
|
35 |
file = microphone if microphone is not None else file_upload
|
36 |
|
37 |
+
pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id if task=="transcribe" else translate_token_id]]
|
38 |
|
39 |
text = pipe(file)["text"]
|
40 |
|
|
|
50 |
return HTML_str
|
51 |
|
52 |
|
53 |
+
def yt_transcribe(yt_url, task):
|
54 |
yt = pt.YouTube(yt_url)
|
55 |
html_embed_str = _return_yt_html_embed(yt_url)
|
56 |
stream = yt.streams.filter(only_audio=True)[0]
|
57 |
stream.download(filename="audio.mp3")
|
58 |
|
59 |
+
pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id if task=="transcribe" else translate_token_id]]
|
60 |
|
61 |
text = pipe("audio.mp3")["text"]
|
62 |
|
|
|
70 |
inputs=[
|
71 |
gr.inputs.Audio(source="microphone", type="filepath", optional=True),
|
72 |
gr.inputs.Audio(source="upload", type="filepath", optional=True),
|
73 |
+
gr.inputs.Radio(["transcribe", "translate"], label="task", default="transcribe"),
|
74 |
],
|
75 |
outputs="text",
|
76 |
layout="horizontal",
|
|
|
86 |
|
87 |
yt_transcribe = gr.Interface(
|
88 |
fn=yt_transcribe,
|
89 |
+
inputs=[
|
90 |
+
gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
91 |
+
gr.inputs.Radio(["transcribe", "translate"], label="task", default="transcribe")
|
92 |
+
],
|
93 |
outputs=["html", "text"],
|
94 |
layout="horizontal",
|
95 |
theme="huggingface",
|
|
|
105 |
with demo:
|
106 |
gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
|
107 |
|
108 |
+
demo.launch(enable_queue=True)
|
109 |
+
|