Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,49 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import requests
|
3 |
-
|
4 |
-
# FastAPI backend URL
|
5 |
-
BACKEND_URL = "http://localhost:
|
6 |
-
|
7 |
-
def add_url(url_list, new_url):
|
8 |
-
if new_url.strip():
|
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()
|
|
|
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):
|
8 |
+
if new_url.strip():
|
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)
|