Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -146,26 +146,19 @@ def analyze_image_with_text(image_path: str, user_text: str) -> str:
|
|
| 146 |
return "圖片路徑無效,無法進行分析。"
|
| 147 |
|
| 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.
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
|
| 167 |
-
except Exception as e:
|
| 168 |
-
return f"圖片分析失敗: {e}"
|
| 169 |
|
| 170 |
|
| 171 |
# ==========================
|
|
|
|
| 146 |
return "圖片路徑無效,無法進行分析。"
|
| 147 |
|
| 148 |
img_user = PIL.Image.open(image_path)
|
| 149 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
chat_model = client.chats.create(model="gemini-2.0-flash-exp", temperature=0.5, top_p=0.5,top_k=16)
|
| 151 |
|
| 152 |
+
response = chat_model.send_message([img_usr, user_text])
|
| 153 |
+
if (response.text != None):
|
| 154 |
+
out = response.text
|
| 155 |
+
else:
|
| 156 |
+
out = "Gemini沒答案!請換個說法!"
|
| 157 |
+
except:
|
| 158 |
+
# 處理錯誤
|
| 159 |
+
out = "Gemini執行出錯!請換個說法!"
|
| 160 |
|
| 161 |
+
return out
|
|
|
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
# ==========================
|