Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -89,19 +89,30 @@ def chat(message, history):
|
|
| 89 |
return history, ""
|
| 90 |
#============starting extract_docx_text
|
| 91 |
def respond(message, history):
|
| 92 |
-
|
| 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 |
-
#
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
#====================
|
| 106 |
def extract_docx_text(file_path):
|
| 107 |
doc = Document(file_path)
|
|
@@ -326,14 +337,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 326 |
out = gr.HTML(label="Compliance Result")
|
| 327 |
#out = gr.Textbox(lines=15, label="Compliance Result",elem_id="compliance-out")
|
| 328 |
run_btn.click(check_compliance, inputs=inp, outputs=out)
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 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")
|
|
@@ -341,4 +348,22 @@ with gr.Blocks(css=css) as demo:
|
|
| 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()
|
|
|
|
| 89 |
return history, ""
|
| 90 |
#============starting extract_docx_text
|
| 91 |
def respond(message, history):
|
| 92 |
+
word_count = len(message.strip().split())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
# If less than 3 words, do not call LLM, just ask user to clarify
|
| 95 |
+
if word_count < 3:
|
| 96 |
+
correction_msg = "Please **clarify** or expand your question (at least 3 words)."
|
| 97 |
+
new_history = history + [
|
| 98 |
+
{"role": "user", "content": message},
|
| 99 |
+
{"role": "assistant", "content": correction_msg},
|
| 100 |
+
]
|
| 101 |
+
return "", new_history
|
| 102 |
+
else:
|
| 103 |
+
answer = qa_chain.invoke(message)
|
| 104 |
+
docs = retriever.invoke(message)
|
| 105 |
+
refs = [f"Page {d.metadata.get('page', 'N/A')}" for d in docs]
|
| 106 |
+
full_answer = f"{answer}\n\n**References:**\n" + "\n".join(refs)
|
| 107 |
+
|
| 108 |
+
# CRITICAL: Append ONLY pure dicts - no metadata, tuples, or extras
|
| 109 |
+
new_history = history + [ # Or history.append() then return history
|
| 110 |
+
{"role": "user", "content": message},
|
| 111 |
+
{"role": "assistant", "content": full_answer}
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
# Clear input
|
| 115 |
+
return "", new_history # Return cleared msg, updated history
|
| 116 |
#====================
|
| 117 |
def extract_docx_text(file_path):
|
| 118 |
doc = Document(file_path)
|
|
|
|
| 337 |
out = gr.HTML(label="Compliance Result")
|
| 338 |
#out = gr.Textbox(lines=15, label="Compliance Result",elem_id="compliance-out")
|
| 339 |
run_btn.click(check_compliance, inputs=inp, outputs=out)
|
| 340 |
+
|
| 341 |
+
with gr.TabItem("NRL ChatBot"):
|
| 342 |
+
gr.Markdown("""# RAG Chatbot - Ask question and answer will be generated by AI from Only MANUAL FOR PROCUREMENT OF
|
| 343 |
+
GOODS - NRL revised on 16.03.23""")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
chatbot = gr.Chatbot(height=500) # Defaults to messages
|
| 345 |
msg = gr.Textbox(placeholder="Ask a question...", label="Query")
|
| 346 |
submit_btn = gr.Button("Submit")
|
|
|
|
| 348 |
# Events
|
| 349 |
submit_btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 350 |
msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 351 |
+
with gr.TabItem("Compliance Check of user technical doc"):
|
| 352 |
+
gr.HTML("""
|
| 353 |
+
<div style="color: white; background: black; padding: 20px; text-align: center; font-size: 24px;">
|
| 354 |
+
🚧 Coming Soon 🚧
|
| 355 |
+
</div>"""
|
| 356 |
+
)
|
| 357 |
+
with gr.TabItem("Compliance Check of ATC"):
|
| 358 |
+
gr.HTML("""
|
| 359 |
+
<div style="color: white; background: black; padding: 20px; text-align: center; font-size: 24px;">
|
| 360 |
+
🚧 Coming Soon 🚧
|
| 361 |
+
</div>"""
|
| 362 |
+
)
|
| 363 |
+
with gr.TabItem("Compliance Check of Draft GeM Tender"):
|
| 364 |
+
gr.HTML("""
|
| 365 |
+
<div style="color: white; background: black; padding: 20px; text-align: center; font-size: 24px;">
|
| 366 |
+
🚧 Coming Soon 🚧
|
| 367 |
+
</div>"""
|
| 368 |
+
)
|
| 369 |
demo.queue().launch()
|