Spaces:
Runtime error
Runtime error
Update run.py
Browse files
run.py
CHANGED
@@ -27,17 +27,17 @@ def download_youtube(url, file_format):
|
|
27 |
if file_format == "audio":
|
28 |
file_path = os.path.splitext(file_path)[0] + ".mp3"
|
29 |
|
30 |
-
return file_path
|
31 |
except Exception as e:
|
32 |
-
return str(e)
|
33 |
|
34 |
-
def show_output(file_path):
|
35 |
-
if
|
36 |
-
return
|
37 |
if file_path.endswith(".mp3"):
|
38 |
-
return None, gr.Audio(file_path,
|
39 |
else:
|
40 |
-
return None,
|
41 |
|
42 |
with gr.Blocks() as demo:
|
43 |
with gr.Row():
|
@@ -50,8 +50,8 @@ with gr.Blocks() as demo:
|
|
50 |
audio_output = gr.Audio(label="Audio Output", visible=False)
|
51 |
video_output = gr.Video(label="Video Output", visible=False)
|
52 |
|
53 |
-
download_button.click(download_youtube, inputs=[url_input, format_input], outputs=
|
54 |
-
show_output, inputs=
|
55 |
)
|
56 |
|
57 |
demo.launch()
|
|
|
27 |
if file_format == "audio":
|
28 |
file_path = os.path.splitext(file_path)[0] + ".mp3"
|
29 |
|
30 |
+
return file_path, None
|
31 |
except Exception as e:
|
32 |
+
return None, str(e)
|
33 |
|
34 |
+
def show_output(file_path, error):
|
35 |
+
if error:
|
36 |
+
return error, None, None
|
37 |
if file_path.endswith(".mp3"):
|
38 |
+
return None, gr.Audio.update(value=file_path, visible=True), gr.Video.update(visible=False)
|
39 |
else:
|
40 |
+
return None, gr.Audio.update(visible=False), gr.Video.update(value=file_path, visible=True)
|
41 |
|
42 |
with gr.Blocks() as demo:
|
43 |
with gr.Row():
|
|
|
50 |
audio_output = gr.Audio(label="Audio Output", visible=False)
|
51 |
video_output = gr.Video(label="Video Output", visible=False)
|
52 |
|
53 |
+
download_button.click(download_youtube, inputs=[url_input, format_input], outputs=[error_output, audio_output, video_output]).then(
|
54 |
+
show_output, inputs=[error_output, audio_output], outputs=[error_output, audio_output, video_output]
|
55 |
)
|
56 |
|
57 |
demo.launch()
|