Hermit11 commited on
Commit
88d4b20
·
verified ·
1 Parent(s): 7f2ec35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  import requests
3
 
4
- # FastAPI backend URL
5
  BACKEND_URL = "http://localhost:8080/combine_videos"
6
 
7
  def add_url(url_list, new_url):
@@ -9,41 +8,44 @@ def add_url(url_list, new_url):
9
  url_list.append(new_url.strip())
10
  return "\n".join(url_list), ""
11
 
 
 
 
12
  def combine_videos(url_list):
13
- urls = url_list.split("\n")
 
 
 
14
  try:
15
- response = requests.post(BACKEND_URL, json={"urls": urls})
16
  response.raise_for_status()
17
  video_path = response.json()["video_path"]
18
- return video_path, gr.update(interactive=True)
19
  except requests.RequestException as e:
20
  error_message = f"Error: {str(e)}"
21
- if response.status_code != 200:
22
- error_message += f"\nServer response: {response.text}"
23
- return error_message, gr.update(interactive=False)
24
-
25
- def download_video(video_path):
26
- return video_path if video_path and not video_path.startswith("Error:") else None
27
 
28
  with gr.Blocks() as demo:
29
- gr.Markdown("# KSL Video Combiner")
30
 
31
  with gr.Row():
32
  url_input = gr.Textbox(label="Enter a video URL")
33
  add_button = gr.Button("Add URL")
 
34
 
35
  url_list = gr.Textbox(label="Added URLs", lines=5)
36
  combine_button = gr.Button("Combine Videos")
37
 
 
38
  video_output = gr.Video(label="Combined Video")
39
- download_button = gr.Button("Download Video", interactive=False)
40
 
41
  url_list_state = gr.State([])
42
 
43
  add_button.click(add_url, inputs=[url_list_state, url_input], outputs=[url_list, url_input])
44
- combine_button.click(combine_videos, inputs=[url_list], outputs=[video_output, download_button])
45
-
46
- download_button.click(download_video, inputs=[video_output], outputs=[gr.File()])
47
 
48
  if __name__ == "__main__":
49
  demo.launch(share=True)
 
1
  import gradio as gr
2
  import requests
3
 
 
4
  BACKEND_URL = "http://localhost:8080/combine_videos"
5
 
6
  def add_url(url_list, new_url):
 
8
  url_list.append(new_url.strip())
9
  return "\n".join(url_list), ""
10
 
11
+ def clear_urls(url_list):
12
+ return "", []
13
+
14
  def combine_videos(url_list):
15
+ urls = [url for url in url_list.split("\n") if url.strip()]
16
+ if not urls:
17
+ return "Error: No URLs provided", gr.update(visible=False), ""
18
+
19
  try:
20
+ response = requests.post(BACKEND_URL, json={"urls": urls}, timeout=300) # 5-minute timeout
21
  response.raise_for_status()
22
  video_path = response.json()["video_path"]
23
+ return f"Video combined successfully. Path: {video_path}", gr.update(visible=True), video_path
24
  except requests.RequestException as e:
25
  error_message = f"Error: {str(e)}"
26
+ if hasattr(e, 'response') and e.response is not None:
27
+ error_message += f"\nServer response: {e.response.text}"
28
+ return error_message, gr.update(visible=False), ""
 
 
 
29
 
30
  with gr.Blocks() as demo:
31
+ gr.Markdown("# Video Combiner")
32
 
33
  with gr.Row():
34
  url_input = gr.Textbox(label="Enter a video URL")
35
  add_button = gr.Button("Add URL")
36
+ clear_button = gr.Button("Clear URLs")
37
 
38
  url_list = gr.Textbox(label="Added URLs", lines=5)
39
  combine_button = gr.Button("Combine Videos")
40
 
41
+ output_text = gr.Textbox(label="Output")
42
  video_output = gr.Video(label="Combined Video")
 
43
 
44
  url_list_state = gr.State([])
45
 
46
  add_button.click(add_url, inputs=[url_list_state, url_input], outputs=[url_list, url_input])
47
+ clear_button.click(clear_urls, inputs=[url_list_state], outputs=[url_list, url_list_state])
48
+ combine_button.click(combine_videos, inputs=[url_list], outputs=[output_text, video_output, video_output])
 
49
 
50
  if __name__ == "__main__":
51
  demo.launch(share=True)