Update app.py
Browse files
app.py
CHANGED
|
@@ -160,14 +160,10 @@ def create_chat_interface():
|
|
| 160 |
history.append([message, "❌ Please select an AI model first"])
|
| 161 |
return history, ""
|
| 162 |
|
| 163 |
-
# Show typing indicator
|
| 164 |
-
history.append([message, "🤔 Thinking..."])
|
| 165 |
-
yield history, ""
|
| 166 |
-
|
| 167 |
# Convert gradio history to API format
|
| 168 |
conversation_history = []
|
| 169 |
-
for
|
| 170 |
-
if user_msg and ai_msg
|
| 171 |
conversation_history.append({"role": "user", "content": user_msg})
|
| 172 |
conversation_history.append({"role": "assistant", "content": ai_msg})
|
| 173 |
|
|
@@ -175,13 +171,13 @@ def create_chat_interface():
|
|
| 175 |
result = chat_ai.send_message(selected_model, message, conversation_history)
|
| 176 |
|
| 177 |
if result["success"]:
|
| 178 |
-
#
|
| 179 |
-
history[
|
| 180 |
-
|
| 181 |
else:
|
| 182 |
-
#
|
| 183 |
-
history[
|
| 184 |
-
|
| 185 |
|
| 186 |
def clear_chat():
|
| 187 |
"""Clear the chat history"""
|
|
@@ -285,7 +281,8 @@ Ready to chat! Type your message below.
|
|
| 285 |
|
| 286 |
# Chat functionality
|
| 287 |
def submit_message(message, history, model):
|
| 288 |
-
|
|
|
|
| 289 |
|
| 290 |
# Send message on button click or enter
|
| 291 |
send_btn.click(
|
|
|
|
| 160 |
history.append([message, "❌ Please select an AI model first"])
|
| 161 |
return history, ""
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# Convert gradio history to API format
|
| 164 |
conversation_history = []
|
| 165 |
+
for user_msg, ai_msg in history:
|
| 166 |
+
if user_msg and ai_msg:
|
| 167 |
conversation_history.append({"role": "user", "content": user_msg})
|
| 168 |
conversation_history.append({"role": "assistant", "content": ai_msg})
|
| 169 |
|
|
|
|
| 171 |
result = chat_ai.send_message(selected_model, message, conversation_history)
|
| 172 |
|
| 173 |
if result["success"]:
|
| 174 |
+
# Add the new conversation to history
|
| 175 |
+
history.append([message, result["response"]])
|
| 176 |
+
return history, ""
|
| 177 |
else:
|
| 178 |
+
# Add error message to history
|
| 179 |
+
history.append([message, f"❌ Error: {result['error']}"])
|
| 180 |
+
return history, ""
|
| 181 |
|
| 182 |
def clear_chat():
|
| 183 |
"""Clear the chat history"""
|
|
|
|
| 281 |
|
| 282 |
# Chat functionality
|
| 283 |
def submit_message(message, history, model):
|
| 284 |
+
new_history, cleared_input = chat_with_ai(message, history, model)
|
| 285 |
+
return new_history, "" # Return updated history and clear the input
|
| 286 |
|
| 287 |
# Send message on button click or enter
|
| 288 |
send_btn.click(
|