Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,12 +47,10 @@ def generate_video(image, prompt=""):
|
|
| 47 |
}
|
| 48 |
|
| 49 |
payload = {
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
{"name": "aspect_ratio", "value": "16:9"}
|
| 55 |
-
]
|
| 56 |
}
|
| 57 |
|
| 58 |
try:
|
|
@@ -60,7 +58,7 @@ def generate_video(image, prompt=""):
|
|
| 60 |
response.raise_for_status()
|
| 61 |
|
| 62 |
data = response.json()
|
| 63 |
-
task_id = data.get("
|
| 64 |
if not task_id:
|
| 65 |
return "Error: No task ID returned by the API."
|
| 66 |
|
|
@@ -70,8 +68,8 @@ def generate_video(image, prompt=""):
|
|
| 70 |
status_response = requests.get(status_url, headers=headers, timeout=30)
|
| 71 |
status_response.raise_for_status()
|
| 72 |
status_data = status_response.json()
|
| 73 |
-
if status_data.get("status") == "
|
| 74 |
-
video_url = status_data.get("
|
| 75 |
if not video_url:
|
| 76 |
return "Error: No video URL in API response."
|
| 77 |
# Download the video
|
|
@@ -87,12 +85,14 @@ def generate_video(image, prompt=""):
|
|
| 87 |
|
| 88 |
return "Error: Video generation timed out."
|
| 89 |
|
| 90 |
-
except requests.exceptions.
|
| 91 |
return f"Error: API request failed. Details: {str(e)}"
|
|
|
|
|
|
|
| 92 |
|
| 93 |
def chatbot_interface(image, prompt):
|
| 94 |
"""
|
| 95 |
-
Gradio interface for image-to-
|
| 96 |
|
| 97 |
Args:
|
| 98 |
image: Uploaded image file
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
payload = {
|
| 50 |
+
"image": image_base64,
|
| 51 |
+
"prompt": prompt,
|
| 52 |
+
"duration": 5,
|
| 53 |
+
"aspect_ratio": "16:9"
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
try:
|
|
|
|
| 58 |
response.raise_for_status()
|
| 59 |
|
| 60 |
data = response.json()
|
| 61 |
+
task_id = data.get("task_id") or data.get("taskId")
|
| 62 |
if not task_id:
|
| 63 |
return "Error: No task ID returned by the API."
|
| 64 |
|
|
|
|
| 68 |
status_response = requests.get(status_url, headers=headers, timeout=30)
|
| 69 |
status_response.raise_for_status()
|
| 70 |
status_data = status_response.json()
|
| 71 |
+
if status_data.get("status") == "succeeded":
|
| 72 |
+
video_url = status_data.get("video_url") or status_data.get("result", {}).get("video_url")
|
| 73 |
if not video_url:
|
| 74 |
return "Error: No video URL in API response."
|
| 75 |
# Download the video
|
|
|
|
| 85 |
|
| 86 |
return "Error: Video generation timed out."
|
| 87 |
|
| 88 |
+
except requests.exceptions.HTTPError as e:
|
| 89 |
return f"Error: API request failed. Details: {str(e)}"
|
| 90 |
+
except requests.exceptions.RequestException as e:
|
| 91 |
+
return f"Error: Network issue. Details: {str(e)}"
|
| 92 |
|
| 93 |
def chatbot_interface(image, prompt):
|
| 94 |
"""
|
| 95 |
+
Gradio interface for image-to-video generation.
|
| 96 |
|
| 97 |
Args:
|
| 98 |
image: Uploaded image file
|