Spaces:
Runtime error

pmmijak commited on
Commit
ed92ca7
·
1 Parent(s): 93c77de
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -82,9 +82,18 @@ def predict(history, docstore):
82
  query = history[-1][0]
83
  # print(query)
84
  docs = docstore.similarity_search(query)
 
 
 
 
 
 
 
 
 
85
  response = chain.run(input_documents=docs, question=query,
86
  context=chat_history)
87
- return response
88
 
89
 
90
  def predict_rqa(history, docstore):
@@ -153,8 +162,13 @@ if __name__ == '__main__':
153
  with gr.Row():
154
  enter = gr.Button("Submit")
155
  with gr.Column(scale=0.5):
156
- chatbot = gr.Chatbot()
157
  clear = gr.Button("Clear")
 
 
 
 
 
158
 
159
 
160
  def user(user_message, history, doc_store):
@@ -164,16 +178,14 @@ if __name__ == '__main__':
164
 
165
  def bot(history, doc_store):
166
  # print(history)
167
- bot_message = predict(history, doc_store)
168
  history[-1][1] = bot_message
169
-
170
- return history
171
-
172
 
173
  msg.submit(user, [msg, chatbot, doc_store], [msg, chatbot], queue=False).then(
174
- bot, [chatbot, doc_store], chatbot)
175
  enter.click(user, [msg, chatbot, doc_store], [msg, chatbot], queue=False).then(
176
- bot, [chatbot, doc_store], chatbot)
177
 
178
  clear.click(lambda: None, None, chatbot, queue=False)
179
 
 
82
  query = history[-1][0]
83
  # print(query)
84
  docs = docstore.similarity_search(query)
85
+
86
+ pieces = ""
87
+ for doc in docs:
88
+ print("\n -------------- \n ")
89
+ print(doc.page_content)
90
+ print("\n -------------- \n ")
91
+ pieces = pieces + str(doc.page_content) + "\n"
92
+ pieces += "\n -------------- \n"
93
+
94
  response = chain.run(input_documents=docs, question=query,
95
  context=chat_history)
96
+ return response, pieces
97
 
98
 
99
  def predict_rqa(history, docstore):
 
162
  with gr.Row():
163
  enter = gr.Button("Submit")
164
  with gr.Column(scale=0.5):
165
+ chatbot = gr.Chatbot(height=600, show_copy_button=True)
166
  clear = gr.Button("Clear")
167
+ with gr.Row():
168
+ st = gr.Textbox(
169
+ label="Text pieces sematically selected as relevant hint input for LLM: ",
170
+ type="text", max_lines=10, visible=True
171
+ )
172
 
173
 
174
  def user(user_message, history, doc_store):
 
178
 
179
  def bot(history, doc_store):
180
  # print(history)
181
+ bot_message, context = predict(history, doc_store)
182
  history[-1][1] = bot_message
183
+ return history, context
 
 
184
 
185
  msg.submit(user, [msg, chatbot, doc_store], [msg, chatbot], queue=False).then(
186
+ bot, [chatbot, doc_store], [chatbot, st])
187
  enter.click(user, [msg, chatbot, doc_store], [msg, chatbot], queue=False).then(
188
+ bot, [chatbot, doc_store], [chatbot, st])
189
 
190
  clear.click(lambda: None, None, chatbot, queue=False)
191