Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -347,7 +347,7 @@ def rag_workflow(query):
|
|
| 347 |
|
| 348 |
|
| 349 |
response = llm.invoke(prompt)
|
| 350 |
-
return response.content
|
| 351 |
|
| 352 |
|
| 353 |
def initialize():
|
|
@@ -395,25 +395,10 @@ import gradio as gr
|
|
| 395 |
|
| 396 |
def bot_kadi(history):
|
| 397 |
user_query = history[-1][0]
|
| 398 |
-
response
|
| 399 |
history[-1] = (user_query, response)
|
| 400 |
|
| 401 |
-
|
| 402 |
-
formatted_references = ""
|
| 403 |
-
docs = query_chroma(vectorstore, user_query, k=5)
|
| 404 |
-
for i, (doc, ref) in enumerate(docs):
|
| 405 |
-
formatted_references += f"""
|
| 406 |
-
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 5px;">
|
| 407 |
-
<h3 style="margin-top: 0;">Reference {i+1}</h3>
|
| 408 |
-
<p><strong>Source:</strong> {ref}</p>
|
| 409 |
-
<button onclick="var elem = document.getElementById('text-{i}'); var button = this; if (elem.style.display === 'block') {{ elem.style.display = 'none'; button.innerHTML = '▶ show source text'; }} else {{ elem.style.display = 'block'; button.innerHTML = '▼ hide source text'; }}">{{'▶ show source text'}}</button>
|
| 410 |
-
<div id="text-{i}" style="display: none;">
|
| 411 |
-
<p><strong>Text:</strong> {doc}</p>
|
| 412 |
-
</div>
|
| 413 |
-
</div>
|
| 414 |
-
"""
|
| 415 |
-
|
| 416 |
-
yield history, formatted_references
|
| 417 |
|
| 418 |
def main():
|
| 419 |
with gr.Blocks() as demo:
|
|
@@ -447,14 +432,10 @@ def main():
|
|
| 447 |
examples_per_page=3,
|
| 448 |
)
|
| 449 |
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
#user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
|
| 455 |
-
#submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
|
| 456 |
-
user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot, doc_citation])
|
| 457 |
-
submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot, doc_citation])
|
| 458 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 459 |
|
| 460 |
demo.launch()
|
|
|
|
| 347 |
|
| 348 |
|
| 349 |
response = llm.invoke(prompt)
|
| 350 |
+
return response.content
|
| 351 |
|
| 352 |
|
| 353 |
def initialize():
|
|
|
|
| 395 |
|
| 396 |
def bot_kadi(history):
|
| 397 |
user_query = history[-1][0]
|
| 398 |
+
response = rag_workflow(user_query)
|
| 399 |
history[-1] = (user_query, response)
|
| 400 |
|
| 401 |
+
yield history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
def main():
|
| 404 |
with gr.Blocks() as demo:
|
|
|
|
| 432 |
examples_per_page=3,
|
| 433 |
)
|
| 434 |
|
| 435 |
+
user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
|
| 436 |
+
submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
|
| 437 |
+
#user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot, doc_citation])
|
| 438 |
+
#submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot, doc_citation])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 440 |
|
| 441 |
demo.launch()
|