Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import os
|
3 |
from lumaai import LumaAI
|
4 |
import requests
|
|
|
5 |
|
6 |
def generate_content(api_key, prompt, aspect_ratio, loop):
|
7 |
"""
|
@@ -32,11 +33,18 @@ def generate_content(api_key, prompt, aspect_ratio, loop):
|
|
32 |
generation_id = generation.id
|
33 |
video_url = None
|
34 |
|
35 |
-
# Poll until the video is ready
|
36 |
-
|
|
|
|
|
|
|
37 |
generation_status = client.generations.get(id=generation_id)
|
38 |
video_url = generation_status.assets.get('video', None)
|
|
|
|
|
39 |
|
|
|
|
|
40 |
return video_url
|
41 |
except Exception as e:
|
42 |
return f"An error occurred: {str(e)}"
|
|
|
2 |
import os
|
3 |
from lumaai import LumaAI
|
4 |
import requests
|
5 |
+
import time
|
6 |
|
7 |
def generate_content(api_key, prompt, aspect_ratio, loop):
|
8 |
"""
|
|
|
33 |
generation_id = generation.id
|
34 |
video_url = None
|
35 |
|
36 |
+
# Poll until the video is ready (adding a timeout of 60 seconds max)
|
37 |
+
timeout = 60 # seconds
|
38 |
+
start_time = time.time()
|
39 |
+
|
40 |
+
while video_url is None and time.time() - start_time < timeout:
|
41 |
generation_status = client.generations.get(id=generation_id)
|
42 |
video_url = generation_status.assets.get('video', None)
|
43 |
+
if video_url is None:
|
44 |
+
time.sleep(5) # Wait for 5 seconds before polling again
|
45 |
|
46 |
+
if video_url is None:
|
47 |
+
return "The video generation timed out. Please try again later."
|
48 |
return video_url
|
49 |
except Exception as e:
|
50 |
return f"An error occurred: {str(e)}"
|