Spaces:
Sleeping
Sleeping
再試
Browse files- image_examples.py +6 -2
image_examples.py
CHANGED
|
@@ -9,6 +9,7 @@ from flask import Flask, abort, request, send_from_directory
|
|
| 9 |
from google import genai
|
| 10 |
from google.genai import types
|
| 11 |
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
|
|
|
|
| 12 |
|
| 13 |
from linebot.v3 import WebhookHandler
|
| 14 |
from linebot.v3.exceptions import InvalidSignatureError
|
|
@@ -240,13 +241,16 @@ def generate_video_from_image(image_path):
|
|
| 240 |
with open(image_path, "rb") as f:
|
| 241 |
img_bytes = f.read()
|
| 242 |
|
|
|
|
|
|
|
|
|
|
| 243 |
prompt = "請根據這張圖片生成一段有創意的短影片,內容需與圖片主題高度相關。"
|
| 244 |
|
| 245 |
-
# 呼叫 Veo
|
| 246 |
operation = client.models.generate_videos(
|
| 247 |
model="veo-2.0-generate-001",
|
| 248 |
prompt=prompt,
|
| 249 |
-
image=
|
| 250 |
config=types.GenerateVideosConfig(
|
| 251 |
person_generation="dont_allow",
|
| 252 |
aspect_ratio="16:9",
|
|
|
|
| 9 |
from google import genai
|
| 10 |
from google.genai import types
|
| 11 |
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
|
| 12 |
+
from google.genai.types import Image as GeminiImage
|
| 13 |
|
| 14 |
from linebot.v3 import WebhookHandler
|
| 15 |
from linebot.v3.exceptions import InvalidSignatureError
|
|
|
|
| 241 |
with open(image_path, "rb") as f:
|
| 242 |
img_bytes = f.read()
|
| 243 |
|
| 244 |
+
# 用 Gemini SDK 的 Image 物件包裝
|
| 245 |
+
gemini_image = GeminiImage(data=img_bytes, mime_type="image/jpeg")
|
| 246 |
+
|
| 247 |
prompt = "請根據這張圖片生成一段有創意的短影片,內容需與圖片主題高度相關。"
|
| 248 |
|
| 249 |
+
# 呼叫 Veo 影片生成
|
| 250 |
operation = client.models.generate_videos(
|
| 251 |
model="veo-2.0-generate-001",
|
| 252 |
prompt=prompt,
|
| 253 |
+
image=gemini_image,
|
| 254 |
config=types.GenerateVideosConfig(
|
| 255 |
person_generation="dont_allow",
|
| 256 |
aspect_ratio="16:9",
|