Spaces:
Runtime error
Runtime error
TogetherAI
commited on
Commit
•
1bfe127
1
Parent(s):
231f5c6
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import torch
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import yt_dlp as youtube_dl
|
5 |
from transformers import pipeline
|
6 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
7 |
-
|
8 |
import tempfile
|
9 |
import os
|
|
|
10 |
|
11 |
MODEL_NAME = "openai/whisper-large-v3"
|
12 |
BATCH_SIZE = 8
|
@@ -22,14 +21,12 @@ pipe = pipeline(
|
|
22 |
device=device,
|
23 |
)
|
24 |
|
25 |
-
|
26 |
def transcribe(inputs, task):
|
27 |
if inputs is None:
|
28 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
29 |
|
30 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
31 |
-
return
|
32 |
-
|
33 |
|
34 |
def _return_yt_html_embed(yt_url):
|
35 |
video_id = yt_url.split("?v=")[-1]
|
@@ -47,19 +44,10 @@ def download_yt_audio(yt_url, filename):
|
|
47 |
except youtube_dl.utils.DownloadError as err:
|
48 |
raise gr.Error(str(err))
|
49 |
|
50 |
-
file_length = info["
|
51 |
-
|
52 |
-
file_h_m_s = [int(sub_length) for sub_length in file_h_m_s]
|
53 |
-
|
54 |
-
if len(file_h_m_s) == 1:
|
55 |
-
file_h_m_s.insert(0, 0)
|
56 |
-
if len(file_h_m_s) == 2:
|
57 |
-
file_h_m_s.insert(0, 0)
|
58 |
-
file_length_s = file_h_m_s[0] * 3600 + file_h_m_s[1] * 60 + file_h_m_s[2]
|
59 |
-
|
60 |
-
if file_length_s > YT_LENGTH_LIMIT_S:
|
61 |
yt_length_limit_hms = time.strftime("%HH:%MM:%SS", time.gmtime(YT_LENGTH_LIMIT_S))
|
62 |
-
file_length_hms = time.strftime("%HH:%MM:%SS", time.gmtime(
|
63 |
raise gr.Error(f"Maximum YouTube length is {yt_length_limit_hms}, got {file_length_hms} YouTube video.")
|
64 |
|
65 |
ydl_opts = {"outtmpl": filename, "format": "worstvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"}
|
@@ -70,8 +58,7 @@ def download_yt_audio(yt_url, filename):
|
|
70 |
except youtube_dl.utils.ExtractorError as err:
|
71 |
raise gr.Error(str(err))
|
72 |
|
73 |
-
|
74 |
-
def yt_transcribe(yt_url, task, max_filesize=75.0):
|
75 |
html_embed_str = _return_yt_html_embed(yt_url)
|
76 |
|
77 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
@@ -87,8 +74,7 @@ def yt_transcribe(yt_url, task, max_filesize=75.0):
|
|
87 |
|
88 |
return html_embed_str, text
|
89 |
|
90 |
-
|
91 |
-
demo = gr.Blocks(theme="TogetherAI/Alex2_Theme")
|
92 |
|
93 |
mf_transcribe = gr.Interface(
|
94 |
fn=transcribe,
|
@@ -98,7 +84,7 @@ mf_transcribe = gr.Interface(
|
|
98 |
],
|
99 |
outputs="text",
|
100 |
layout="horizontal",
|
101 |
-
theme="
|
102 |
title="Whisper Large V3: Transcribe Audio",
|
103 |
description=(
|
104 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
|
@@ -116,7 +102,7 @@ file_transcribe = gr.Interface(
|
|
116 |
],
|
117 |
outputs="text",
|
118 |
layout="horizontal",
|
119 |
-
theme="
|
120 |
title="Whisper Large V3: Transcribe Audio",
|
121 |
description=(
|
122 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
|
@@ -134,7 +120,7 @@ yt_transcribe = gr.Interface(
|
|
134 |
],
|
135 |
outputs=["html", "text"],
|
136 |
layout="horizontal",
|
137 |
-
theme="
|
138 |
title="Whisper Large V3: Transcribe YouTube",
|
139 |
description=(
|
140 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
|
@@ -147,4 +133,4 @@ yt_transcribe = gr.Interface(
|
|
147 |
with demo:
|
148 |
gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
149 |
|
150 |
-
demo.launch(enable_queue=True)
|
|
|
1 |
import torch
|
|
|
2 |
import gradio as gr
|
3 |
import yt_dlp as youtube_dl
|
4 |
from transformers import pipeline
|
5 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
|
|
6 |
import tempfile
|
7 |
import os
|
8 |
+
import time
|
9 |
|
10 |
MODEL_NAME = "openai/whisper-large-v3"
|
11 |
BATCH_SIZE = 8
|
|
|
21 |
device=device,
|
22 |
)
|
23 |
|
|
|
24 |
def transcribe(inputs, task):
|
25 |
if inputs is None:
|
26 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
27 |
|
28 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
29 |
+
return text
|
|
|
30 |
|
31 |
def _return_yt_html_embed(yt_url):
|
32 |
video_id = yt_url.split("?v=")[-1]
|
|
|
44 |
except youtube_dl.utils.DownloadError as err:
|
45 |
raise gr.Error(str(err))
|
46 |
|
47 |
+
file_length = info["duration"]
|
48 |
+
if file_length > YT_LENGTH_LIMIT_S:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
yt_length_limit_hms = time.strftime("%HH:%MM:%SS", time.gmtime(YT_LENGTH_LIMIT_S))
|
50 |
+
file_length_hms = time.strftime("%HH:%MM:%SS", time.gmtime(file_length))
|
51 |
raise gr.Error(f"Maximum YouTube length is {yt_length_limit_hms}, got {file_length_hms} YouTube video.")
|
52 |
|
53 |
ydl_opts = {"outtmpl": filename, "format": "worstvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"}
|
|
|
58 |
except youtube_dl.utils.ExtractorError as err:
|
59 |
raise gr.Error(str(err))
|
60 |
|
61 |
+
def yt_transcribe(yt_url, task):
|
|
|
62 |
html_embed_str = _return_yt_html_embed(yt_url)
|
63 |
|
64 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
|
74 |
|
75 |
return html_embed_str, text
|
76 |
|
77 |
+
demo = gr.Blocks(theme="ParityError/Interstellar")
|
|
|
78 |
|
79 |
mf_transcribe = gr.Interface(
|
80 |
fn=transcribe,
|
|
|
84 |
],
|
85 |
outputs="text",
|
86 |
layout="horizontal",
|
87 |
+
theme="ParityError/Interstellar",
|
88 |
title="Whisper Large V3: Transcribe Audio",
|
89 |
description=(
|
90 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
|
|
|
102 |
],
|
103 |
outputs="text",
|
104 |
layout="horizontal",
|
105 |
+
theme="ParityError/Interstellar",
|
106 |
title="Whisper Large V3: Transcribe Audio",
|
107 |
description=(
|
108 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the"
|
|
|
120 |
],
|
121 |
outputs=["html", "text"],
|
122 |
layout="horizontal",
|
123 |
+
theme="ParityError/Interstellar",
|
124 |
title="Whisper Large V3: Transcribe YouTube",
|
125 |
description=(
|
126 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the checkpoint"
|
|
|
133 |
with demo:
|
134 |
gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
135 |
|
136 |
+
demo.launch(enable_queue=True)
|