Spaces:
Sleeping
Sleeping
測試上傳影片
Browse files
gemini.py
CHANGED
|
@@ -225,13 +225,26 @@ def handle_video_message(event):
|
|
| 225 |
# 下載影片內容
|
| 226 |
with ApiClient(configuration) as api_client:
|
| 227 |
blob_api = MessagingApiBlob(api_client)
|
| 228 |
-
|
| 229 |
|
| 230 |
# 儲存影片到本地
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
with tempfile.NamedTemporaryFile(
|
| 232 |
dir=static_tmp_path, suffix=".mp4", delete=False
|
| 233 |
) as tf:
|
| 234 |
-
tf.write(
|
| 235 |
filename = os.path.basename(tf.name)
|
| 236 |
|
| 237 |
video_url = f"https://{base_url}/images/{filename}"
|
|
@@ -246,7 +259,7 @@ def handle_video_message(event):
|
|
| 246 |
response_modalities=["TEXT"],
|
| 247 |
tools=[google_search_tool],
|
| 248 |
),
|
| 249 |
-
contents=[{"mime_type": "video/mp4", "data":
|
| 250 |
)
|
| 251 |
description = response.text
|
| 252 |
except Exception as e:
|
|
|
|
| 225 |
# 下載影片內容
|
| 226 |
with ApiClient(configuration) as api_client:
|
| 227 |
blob_api = MessagingApiBlob(api_client)
|
| 228 |
+
video_data = blob_api.get_message_content(message_id=event.message.id)
|
| 229 |
|
| 230 |
# 儲存影片到本地
|
| 231 |
+
if video_data is None:
|
| 232 |
+
err_msg = "抱歉,無法取得影片內容。"
|
| 233 |
+
app.logger.error(err_msg)
|
| 234 |
+
with ApiClient(configuration) as api_client:
|
| 235 |
+
line_bot_api = MessagingApi(api_client)
|
| 236 |
+
line_bot_api.reply_message(
|
| 237 |
+
ReplyMessageRequest(
|
| 238 |
+
reply_token=event.reply_token,
|
| 239 |
+
messages=[TextMessage(text=err_msg)]
|
| 240 |
+
)
|
| 241 |
+
)
|
| 242 |
+
return
|
| 243 |
+
|
| 244 |
with tempfile.NamedTemporaryFile(
|
| 245 |
dir=static_tmp_path, suffix=".mp4", delete=False
|
| 246 |
) as tf:
|
| 247 |
+
tf.write(video_data)
|
| 248 |
filename = os.path.basename(tf.name)
|
| 249 |
|
| 250 |
video_url = f"https://{base_url}/images/{filename}"
|
|
|
|
| 259 |
response_modalities=["TEXT"],
|
| 260 |
tools=[google_search_tool],
|
| 261 |
),
|
| 262 |
+
contents=[{"mime_type": "video/mp4", "data": video_data}, "用繁體中文描述這段影片"],
|
| 263 |
)
|
| 264 |
description = response.text
|
| 265 |
except Exception as e:
|