Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,6 @@
|
|
2 |
|
3 |
|
4 |
|
5 |
-
|
6 |
-
def install(package):
|
7 |
-
if hasattr(pip, 'main'):
|
8 |
-
pip.main(['install', package])
|
9 |
-
install("speechbrain")
|
10 |
-
|
11 |
import torch
|
12 |
|
13 |
import gradio as gr
|
@@ -29,95 +23,6 @@ model = separator.from_hparams(source="speechbrain/sepformer-libri2mix", savedir
|
|
29 |
|
30 |
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
# MODEL_NAME = "openai/whisper-large-v3"
|
40 |
-
# BATCH_SIZE = 8
|
41 |
-
# FILE_LIMIT_MB = 1000
|
42 |
-
# YT_LENGTH_LIMIT_S = 3600 # limit to 1 hour YouTube files
|
43 |
-
|
44 |
-
# device = 0 if torch.cuda.is_available() else "cpu"
|
45 |
-
|
46 |
-
# pipe = pipeline(
|
47 |
-
# task="automatic-speech-recognition",
|
48 |
-
# model=MODEL_NAME,
|
49 |
-
# chunk_length_s=30,
|
50 |
-
# device=device,
|
51 |
-
# )
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
# # def transcribe(inputs, task):
|
57 |
-
# # if inputs is None:
|
58 |
-
# # raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
59 |
-
|
60 |
-
# # text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
61 |
-
# # return text
|
62 |
-
|
63 |
-
|
64 |
-
# # def _return_yt_html_embed(yt_url):
|
65 |
-
# # video_id = yt_url.split("?v=")[-1]
|
66 |
-
# # HTML_str = (
|
67 |
-
# # f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
|
68 |
-
# # " </center>"
|
69 |
-
# # )
|
70 |
-
# # return HTML_str
|
71 |
-
|
72 |
-
# # def download_yt_audio(yt_url, filename):
|
73 |
-
# # info_loader = youtube_dl.YoutubeDL()
|
74 |
-
|
75 |
-
# # try:
|
76 |
-
# # info = info_loader.extract_info(yt_url, download=False)
|
77 |
-
# # except youtube_dl.utils.DownloadError as err:
|
78 |
-
# # raise gr.Error(str(err))
|
79 |
-
|
80 |
-
# # file_length = info["duration_string"]
|
81 |
-
# # file_h_m_s = file_length.split(":")
|
82 |
-
# # file_h_m_s = [int(sub_length) for sub_length in file_h_m_s]
|
83 |
-
|
84 |
-
# # if len(file_h_m_s) == 1:
|
85 |
-
# # file_h_m_s.insert(0, 0)
|
86 |
-
# # if len(file_h_m_s) == 2:
|
87 |
-
# # file_h_m_s.insert(0, 0)
|
88 |
-
# # file_length_s = file_h_m_s[0] * 3600 + file_h_m_s[1] * 60 + file_h_m_s[2]
|
89 |
-
|
90 |
-
# # if file_length_s > YT_LENGTH_LIMIT_S:
|
91 |
-
# # yt_length_limit_hms = time.strftime("%HH:%MM:%SS", time.gmtime(YT_LENGTH_LIMIT_S))
|
92 |
-
# # file_length_hms = time.strftime("%HH:%MM:%SS", time.gmtime(file_length_s))
|
93 |
-
# # raise gr.Error(f"Maximum YouTube length is {yt_length_limit_hms}, got {file_length_hms} YouTube video.")
|
94 |
-
|
95 |
-
# # ydl_opts = {"outtmpl": filename, "format": "worstvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"}
|
96 |
-
|
97 |
-
# # with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
98 |
-
# # try:
|
99 |
-
# # ydl.download([yt_url])
|
100 |
-
# # except youtube_dl.utils.ExtractorError as err:
|
101 |
-
# # raise gr.Error(str(err))
|
102 |
-
|
103 |
-
|
104 |
-
# # def yt_transcribe(yt_url, task, max_filesize=75.0):
|
105 |
-
# # html_embed_str = _return_yt_html_embed(yt_url)
|
106 |
-
|
107 |
-
# # with tempfile.TemporaryDirectory() as tmpdirname:
|
108 |
-
# # filepath = os.path.join(tmpdirname, "video.mp4")
|
109 |
-
# # download_yt_audio(yt_url, filepath)
|
110 |
-
# # with open(filepath, "rb") as f:
|
111 |
-
# # inputs = f.read()
|
112 |
-
|
113 |
-
# # inputs = ffmpeg_read(inputs, pipe.feature_extractor.sampling_rate)
|
114 |
-
# # inputs = {"array": inputs, "sampling_rate": pipe.feature_extractor.sampling_rate}
|
115 |
-
|
116 |
-
# # text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
117 |
-
|
118 |
-
# # return html_embed_str, text
|
119 |
-
|
120 |
-
|
121 |
demo = gr.Blocks()
|
122 |
|
123 |
|
@@ -141,62 +46,4 @@ with demo:
|
|
141 |
|
142 |
demo.launch(enable_queue=True)
|
143 |
|
144 |
-
# mf_transcribe = gr.Interface(
|
145 |
-
# fn=transcribe,
|
146 |
-
# inputs=[
|
147 |
-
# gr.inputs.Audio(source="microphone", type="filepath", optional=True),
|
148 |
-
# gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
149 |
-
# ],
|
150 |
-
# outputs="text",
|
151 |
-
# layout="horizontal",
|
152 |
-
# theme="huggingface",
|
153 |
-
# title="Whisper Large V3: Transcribe Audio",
|
154 |
-
# description=(
|
155 |
-
# "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
|
156 |
-
# f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
157 |
-
# " of arbitrary length."
|
158 |
-
# ),
|
159 |
-
# allow_flagging="never",
|
160 |
-
# )
|
161 |
-
|
162 |
-
# file_transcribe = gr.Interface(
|
163 |
-
# fn=transcribe,
|
164 |
-
# inputs=[
|
165 |
-
# gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Audio file"),
|
166 |
-
# gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe"),
|
167 |
-
# ],
|
168 |
-
# outputs="text",
|
169 |
-
# layout="horizontal",
|
170 |
-
# theme="huggingface",
|
171 |
-
# title="Whisper Large V3: Transcribe Audio",
|
172 |
-
# description=(
|
173 |
-
# "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
|
174 |
-
# f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
175 |
-
# " of arbitrary length."
|
176 |
-
# ),
|
177 |
-
# allow_flagging="never",
|
178 |
-
# )
|
179 |
-
|
180 |
-
# yt_transcribe = gr.Interface(
|
181 |
-
# fn=yt_transcribe,
|
182 |
-
# inputs=[
|
183 |
-
# gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
184 |
-
# gr.inputs.Radio(["transcribe", "translate"], label="Task", default="transcribe")
|
185 |
-
# ],
|
186 |
-
# outputs=["html", "text"],
|
187 |
-
# layout="horizontal",
|
188 |
-
# theme="huggingface",
|
189 |
-
# title="Whisper Large V3: Transcribe YouTube",
|
190 |
-
# description=(
|
191 |
-
# "Transcribe long-form YouTube videos with the click of a button! Demo uses the OpenAI Whisper checkpoint"
|
192 |
-
# f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
193 |
-
# " arbitrary length."
|
194 |
-
# ),
|
195 |
-
# allow_flagging="never",
|
196 |
-
# )
|
197 |
-
|
198 |
-
# with demo:
|
199 |
-
# gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
200 |
-
|
201 |
-
# demo.launch(enable_queue=True)
|
202 |
|
|
|
2 |
|
3 |
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import torch
|
6 |
|
7 |
import gradio as gr
|
|
|
23 |
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
demo = gr.Blocks()
|
27 |
|
28 |
|
|
|
46 |
|
47 |
demo.launch(enable_queue=True)
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|