ReallyFloppyPenguin commited on
Commit
e5c4a6a
·
verified ·
1 Parent(s): 7c79299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
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 i, (user_msg, ai_msg) in enumerate(history[:-1]): # Exclude the current "thinking" message
170
- if user_msg and ai_msg and ai_msg != "🤔 Thinking...":
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
- # Update the last message with the real response
179
- history[-1] = [message, result["response"]]
180
- yield history, ""
181
  else:
182
- # Update with error message
183
- history[-1] = [message, f"❌ Error: {result['error']}"]
184
- yield history, ""
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
- return chat_with_ai(message, history, model)
 
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(