Spaces:
Running
Running
gradio 5.4.0
Browse files- README.md +2 -2
- app.py +16 -23
- requirements.txt +1 -1
README.md
CHANGED
@@ -4,9 +4,9 @@ emoji: 🔥
|
|
4 |
colorFrom: pink
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
4 |
colorFrom: pink
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.4.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -41,29 +41,29 @@ def _return_yt_html_embed(yt_url):
|
|
41 |
|
42 |
def download_yt_audio(yt_url, filename):
|
43 |
info_loader = youtube_dl.YoutubeDL()
|
44 |
-
|
45 |
try:
|
46 |
info = info_loader.extract_info(yt_url, download=False)
|
47 |
except youtube_dl.utils.DownloadError as err:
|
48 |
raise gr.Error(str(err))
|
49 |
-
|
50 |
file_length = info["duration_string"]
|
51 |
file_h_m_s = file_length.split(":")
|
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(file_length_s))
|
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"}
|
66 |
-
|
67 |
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
68 |
try:
|
69 |
ydl.download([yt_url])
|
@@ -93,59 +93,52 @@ demo = gr.Blocks()
|
|
93 |
mf_transcribe = gr.Interface(
|
94 |
fn=transcribe,
|
95 |
inputs=[
|
96 |
-
gr.
|
97 |
-
gr.
|
98 |
],
|
99 |
outputs="text",
|
100 |
-
layout="horizontal",
|
101 |
-
theme="huggingface",
|
102 |
title="Whisper Uzbek: Transcribe Audio",
|
103 |
description=(
|
104 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
|
105 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
106 |
" of arbitrary length."
|
107 |
),
|
108 |
-
|
109 |
)
|
110 |
|
111 |
file_transcribe = gr.Interface(
|
112 |
fn=transcribe,
|
113 |
inputs=[
|
114 |
-
gr.
|
115 |
-
gr.
|
116 |
],
|
117 |
outputs="text",
|
118 |
-
layout="horizontal",
|
119 |
-
theme="huggingface",
|
120 |
title="Whisper Uzbek: Transcribe Audio",
|
121 |
description=(
|
122 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
|
123 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
124 |
" of arbitrary length."
|
125 |
),
|
126 |
-
|
127 |
)
|
128 |
|
129 |
yt_transcribe = gr.Interface(
|
130 |
fn=yt_transcribe,
|
131 |
inputs=[
|
132 |
-
gr.
|
133 |
-
gr.
|
134 |
],
|
135 |
outputs=["html", "text"],
|
136 |
-
layout="horizontal",
|
137 |
-
theme="huggingface",
|
138 |
title="Whisper Uzbek: Transcribe YouTube",
|
139 |
description=(
|
140 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the OpenAI Whisper checkpoint"
|
141 |
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
142 |
" arbitrary length."
|
143 |
),
|
144 |
-
|
145 |
)
|
146 |
|
147 |
with demo:
|
148 |
gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
149 |
|
150 |
-
demo.launch(
|
151 |
-
|
|
|
41 |
|
42 |
def download_yt_audio(yt_url, filename):
|
43 |
info_loader = youtube_dl.YoutubeDL()
|
44 |
+
|
45 |
try:
|
46 |
info = info_loader.extract_info(yt_url, download=False)
|
47 |
except youtube_dl.utils.DownloadError as err:
|
48 |
raise gr.Error(str(err))
|
49 |
+
|
50 |
file_length = info["duration_string"]
|
51 |
file_h_m_s = file_length.split(":")
|
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(file_length_s))
|
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"}
|
66 |
+
|
67 |
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
68 |
try:
|
69 |
ydl.download([yt_url])
|
|
|
93 |
mf_transcribe = gr.Interface(
|
94 |
fn=transcribe,
|
95 |
inputs=[
|
96 |
+
gr.Audio(sources=["microphone"], type="filepath"),
|
97 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
98 |
],
|
99 |
outputs="text",
|
|
|
|
|
100 |
title="Whisper Uzbek: Transcribe Audio",
|
101 |
description=(
|
102 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
|
103 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
104 |
" of arbitrary length."
|
105 |
),
|
106 |
+
flagging_mode="never",
|
107 |
)
|
108 |
|
109 |
file_transcribe = gr.Interface(
|
110 |
fn=transcribe,
|
111 |
inputs=[
|
112 |
+
gr.Audio(sources=["upload"], type="filepath", label="Audio file"),
|
113 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe"),
|
114 |
],
|
115 |
outputs="text",
|
|
|
|
|
116 |
title="Whisper Uzbek: Transcribe Audio",
|
117 |
description=(
|
118 |
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
|
119 |
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
|
120 |
" of arbitrary length."
|
121 |
),
|
122 |
+
flagging_mode="never",
|
123 |
)
|
124 |
|
125 |
yt_transcribe = gr.Interface(
|
126 |
fn=yt_transcribe,
|
127 |
inputs=[
|
128 |
+
gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
|
129 |
+
gr.Radio(["transcribe", "translate"], label="Task", value="transcribe")
|
130 |
],
|
131 |
outputs=["html", "text"],
|
|
|
|
|
132 |
title="Whisper Uzbek: Transcribe YouTube",
|
133 |
description=(
|
134 |
"Transcribe long-form YouTube videos with the click of a button! Demo uses the OpenAI Whisper checkpoint"
|
135 |
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe video files of"
|
136 |
" arbitrary length."
|
137 |
),
|
138 |
+
flagging_mode="never",
|
139 |
)
|
140 |
|
141 |
with demo:
|
142 |
gr.TabbedInterface([mf_transcribe, file_transcribe, yt_transcribe], ["Microphone", "Audio file", "YouTube"])
|
143 |
|
144 |
+
demo.launch()
|
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
|
2 |
torch
|
3 |
yt-dlp
|
|
|
1 |
+
transformers
|
2 |
torch
|
3 |
yt-dlp
|