Update app.py
Browse files
app.py
CHANGED
@@ -159,20 +159,38 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
159 |
run_button = gr.Button("π Transcribe Audio", variant="primary", interactive=False)
|
160 |
run_button.click(run_asr, inputs=[audio_input, youtube_input], outputs=[result])
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
)
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
)
|
175 |
|
|
|
176 |
gr.Markdown("### How to use:")
|
177 |
gr.Markdown("1. Upload an audio file or record your voice using the microphone, OR paste a YouTube URL.")
|
178 |
gr.Markdown("2. If you paste a YouTube URL, the video will be displayed for your reference, and any previous transcription or audio input will be cleared.")
|
|
|
159 |
run_button = gr.Button("π Transcribe Audio", variant="primary", interactive=False)
|
160 |
run_button.click(run_asr, inputs=[audio_input, youtube_input], outputs=[result])
|
161 |
|
162 |
+
def update_button_state(audio, youtube_url):
|
163 |
+
print(audio, youtube_url, progress)
|
164 |
+
# Button is interactive if there's input and progress is 0 or 1 (not in progress)
|
165 |
+
return gr.Button(interactive=bool(audio) or bool(youtube_url))
|
166 |
+
|
167 |
+
user_audio_input.change(
|
168 |
+
fn=update_button_state,
|
169 |
+
inputs=[audio_input, youtube_input],
|
170 |
+
outputs=run_button
|
171 |
+
)
|
172 |
+
user_youtube_url.change(
|
173 |
+
fn=update_button_state,
|
174 |
+
inputs=[audio_input, youtube_input],
|
175 |
+
outputs=run_button
|
176 |
)
|
177 |
|
178 |
+
async def update_video_embed(youtube_url):
|
179 |
+
if youtube_url:
|
180 |
+
try:
|
181 |
+
video_id = await fetch_youtube_id(youtube_url)
|
182 |
+
return f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'
|
183 |
+
except Exception as e:
|
184 |
+
print(f"Error embedding video: {e}")
|
185 |
+
return ""
|
186 |
+
|
187 |
+
user_youtube_url.change(
|
188 |
+
fn=update_video_embed,
|
189 |
+
inputs=[youtube_input],
|
190 |
+
outputs=[video_player]
|
191 |
)
|
192 |
|
193 |
+
|
194 |
gr.Markdown("### How to use:")
|
195 |
gr.Markdown("1. Upload an audio file or record your voice using the microphone, OR paste a YouTube URL.")
|
196 |
gr.Markdown("2. If you paste a YouTube URL, the video will be displayed for your reference, and any previous transcription or audio input will be cleared.")
|