Update app.py
Browse files
app.py
CHANGED
|
@@ -249,18 +249,23 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
| 249 |
operation = client.operations.get(operation)
|
| 250 |
if operation.error:
|
| 251 |
raise ValueError(f"Video generation failed: {operation.error.message}")
|
| 252 |
-
if operation.response and
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
except Exception as e:
|
| 265 |
print(f"Error generating video: {e}")
|
| 266 |
yield {"stage": "generating_video", "message": random.choice(PROGRESS_STAGES["generating_video"]), "progress": 80}
|
|
@@ -278,18 +283,25 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
| 278 |
while not operation.done:
|
| 279 |
time.sleep(20)
|
| 280 |
operation = client.operations.get(operation)
|
| 281 |
-
if operation.
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
except Exception as e:
|
| 294 |
print(f"Error generating text-to-video: {e}")
|
| 295 |
if total_attempts == max_total_attempts:
|
|
@@ -525,7 +537,7 @@ def generate_share_links(image_base64, video_base64, caption):
|
|
| 525 |
font-size: 14px;
|
| 526 |
font-weight: bold;
|
| 527 |
transition: background-color 0.3s;
|
| 528 |
-
" onmouseover="this
|
| 529 |
<a href="https://www.instagram.com/?caption={caption}" target="_blank" style="
|
| 530 |
background-color: #e1306c;
|
| 531 |
color: white;
|
|
@@ -809,7 +821,7 @@ with gr.Blocks(
|
|
| 809 |
label="Generate Video (may take longer)",
|
| 810 |
value=False
|
| 811 |
)
|
| 812 |
-
magic_button = gr.Button("✨
|
| 813 |
|
| 814 |
feed_html = gr.HTML()
|
| 815 |
share_html = gr.HTML(label="Share this item:")
|
|
|
|
| 249 |
operation = client.operations.get(operation)
|
| 250 |
if operation.error:
|
| 251 |
raise ValueError(f"Video generation failed: {operation.error.message}")
|
| 252 |
+
if operation.response and hasattr(operation.response, 'generated_videos') and operation.response.generated_videos:
|
| 253 |
+
if len(operation.response.generated_videos) > 0:
|
| 254 |
+
video = operation.response.generated_videos[0]
|
| 255 |
+
if video and hasattr(video, 'video'):
|
| 256 |
+
video_data = client.files.download(file=video.video)
|
| 257 |
+
video_bytes = video_data if isinstance(video_data, bytes) else BytesIO(video_data).getvalue()
|
| 258 |
+
video_base64 = base64.b64encode(video_bytes).decode()
|
| 259 |
+
yield {"stage": "finalizing", "message": random.choice(PROGRESS_STAGES["finalizing"]), "progress": 90}
|
| 260 |
+
return {
|
| 261 |
+
'text': text,
|
| 262 |
+
'image_base64': img_str,
|
| 263 |
+
'video_base64': video_base64,
|
| 264 |
+
'ideas': ideas
|
| 265 |
+
}
|
| 266 |
+
raise ValueError("No valid video generated")
|
| 267 |
+
else:
|
| 268 |
+
raise ValueError("Video generation operation failed: No generated_videos in response")
|
| 269 |
except Exception as e:
|
| 270 |
print(f"Error generating video: {e}")
|
| 271 |
yield {"stage": "generating_video", "message": random.choice(PROGRESS_STAGES["generating_video"]), "progress": 80}
|
|
|
|
| 283 |
while not operation.done:
|
| 284 |
time.sleep(20)
|
| 285 |
operation = client.operations.get(operation)
|
| 286 |
+
if operation.error:
|
| 287 |
+
raise ValueError(f"Video generation failed: {operation.error.message}")
|
| 288 |
+
if operation.response and hasattr(operation.response, 'generated_videos') and operation.response.generated_videos:
|
| 289 |
+
if len(operation.response.generated_videos) > 0:
|
| 290 |
+
video = operation.response.generated_videos[0]
|
| 291 |
+
if video and hasattr(video, 'video'):
|
| 292 |
+
video_data = client.files.download(file=video.video)
|
| 293 |
+
video_bytes = video_data if isinstance(video_data, bytes) else BytesIO(video_data).getvalue()
|
| 294 |
+
video_base64 = base64.b64encode(video_bytes).decode()
|
| 295 |
+
yield {"stage": "finalizing", "message": random.choice(PROGRESS_STAGES["finalizing"]), "progress": 90}
|
| 296 |
+
return {
|
| 297 |
+
'text': text,
|
| 298 |
+
'image_base64': img_str,
|
| 299 |
+
'video_base64': video_base64,
|
| 300 |
+
'ideas': ideas
|
| 301 |
+
}
|
| 302 |
+
raise ValueError("No valid video generated")
|
| 303 |
+
else:
|
| 304 |
+
raise ValueError("Video generation operation failed: No generated_videos in response")
|
| 305 |
except Exception as e:
|
| 306 |
print(f"Error generating text-to-video: {e}")
|
| 307 |
if total_attempts == max_total_attempts:
|
|
|
|
| 537 |
font-size: 14px;
|
| 538 |
font-weight: bold;
|
| 539 |
transition: background-color 0.3s;
|
| 540 |
+
" onmouseover="this.style.backgroundColor='#00d9d1'" onmouseout="this.style.backgroundColor='#00f2ea'">Share on TikTok</a>
|
| 541 |
<a href="https://www.instagram.com/?caption={caption}" target="_blank" style="
|
| 542 |
background-color: #e1306c;
|
| 543 |
color: white;
|
|
|
|
| 821 |
label="Generate Video (may take longer)",
|
| 822 |
value=False
|
| 823 |
)
|
| 824 |
+
magic_button = gr.Button("✨ Create ✨", elem_classes="gr-button")
|
| 825 |
|
| 826 |
feed_html = gr.HTML()
|
| 827 |
share_html = gr.HTML(label="Share this item:")
|