Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,14 +90,18 @@ def chat(message, history):
|
|
| 90 |
#============starting extract_docx_text
|
| 91 |
def respond(message, history):
|
| 92 |
answer = qa_chain.invoke(message)
|
| 93 |
-
docs = retriever.invoke(message)
|
| 94 |
refs = [f"Page {d.metadata.get('page', 'N/A')}" for d in docs]
|
| 95 |
-
full_answer = f"{answer}\n\n**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
|
| 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,13 +333,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 329 |
</div>"""
|
| 330 |
)
|
| 331 |
with gr.TabItem("ChatBot-NRL manual-goods"):
|
| 332 |
-
gr.Markdown("# RAG Chatbot
|
| 333 |
-
chatbot = gr.Chatbot(height=500) #
|
| 334 |
-
msg = gr.Textbox(placeholder="
|
| 335 |
-
|
| 336 |
-
clear = gr.Button("Clear")
|
| 337 |
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
demo.queue().launch()
|
|
|
|
| 90 |
#============starting extract_docx_text
|
| 91 |
def respond(message, history):
|
| 92 |
answer = qa_chain.invoke(message)
|
| 93 |
+
docs = retriever.invoke(message)
|
| 94 |
refs = [f"Page {d.metadata.get('page', 'N/A')}" for d in docs]
|
| 95 |
+
full_answer = f"{answer}\n\n**References:**\n" + "\n".join(refs)
|
| 96 |
+
|
| 97 |
+
# CRITICAL: Append ONLY pure dicts - no metadata, tuples, or extras
|
| 98 |
+
new_history = history + [ # Or history.append() then return history
|
| 99 |
+
{"role": "user", "content": message},
|
| 100 |
+
{"role": "assistant", "content": full_answer}
|
| 101 |
+
]
|
| 102 |
|
| 103 |
+
# Clear input
|
| 104 |
+
return "", new_history # Return cleared msg, updated history
|
|
|
|
|
|
|
| 105 |
#====================
|
| 106 |
def extract_docx_text(file_path):
|
| 107 |
doc = Document(file_path)
|
|
|
|
| 333 |
</div>"""
|
| 334 |
)
|
| 335 |
with gr.TabItem("ChatBot-NRL manual-goods"):
|
| 336 |
+
gr.Markdown("# RAG Chatbot")
|
| 337 |
+
chatbot = gr.Chatbot(height=500) # Defaults to messages
|
| 338 |
+
msg = gr.Textbox(placeholder="Ask a question...", label="Query")
|
| 339 |
+
submit_btn = gr.Button("Submit")
|
|
|
|
| 340 |
|
| 341 |
+
# Events
|
| 342 |
+
submit_btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 343 |
+
msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 344 |
demo.queue().launch()
|