jerrypan7 commited on
Commit
12e73ad
Β·
verified Β·
1 Parent(s): 752e757

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
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
- # Update video player, clear transcription and audio input, and enable run button when YouTube URL is entered
163
- youtube_input.change(
164
- fn=lambda url: (*embed_youtube(url), gr.update(interactive=bool(url))),
165
- inputs=[youtube_input],
166
- outputs=[video_player, result, audio_input, run_button]
 
 
 
 
 
 
 
 
 
167
  )
168
 
169
- # Clear transcription, YouTube input, video player, and update run button when audio is input
170
- audio_input.change(
171
- fn=clear_on_audio_input,
172
- inputs=[audio_input],
173
- outputs=[result, video_player, youtube_input, run_button]
 
 
 
 
 
 
 
 
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.")