Spaces:
Runtime error
Runtime error
檔名為亂數產生以免重複
Browse files
test.py
CHANGED
@@ -4,6 +4,7 @@ import logging
|
|
4 |
import os
|
5 |
import tempfile
|
6 |
from io import BytesIO
|
|
|
7 |
|
8 |
from google import genai
|
9 |
from google.genai import types
|
@@ -110,13 +111,15 @@ def handle_text_message(event):
|
|
110 |
for part in response.candidates[0].content.parts:
|
111 |
if part.inline_data is not None:
|
112 |
image = Image.open(BytesIO(part.inline_data.data))
|
113 |
-
filename = "
|
114 |
image_path = os.path.join(static_tmp_path, filename)
|
115 |
image.save(image_path)
|
116 |
|
117 |
# 建立圖片的公開 URL
|
118 |
image_url = f"https://{base_url}/images/{filename}"
|
119 |
-
|
|
|
|
|
120 |
with ApiClient(configuration) as api_client:
|
121 |
line_bot_api = MessagingApi(api_client)
|
122 |
line_bot_api.reply_message(
|
|
|
4 |
import os
|
5 |
import tempfile
|
6 |
from io import BytesIO
|
7 |
+
import uuid
|
8 |
|
9 |
from google import genai
|
10 |
from google.genai import types
|
|
|
111 |
for part in response.candidates[0].content.parts:
|
112 |
if part.inline_data is not None:
|
113 |
image = Image.open(BytesIO(part.inline_data.data))
|
114 |
+
filename = f"{uuid.uuid4().hex}.png"
|
115 |
image_path = os.path.join(static_tmp_path, filename)
|
116 |
image.save(image_path)
|
117 |
|
118 |
# 建立圖片的公開 URL
|
119 |
image_url = f"https://{base_url}/images/{filename}"
|
120 |
+
app.logger.info(f"Image URL: {image_url}")
|
121 |
+
|
122 |
+
# 回傳圖片給 LINE 使用者
|
123 |
with ApiClient(configuration) as api_client:
|
124 |
line_bot_api = MessagingApi(api_client)
|
125 |
line_bot_api.reply_message(
|