manabb commited on
Commit
22603de
·
verified ·
1 Parent(s): 16f7031

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -94,8 +94,10 @@ def respond(message, history):
94
  refs = [f"Page {d.metadata.get('page', 'N/A')}" for d in docs]
95
  full_answer = f"{answer}\n\n**Refs:** {' | '.join(refs)}"
96
 
97
- history.append([message, full_answer])
98
- return history, ""
 
 
99
  #====================
100
  def extract_docx_text(file_path):
101
  doc = Document(file_path)
@@ -327,11 +329,13 @@ with gr.Blocks(css=css) as demo:
327
  </div>"""
328
  )
329
  with gr.TabItem("ChatBot-NRL manual-goods"):
330
- gr.Markdown("# RAG Chatbot - procurement manual of Goods")
331
- chatbot = gr.Chatbot(height=500, type="tuples") # Explicit tuples format
332
- msg = gr.Textbox(placeholder="Ask about GeM...", scale=4)
333
- clear = gr.Button("Clear")
334
-
335
- msg.submit(respond, [msg, chatbot], [chatbot, msg])
336
- clear.click(lambda: ([], ""), None, chatbot)
 
 
337
  demo.queue().launch()
 
94
  refs = [f"Page {d.metadata.get('page', 'N/A')}" for d in docs]
95
  full_answer = f"{answer}\n\n**Refs:** {' | '.join(refs)}"
96
 
97
+ # Append in messages format
98
+ history.append({"role": "user", "content": message})
99
+ history.append({"role": "assistant", "content": full_answer})
100
+ return history
101
  #====================
102
  def extract_docx_text(file_path):
103
  doc = Document(file_path)
 
329
  </div>"""
330
  )
331
  with gr.TabItem("ChatBot-NRL manual-goods"):
332
+ gr.Markdown("# RAG Chatbot with Page References")
333
+ chatbot = gr.Chatbot(height=500) # No 'type' arg!
334
+ msg = gr.Textbox(placeholder="What is GeM?", scale=4)
335
+ submit = gr.Button("Send", scale=1)
336
+ clear = gr.Button("Clear")
337
+
338
+ submit.click(respond, [msg, chatbot], [chatbot, msg])
339
+ msg.submit(respond, [msg, chatbot], [chatbot, msg])
340
+ clear.click(lambda: [], None, chatbot, queue=False)
341
  demo.queue().launch()