Update app.py
Browse files
app.py
CHANGED
@@ -213,6 +213,7 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
213 |
max_video_retries_per_image = 2
|
214 |
video_generated = False
|
215 |
|
|
|
216 |
try:
|
217 |
yield (60, f"Filming a viral video for {user_input}... 🎥")
|
218 |
video_prompt = f"""
|
@@ -220,6 +221,7 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
220 |
Use a close-up shot with a slow dolly shot circling around the subject,
|
221 |
using shallow focus on the main subject to emphasize details, in a realistic style with cinematic lighting.
|
222 |
"""
|
|
|
223 |
operation = client.models.generate_videos(
|
224 |
model="veo-2.0-generate-001",
|
225 |
prompt=video_prompt,
|
@@ -235,9 +237,10 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
235 |
time.sleep(20)
|
236 |
operation = client.operations.get(operation)
|
237 |
|
|
|
238 |
if operation.error:
|
239 |
raise ValueError(f"Video generation failed: {operation.error.message}")
|
240 |
-
if operation.response is None or not hasattr(operation.response, 'generated_videos'):
|
241 |
raise ValueError("Video generation failed: No generated_videos in response")
|
242 |
|
243 |
if len(operation.response.generated_videos) > 0:
|
@@ -261,10 +264,13 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
261 |
'video_base64': video_base64,
|
262 |
'ideas': ideas
|
263 |
}
|
|
|
|
|
264 |
except Exception as e:
|
265 |
print(f"Error generating video (image-to-video): {e}")
|
266 |
yield (70, f"Switching to a new video approach for {user_input}... 🎞️")
|
267 |
|
|
|
268 |
if not video_generated:
|
269 |
for video_attempt in range(max_video_retries_per_image):
|
270 |
try:
|
@@ -278,6 +284,7 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
278 |
The user concept is "{user_input}". Based on this and a simplified scene: {image_prompt}, create a video.
|
279 |
Use a static close-up shot of the subject in a realistic style.
|
280 |
"""
|
|
|
281 |
operation = client.models.generate_videos(
|
282 |
model="veo-2.0-generate-001",
|
283 |
prompt=video_prompt,
|
@@ -292,9 +299,10 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
292 |
time.sleep(20)
|
293 |
operation = client.operations.get(operation)
|
294 |
|
|
|
295 |
if operation.error:
|
296 |
raise ValueError(f"Video generation failed: {operation.error.message}")
|
297 |
-
if operation.response is None or not hasattr(operation.response, 'generated_videos'):
|
298 |
raise ValueError("Video generation failed: No generated_videos in response")
|
299 |
|
300 |
if len(operation.response.generated_videos) > 0:
|
@@ -318,6 +326,8 @@ def generate_item(user_input, ideas, generate_video=False, max_retries=3):
|
|
318 |
'video_base64': video_base64,
|
319 |
'ideas': ideas
|
320 |
}
|
|
|
|
|
321 |
except Exception as e:
|
322 |
print(f"Error generating video (text-to-video attempt {video_attempt + 1}): {e}")
|
323 |
if video_attempt == max_video_retries_per_image - 1:
|
@@ -626,7 +636,7 @@ def generate_share_links(image_base64, video_base64, caption):
|
|
626 |
text-decoration: none;
|
627 |
font-size: 14px;
|
628 |
font-weight: bold;
|
629 |
-
|
630 |
" onmouseover="this.style.backgroundColor='#45a049'" onmouseout="this.style.backgroundColor='#4CAF50'">Download Video</a>
|
631 |
"""
|
632 |
download_links += "</div>"
|
|
|
213 |
max_video_retries_per_image = 2
|
214 |
video_generated = False
|
215 |
|
216 |
+
# Image-to-video generation
|
217 |
try:
|
218 |
yield (60, f"Filming a viral video for {user_input}... 🎥")
|
219 |
video_prompt = f"""
|
|
|
221 |
Use a close-up shot with a slow dolly shot circling around the subject,
|
222 |
using shallow focus on the main subject to emphasize details, in a realistic style with cinematic lighting.
|
223 |
"""
|
224 |
+
print(f"Attempting image-to-video generation: {video_prompt}")
|
225 |
operation = client.models.generate_videos(
|
226 |
model="veo-2.0-generate-001",
|
227 |
prompt=video_prompt,
|
|
|
237 |
time.sleep(20)
|
238 |
operation = client.operations.get(operation)
|
239 |
|
240 |
+
print(f"Image-to-video operation: done={operation.done}, error={operation.error}, response={operation.response}")
|
241 |
if operation.error:
|
242 |
raise ValueError(f"Video generation failed: {operation.error.message}")
|
243 |
+
if operation.response is None or not hasattr(operation.response, 'generated_videos') or operation.response.generated_videos is None:
|
244 |
raise ValueError("Video generation failed: No generated_videos in response")
|
245 |
|
246 |
if len(operation.response.generated_videos) > 0:
|
|
|
264 |
'video_base64': video_base64,
|
265 |
'ideas': ideas
|
266 |
}
|
267 |
+
else:
|
268 |
+
raise ValueError("No video was generated")
|
269 |
except Exception as e:
|
270 |
print(f"Error generating video (image-to-video): {e}")
|
271 |
yield (70, f"Switching to a new video approach for {user_input}... 🎞️")
|
272 |
|
273 |
+
# Text-to-video generation (fallback)
|
274 |
if not video_generated:
|
275 |
for video_attempt in range(max_video_retries_per_image):
|
276 |
try:
|
|
|
284 |
The user concept is "{user_input}". Based on this and a simplified scene: {image_prompt}, create a video.
|
285 |
Use a static close-up shot of the subject in a realistic style.
|
286 |
"""
|
287 |
+
print(f"Attempting text-to-video generation (attempt {video_attempt + 1}): {video_prompt}")
|
288 |
operation = client.models.generate_videos(
|
289 |
model="veo-2.0-generate-001",
|
290 |
prompt=video_prompt,
|
|
|
299 |
time.sleep(20)
|
300 |
operation = client.operations.get(operation)
|
301 |
|
302 |
+
print(f"Text-to-video operation (attempt {video_attempt + 1}): done={operation.done}, error={operation.error}, response={operation.response}")
|
303 |
if operation.error:
|
304 |
raise ValueError(f"Video generation failed: {operation.error.message}")
|
305 |
+
if operation.response is None or not hasattr(operation.response, 'generated_videos') or operation.response.generated_videos is None:
|
306 |
raise ValueError("Video generation failed: No generated_videos in response")
|
307 |
|
308 |
if len(operation.response.generated_videos) > 0:
|
|
|
326 |
'video_base64': video_base64,
|
327 |
'ideas': ideas
|
328 |
}
|
329 |
+
else:
|
330 |
+
raise ValueError("No video was generated")
|
331 |
except Exception as e:
|
332 |
print(f"Error generating video (text-to-video attempt {video_attempt + 1}): {e}")
|
333 |
if video_attempt == max_video_retries_per_image - 1:
|
|
|
636 |
text-decoration: none;
|
637 |
font-size: 14px;
|
638 |
font-weight: bold;
|
639 |
+
transition: background-color 0.3s;
|
640 |
" onmouseover="this.style.backgroundColor='#45a049'" onmouseout="this.style.backgroundColor='#4CAF50'">Download Video</a>
|
641 |
"""
|
642 |
download_links += "</div>"
|