bupa1018 commited on
Commit
499e447
·
1 Parent(s): d066682

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -26
app.py CHANGED
@@ -347,7 +347,7 @@ def rag_workflow(query):
347
 
348
 
349
  response = llm.invoke(prompt)
350
- return response.content, references
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, references = rag_workflow(user_query)
399
  history[-1] = (user_query, response)
400
 
401
- # Format references for display with text passages
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 = '&#9654; show source text'; }} else {{ elem.style.display = 'block'; button.innerHTML = '&#9660; hide source text'; }}">{{'&#9654; 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
- with gr.Column(scale=3):
451
- with gr.Tab("References"):
452
- doc_citation = gr.HTML("<p>References used in answering the question will be displayed below.</p>")
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()