zm-f21 commited on
Commit
c1b32e3
·
verified ·
1 Parent(s): 3751f42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -223,25 +223,32 @@ Answer conversationally:
223
  return f"{answer}\n\nSources Used:\n{metadata}"
224
 
225
  # =======================================================
226
- # 10) Gradio Chat Interface (INTRO only once)
227
  # =======================================================
228
- INTRO_MESSAGE = {
229
- "role": "assistant",
230
- "content": INTRO_TEXT
231
- }
232
 
233
  def chat_api(message, history):
234
- history.append({"role": "user", "content": message})
 
 
 
 
 
235
  reply = generate_with_rag(message)
236
- history.append({"role": "assistant", "content": reply})
 
 
 
237
  return history, history
238
 
 
239
  with gr.Blocks() as demo:
240
  gr.Markdown("## Canada Residential Tenancy Assistant (RAG + Mistral 7B)")
241
 
242
  chatbot = gr.Chatbot(
243
- value=[(None, INTRO_MESSAGE["content"])],
244
- height=500
245
  )
246
 
247
  user_box = gr.Textbox(
@@ -254,5 +261,6 @@ with gr.Blocks() as demo:
254
  send_btn.click(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
255
  user_box.submit(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
256
 
 
257
  if __name__ == "__main__":
258
- demo.launch()
 
223
  return f"{answer}\n\nSources Used:\n{metadata}"
224
 
225
  # =======================================================
226
+ # 10) Gradio Chat Interface (INTRO only once, FIXED)
227
  # =======================================================
228
+
229
+ INTRO_TUPLE = (None, INTRO_TEXT)
 
 
230
 
231
  def chat_api(message, history):
232
+ # history is a list of tuples: [(user, bot), ...]
233
+
234
+ # Add user message
235
+ history.append((message, None))
236
+
237
+ # Generate bot reply
238
  reply = generate_with_rag(message)
239
+
240
+ # Replace last tuple with completed (user, bot) pair
241
+ history[-1] = (message, reply)
242
+
243
  return history, history
244
 
245
+
246
  with gr.Blocks() as demo:
247
  gr.Markdown("## Canada Residential Tenancy Assistant (RAG + Mistral 7B)")
248
 
249
  chatbot = gr.Chatbot(
250
+ value=[INTRO_TUPLE], # must be a list of tuples!
251
+ height=500,
252
  )
253
 
254
  user_box = gr.Textbox(
 
261
  send_btn.click(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
262
  user_box.submit(chat_api, inputs=[user_box, chatbot], outputs=[chatbot, chatbot])
263
 
264
+
265
  if __name__ == "__main__":
266
+ demo.launch(share=True)