Hev832 commited on
Commit
ee31586
·
verified ·
1 Parent(s): 62bd18f

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +9 -9
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 not file_path or not os.path.exists(file_path):
36
- return "Error downloading file.", None, None
37
  if file_path.endswith(".mp3"):
38
- return None, gr.Audio(file_path, label="Audio Output"), None
39
  else:
40
- return None, None, gr.Video(file_path, label="Video Output")
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=None).then(
54
- show_output, inputs=None, outputs=[error_output, audio_output, video_output]
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()