Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,21 +11,37 @@ def add_url(url_list, new_url):
|
|
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 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
@@ -39,13 +55,22 @@ with gr.Blocks() as demo:
|
|
39 |
combine_button = gr.Button("Combine Videos")
|
40 |
|
41 |
output_text = gr.Textbox(label="Output")
|
42 |
-
video_output = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
demo.launch(share=True)
|
|
|
11 |
def clear_urls(url_list):
|
12 |
return "", []
|
13 |
|
14 |
+
def combine_videos(url_list, video_history):
|
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), "", video_history
|
18 |
|
19 |
try:
|
20 |
response = requests.post(BACKEND_URL, json={"urls": urls}, timeout=300) # 5-minute timeout
|
21 |
response.raise_for_status()
|
22 |
+
vimeo_url = response.json()["vimeo_url"]
|
23 |
+
video_id = vimeo_url.split("/")[-1]
|
24 |
+
embed_html = f'<div style="padding:56.25% 0 0 0;position:relative;"><iframe src="https://player.vimeo.com/video/{video_id}?badge=0&autopause=0&player_id=0&app_id=58479" frameborder="0" allow="autoplay; fullscreen; picture-in-picture; clipboard-write" style="position:absolute;top:0;left:0;width:100%;height:100%;" title="Combined Video"></iframe></div><script src="https://player.vimeo.com/api/player.js"></script>'
|
25 |
+
|
26 |
+
# Add the new video to the history
|
27 |
+
video_history.append({"url": vimeo_url, "embed": embed_html})
|
28 |
+
|
29 |
+
return f"Video combined and uploaded successfully. Vimeo URL: {vimeo_url}", gr.update(value=embed_html, visible=True), vimeo_url, video_history
|
30 |
except requests.RequestException as e:
|
31 |
error_message = f"Error: {str(e)}"
|
32 |
if hasattr(e, 'response') and e.response is not None:
|
33 |
error_message += f"\nServer response: {e.response.text}"
|
34 |
+
return error_message, gr.update(visible=False), "", video_history
|
35 |
+
|
36 |
+
def display_video(video_history, index):
|
37 |
+
if 0 <= index < len(video_history):
|
38 |
+
return video_history[index]["embed"], video_history[index]["url"]
|
39 |
+
return "", ""
|
40 |
+
|
41 |
+
def download_video(vimeo_url):
|
42 |
+
if vimeo_url:
|
43 |
+
return vimeo_url
|
44 |
+
return None
|
45 |
|
46 |
with gr.Blocks() as demo:
|
47 |
gr.Markdown("# Video Combiner")
|
|
|
55 |
combine_button = gr.Button("Combine Videos")
|
56 |
|
57 |
output_text = gr.Textbox(label="Output")
|
58 |
+
video_output = gr.HTML(label="Combined Video")
|
59 |
+
vimeo_url_output = gr.Textbox(label="Vimeo URL", interactive=False)
|
60 |
+
|
61 |
+
video_history = gr.State([])
|
62 |
+
video_index = gr.Number(value=0, label="Video Index", interactive=True)
|
63 |
+
|
64 |
+
display_button = gr.Button("Display Video")
|
65 |
+
download_button = gr.Button("Download Video")
|
66 |
|
67 |
url_list_state = gr.State([])
|
68 |
|
69 |
add_button.click(add_url, inputs=[url_list_state, url_input], outputs=[url_list, url_input])
|
70 |
clear_button.click(clear_urls, inputs=[url_list_state], outputs=[url_list, url_list_state])
|
71 |
+
combine_button.click(combine_videos, inputs=[url_list, video_history], outputs=[output_text, video_output, vimeo_url_output, video_history])
|
72 |
+
display_button.click(display_video, inputs=[video_history, video_index], outputs=[video_output, vimeo_url_output])
|
73 |
+
download_button.click(download_video, inputs=[vimeo_url_output], outputs=[gr.File()])
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
demo.launch(share=True)
|