Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -32,6 +32,8 @@ from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
| 32 |
|
| 33 |
# 設置 Google AI API 金鑰
|
| 34 |
google_api = os.environ["GOOGLE_API_KEY"]
|
|
|
|
|
|
|
| 35 |
# 設置 Line Bot 的 API 金鑰和秘密金鑰
|
| 36 |
line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
|
| 37 |
line_handler = WebhookHandler(os.environ["CHANNEL_SECRET"])
|
|
@@ -101,7 +103,7 @@ def generate_and_upload_image(prompt: str) -> str:
|
|
| 101 |
生成圖片的 URL。
|
| 102 |
"""
|
| 103 |
try:
|
| 104 |
-
genai_client = genai.Client(api_key=google_api)
|
| 105 |
response = genai_client.models.generate_content(
|
| 106 |
model="gemini-2.0-flash-exp",
|
| 107 |
contents=prompt,
|
|
@@ -146,12 +148,13 @@ def analyze_image_with_text(image_path: str, user_text: str) -> str:
|
|
| 146 |
img_user = PIL.Image.open(image_path)
|
| 147 |
|
| 148 |
# 建立一個新的聊天模型實例,以確保狀態獨立
|
| 149 |
-
chat_model = ChatGoogleGenerativeAI(
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
)
|
|
|
|
| 155 |
|
| 156 |
response = chat_model.invoke([
|
| 157 |
{"role": "user", "content": [
|
|
|
|
| 32 |
|
| 33 |
# 設置 Google AI API 金鑰
|
| 34 |
google_api = os.environ["GOOGLE_API_KEY"]
|
| 35 |
+
genai_client = genai.Client(api_key=google_api)
|
| 36 |
+
|
| 37 |
# 設置 Line Bot 的 API 金鑰和秘密金鑰
|
| 38 |
line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
|
| 39 |
line_handler = WebhookHandler(os.environ["CHANNEL_SECRET"])
|
|
|
|
| 103 |
生成圖片的 URL。
|
| 104 |
"""
|
| 105 |
try:
|
| 106 |
+
# genai_client = genai.Client(api_key=google_api)
|
| 107 |
response = genai_client.models.generate_content(
|
| 108 |
model="gemini-2.0-flash-exp",
|
| 109 |
contents=prompt,
|
|
|
|
| 148 |
img_user = PIL.Image.open(image_path)
|
| 149 |
|
| 150 |
# 建立一個新的聊天模型實例,以確保狀態獨立
|
| 151 |
+
# chat_model = ChatGoogleGenerativeAI(
|
| 152 |
+
# model="gemini-2.0-flash-exp",
|
| 153 |
+
# temperature=0.5,
|
| 154 |
+
# top_p=0.5,
|
| 155 |
+
# top_k=16
|
| 156 |
+
# )
|
| 157 |
+
chat_model = client.chats.create(model="gemini-2.0-flash-exp", temperature=0.5, top_p=0.5,top_k=16)
|
| 158 |
|
| 159 |
response = chat_model.invoke([
|
| 160 |
{"role": "user", "content": [
|