Spaces:
Running
on
T4
Running
on
T4
update test
Browse files
app.py
CHANGED
@@ -65,24 +65,19 @@ def _return_yt_html_embed(yt_url):
|
|
65 |
return HTML_str
|
66 |
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
'outtmpl': 'audio.mp3',
|
72 |
-
'noplaylist': True
|
73 |
-
}
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
except Exception as e:
|
79 |
-
return f"Error downloading audio: {str(e)}"
|
80 |
|
81 |
-
|
82 |
-
|
83 |
|
84 |
-
text =
|
85 |
-
return
|
86 |
|
87 |
|
88 |
demo = gr.Blocks()
|
@@ -90,8 +85,8 @@ demo = gr.Blocks()
|
|
90 |
mf_transcribe = gr.Interface(
|
91 |
fn=transcribe,
|
92 |
inputs=[
|
93 |
-
gr.
|
94 |
-
gr.
|
95 |
],
|
96 |
outputs="text",
|
97 |
title="NB-Whisper Demo",
|
@@ -106,20 +101,20 @@ mf_transcribe = gr.Interface(
|
|
106 |
yt_transcribe = gr.Interface(
|
107 |
fn=yt_transcribe,
|
108 |
inputs=[
|
109 |
-
gr.
|
110 |
-
gr.
|
111 |
],
|
112 |
-
examples=[["https://www.youtube.com/watch?v=mukeSSa5GKo"]],
|
113 |
outputs=["html", "text"],
|
114 |
title="Whisper Demo: Transcribe YouTube",
|
115 |
description=(
|
116 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the the fine-tuned checkpoint:"
|
117 |
-
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe
|
118 |
" arbitrary length."
|
119 |
),
|
120 |
allow_flagging="never",
|
121 |
)
|
122 |
|
|
|
123 |
with demo:
|
124 |
gr.TabbedInterface([
|
125 |
mf_transcribe,
|
|
|
65 |
return HTML_str
|
66 |
|
67 |
|
68 |
+
@spaces.GPU
|
69 |
+
def yt_transcribe(yt_url, task):
|
70 |
+
html_embed_str = _return_yt_html_embed(yt_url)
|
|
|
|
|
|
|
71 |
|
72 |
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
73 |
+
filepath = os.path.join(tmpdirname, "audio.mp3")
|
74 |
+
download_yt_audio(yt_url, filepath)
|
|
|
|
|
75 |
|
76 |
+
inputs = ffmpeg_read(filepath, pipe.feature_extractor.sampling_rate)
|
77 |
+
inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
|
78 |
|
79 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
80 |
+
return html_embed_str, text
|
81 |
|
82 |
|
83 |
demo = gr.Blocks()
|
|
|
85 |
mf_transcribe = gr.Interface(
|
86 |
fn=transcribe,
|
87 |
inputs=[
|
88 |
+
gr.Audio(sources="microphone", type="filepath"),
|
89 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
90 |
],
|
91 |
outputs="text",
|
92 |
title="NB-Whisper Demo",
|
|
|
101 |
yt_transcribe = gr.Interface(
|
102 |
fn=yt_transcribe,
|
103 |
inputs=[
|
104 |
+
gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
105 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
106 |
],
|
|
|
107 |
outputs=["html", "text"],
|
108 |
title="Whisper Demo: Transcribe YouTube",
|
109 |
description=(
|
110 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the the fine-tuned checkpoint:"
|
111 |
+
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
112 |
" arbitrary length."
|
113 |
),
|
114 |
allow_flagging="never",
|
115 |
)
|
116 |
|
117 |
+
|
118 |
with demo:
|
119 |
gr.TabbedInterface([
|
120 |
mf_transcribe,
|