Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -119,21 +119,21 @@ def save_chat_history(session_id, history):
|
|
| 119 |
def upload_to_gemini(path, mime_type=None):
|
| 120 |
"""上传文件到Gemini API"""
|
| 121 |
file = genai.upload_file(path, mime_type=mime_type)
|
| 122 |
-
|
| 123 |
return file
|
| 124 |
|
| 125 |
def wait_for_files_active(files):
|
| 126 |
"""等待文件处理完成"""
|
| 127 |
-
|
| 128 |
for name in (file.name for file in files):
|
| 129 |
file = genai.get_file(name)
|
| 130 |
while file.state.name == "PROCESSING":
|
| 131 |
-
|
| 132 |
time.sleep(10)
|
| 133 |
file = genai.get_file(name)
|
| 134 |
if file.state.name != "ACTIVE":
|
| 135 |
raise Exception(f"File {file.name} failed to process")
|
| 136 |
-
|
| 137 |
|
| 138 |
@app.route('/upload', methods=['POST'])
|
| 139 |
def get_upload_file():
|
|
@@ -286,7 +286,7 @@ def chat():
|
|
| 286 |
files = []
|
| 287 |
|
| 288 |
parts = userMessage.get("parts", [])
|
| 289 |
-
|
| 290 |
userTextMessage = parts[-1]
|
| 291 |
file_urls = parts[:-1]
|
| 292 |
if file_urls:
|
|
@@ -330,8 +330,8 @@ def chat():
|
|
| 330 |
chat_history.append(model_message)
|
| 331 |
save_chat_history(session_id, chat_history)
|
| 332 |
debug.log_prompt(chat_history, preset_name)
|
| 333 |
-
|
| 334 |
-
|
| 335 |
|
| 336 |
except Exception as e:
|
| 337 |
logger.error(f"Error generating response: {str(e)}")
|
|
|
|
| 119 |
def upload_to_gemini(path, mime_type=None):
|
| 120 |
"""上传文件到Gemini API"""
|
| 121 |
file = genai.upload_file(path, mime_type=mime_type)
|
| 122 |
+
debug.log_message(f"Uploaded file '{file.display_name}' as: {file.uri}")
|
| 123 |
return file
|
| 124 |
|
| 125 |
def wait_for_files_active(files):
|
| 126 |
"""等待文件处理完成"""
|
| 127 |
+
debug.log_message("Waiting for file processing...")
|
| 128 |
for name in (file.name for file in files):
|
| 129 |
file = genai.get_file(name)
|
| 130 |
while file.state.name == "PROCESSING":
|
| 131 |
+
debug.log_message(".", end="", flush=True)
|
| 132 |
time.sleep(10)
|
| 133 |
file = genai.get_file(name)
|
| 134 |
if file.state.name != "ACTIVE":
|
| 135 |
raise Exception(f"File {file.name} failed to process")
|
| 136 |
+
debug.log_message("...all files ready")
|
| 137 |
|
| 138 |
@app.route('/upload', methods=['POST'])
|
| 139 |
def get_upload_file():
|
|
|
|
| 286 |
files = []
|
| 287 |
|
| 288 |
parts = userMessage.get("parts", [])
|
| 289 |
+
debug.log_message(f"Parts: {parts}")
|
| 290 |
userTextMessage = parts[-1]
|
| 291 |
file_urls = parts[:-1]
|
| 292 |
if file_urls:
|
|
|
|
| 330 |
chat_history.append(model_message)
|
| 331 |
save_chat_history(session_id, chat_history)
|
| 332 |
debug.log_prompt(chat_history, preset_name)
|
| 333 |
+
debug.log_message(f"User message parts: {parts}")
|
| 334 |
+
debug.log_message(f"Chat history before sending: {chat_history}")
|
| 335 |
|
| 336 |
except Exception as e:
|
| 337 |
logger.error(f"Error generating response: {str(e)}")
|