Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -167,10 +167,11 @@ import torch
|
|
167 |
|
168 |
import gradio as gr
|
169 |
import yt_dlp as youtube_dl
|
170 |
-
|
|
|
|
|
171 |
from transformers import pipeline
|
172 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
173 |
-
import pytube
|
174 |
|
175 |
import tempfile
|
176 |
import os
|
@@ -190,7 +191,7 @@ pipe = pipeline(
|
|
190 |
)
|
191 |
|
192 |
|
193 |
-
@spaces.GPU
|
194 |
def transcribe(inputs, task="transcribe"):
|
195 |
if inputs is None:
|
196 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
@@ -264,15 +265,20 @@ def yt_transcribe(yt_url, task="transcribe", progress=gr.Progress(), max_filesiz
|
|
264 |
progress(0, desc="Loading audio file...")
|
265 |
html_embed_str = _return_yt_html_embed(yt_url)
|
266 |
try:
|
267 |
-
yt = pytube.YouTube(yt_url)
|
268 |
-
stream = yt.streams.filter(only_audio=True)[0]
|
|
|
|
|
|
|
|
|
269 |
except:
|
270 |
raise gr.Error("An error occurred while loading the YouTube video. Please try again.")
|
271 |
|
272 |
if stream.filesize_mb > max_filesize:
|
273 |
raise gr.Error(f"Maximum YouTube file size is {max_filesize}MB, got {stream.filesize_mb:.2f}MB.")
|
274 |
|
275 |
-
stream.download(filename="audio.mp3")
|
|
|
276 |
|
277 |
with open("audio.mp3", "rb") as f:
|
278 |
inputs = f.read()
|
|
|
167 |
|
168 |
import gradio as gr
|
169 |
import yt_dlp as youtube_dl
|
170 |
+
from pytubefix import YouTube
|
171 |
+
from pytubefix.cli import on_progress
|
172 |
+
|
173 |
from transformers import pipeline
|
174 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
|
|
175 |
|
176 |
import tempfile
|
177 |
import os
|
|
|
191 |
)
|
192 |
|
193 |
|
194 |
+
# @spaces.GPU
|
195 |
def transcribe(inputs, task="transcribe"):
|
196 |
if inputs is None:
|
197 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
|
|
265 |
progress(0, desc="Loading audio file...")
|
266 |
html_embed_str = _return_yt_html_embed(yt_url)
|
267 |
try:
|
268 |
+
# yt = pytube.YouTube(yt_url)
|
269 |
+
# stream = yt.streams.filter(only_audio=True)[0]
|
270 |
+
yt = YouTube(yt_url, on_progress_callback = on_progress)
|
271 |
+
|
272 |
+
stream = yt.streams.get_audio_only()
|
273 |
+
|
274 |
except:
|
275 |
raise gr.Error("An error occurred while loading the YouTube video. Please try again.")
|
276 |
|
277 |
if stream.filesize_mb > max_filesize:
|
278 |
raise gr.Error(f"Maximum YouTube file size is {max_filesize}MB, got {stream.filesize_mb:.2f}MB.")
|
279 |
|
280 |
+
# stream.download(filename="audio.mp3")
|
281 |
+
stream.download(filename="audio.mp3", mp3=True)
|
282 |
|
283 |
with open("audio.mp3", "rb") as f:
|
284 |
inputs = f.read()
|