Spaces:
Sleeping
Sleeping
DeepLearning101
commited on
Commit
•
1b51c36
1
Parent(s):
face9e4
Update app.py
Browse files
app.py
CHANGED
@@ -45,22 +45,15 @@ def download_yt_audio(yt_url, filename):
|
|
45 |
except youtube_dl.utils.DownloadError as err:
|
46 |
raise gr.Error(str(err))
|
47 |
|
48 |
-
file_length = info["
|
49 |
-
|
50 |
-
file_h_m_s = [int(sub_length) for sub_length in file_h_m_s]
|
51 |
-
|
52 |
-
if len(file_h_m_s) == 1:
|
53 |
-
file_h_m_s.insert(0, 0)
|
54 |
-
if len(file_h_m_s) == 2:
|
55 |
-
file_h_m_s.insert(0, 0)
|
56 |
-
file_length_s = file_h_m_s[0] * 3600 + file_h_m_s[1] * 60 + file_h_m_s[2]
|
57 |
|
58 |
if file_length_s > YT_LENGTH_LIMIT_S:
|
59 |
-
yt_length_limit_hms = time.strftime("%
|
60 |
-
file_length_hms = time.strftime("%
|
61 |
raise gr.Error(f"Maximum YouTube length is {yt_length_limit_hms}, got {file_length_hms} YouTube video.")
|
62 |
|
63 |
-
ydl_opts = {"outtmpl": filename, "format": "
|
64 |
|
65 |
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
66 |
try:
|
@@ -72,7 +65,7 @@ def yt_transcribe(yt_url, task, max_filesize=75.0):
|
|
72 |
html_embed_str = _return_yt_html_embed(yt_url)
|
73 |
|
74 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
75 |
-
filepath = os.path.join(tmpdirname, "
|
76 |
download_yt_audio(yt_url, filepath)
|
77 |
with open(filepath, "rb") as f:
|
78 |
inputs = f.read()
|
@@ -105,7 +98,7 @@ mf_transcribe = gr.Interface(
|
|
105 |
file_transcribe = gr.Interface(
|
106 |
fn=transcribe,
|
107 |
inputs=[
|
108 |
-
gr.Audio(
|
109 |
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
110 |
],
|
111 |
outputs="text",
|
@@ -141,4 +134,4 @@ yt_transcribe = gr.Interface(
|
|
141 |
with gr.Blocks() as demo:
|
142 |
gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
143 |
|
144 |
-
demo.launch(enable_queue=True)
|
|
|
45 |
except youtube_dl.utils.DownloadError as err:
|
46 |
raise gr.Error(str(err))
|
47 |
|
48 |
+
file_length = info["duration"]
|
49 |
+
file_length_s = int(file_length)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
if file_length_s > YT_LENGTH_LIMIT_S:
|
52 |
+
yt_length_limit_hms = time.strftime("%H:%M:%S", time.gmtime(YT_LENGTH_LIMIT_S))
|
53 |
+
file_length_hms = time.strftime("%H:%M:%S", time.gmtime(file_length_s))
|
54 |
raise gr.Error(f"Maximum YouTube length is {yt_length_limit_hms}, got {file_length_hms} YouTube video.")
|
55 |
|
56 |
+
ydl_opts = {"outtmpl": filename, "format": "bestaudio/best"}
|
57 |
|
58 |
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
59 |
try:
|
|
|
65 |
html_embed_str = _return_yt_html_embed(yt_url)
|
66 |
|
67 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
68 |
+
filepath = os.path.join(tmpdirname, "audio.m4a")
|
69 |
download_yt_audio(yt_url, filepath)
|
70 |
with open(filepath, "rb") as f:
|
71 |
inputs = f.read()
|
|
|
98 |
file_transcribe = gr.Interface(
|
99 |
fn=transcribe,
|
100 |
inputs=[
|
101 |
+
gr.Audio(type="filepath", optional=True, label="Audio file"),
|
102 |
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
103 |
],
|
104 |
outputs="text",
|
|
|
134 |
with gr.Blocks() as demo:
|
135 |
gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
136 |
|
137 |
+
demo.launch(enable_queue=True)
|