manabb commited on
Commit
16f7031
·
verified ·
1 Parent(s): 65d45bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -88,7 +88,15 @@ def chat(message, history):
88
  history.append([message, full])
89
  return history, ""
90
  #============starting extract_docx_text
91
-
 
 
 
 
 
 
 
 
92
  def extract_docx_text(file_path):
93
  doc = Document(file_path)
94
  final_data = []
@@ -318,12 +326,12 @@ with gr.Blocks(css=css) as demo:
318
  🚧 Coming Soon 🚧
319
  </div>"""
320
  )
321
- with gr.TabItem("ChatBox-NRL maual-goods"):
322
- gr.ChatInterface(
323
- chat,
324
- title="RAG Chatbot - NRL procurement manual of Goods",
325
- description="Ask questions!",
326
- examples=["what is GeM", "What is limited tender"],
327
- cache_examples=False # Disable for dynamic retriever
328
- )
329
  demo.queue().launch()
 
88
  history.append([message, full])
89
  return history, ""
90
  #============starting extract_docx_text
91
+ def respond(message, history):
92
+ answer = qa_chain.invoke(message)
93
+ docs = retriever.invoke(message) # Global or pass as state
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)
102
  final_data = []
 
326
  🚧 Coming Soon 🚧
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()