Isshi14 commited on
Commit
b63bb09
·
verified ·
1 Parent(s): e847192

Upload 2 files

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -133,9 +133,23 @@ def load_profile():
133
  return "Profile not found."
134
 
135
  def respond(message, chat_history):
136
- answer = query_rag(message, vector_store, hf_client)
 
 
 
 
 
 
 
137
  chat_history.append({"role": "user", "content": message})
138
- chat_history.append({"role": "assistant", "content": answer})
 
 
 
 
 
 
 
139
  return "", chat_history
140
 
141
  with gr.Blocks(title="My AI Twin", theme=gr.themes.Soft()) as demo:
 
133
  return "Profile not found."
134
 
135
  def respond(message, chat_history):
136
+ if not message:
137
+ return "", chat_history
138
+
139
+ # Initialize history if None (though Gradio usually handles this)
140
+ if chat_history is None:
141
+ chat_history = []
142
+
143
+ # Append user message immediately for responsiveness
144
  chat_history.append({"role": "user", "content": message})
145
+
146
+ try:
147
+ # Get AI response
148
+ answer = query_rag(message, vector_store, hf_client)
149
+ chat_history.append({"role": "assistant", "content": answer})
150
+ except Exception as e:
151
+ chat_history.append({"role": "assistant", "content": f"Error: {str(e)}"})
152
+
153
  return "", chat_history
154
 
155
  with gr.Blocks(title="My AI Twin", theme=gr.themes.Soft()) as demo: