anasmkh commited on
Commit
67c6e4d
·
verified ·
1 Parent(s): 6fa8435

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -59,9 +59,18 @@ chat_engine = index.as_chat_engine(
59
  import gradio as gr
60
  def chat_with_ai(user_input, chat_history):
61
  response = chat_engine.chat(user_input)
62
-
63
- chat_history.append((user_input, str(response)))
64
-
 
 
 
 
 
 
 
 
 
65
  return chat_history, ""
66
 
67
  def clear_history():
 
59
  import gradio as gr
60
  def chat_with_ai(user_input, chat_history):
61
  response = chat_engine.chat(user_input)
62
+ references = response.source_nodes
63
+ ref,pages = [],[]
64
+ for i in range(len(references)):
65
+ if references[i].metadata['file_name'] not in ref:
66
+ ref.append(references[i].metadata['file_name'])
67
+ pages.append(references[i].metadata['page_label'])
68
+ complete_response = str(response) + "\n\n" + "references:" + str(ref) + "\n\n" + "pages:" + str(pages)
69
+ if ref !=[] or pages!=[]:
70
+ chat_history.append((user_input, complete_response))
71
+ elif ref==[] or pages==[]:
72
+ chat_history.append((user_input,str(response)))
73
+
74
  return chat_history, ""
75
 
76
  def clear_history():