Update app.py
Browse files
app.py
CHANGED
@@ -267,7 +267,12 @@ def conversation(qa_chain, message, history):
|
|
267 |
# return gr.update(value=""), new_history, response_sources[0], response_sources[1]
|
268 |
return qa_chain, gr.update(value=""), new_history, response_source1, response_source1_page, response_source2, response_source2_page, response_source3, response_source3_page
|
269 |
|
|
|
|
|
|
|
|
|
270 |
|
|
|
271 |
def upload_file(file_obj):
|
272 |
list_file_path = []
|
273 |
for idx, file in enumerate(file_obj):
|
@@ -325,6 +330,10 @@ def demo():
|
|
325 |
|
326 |
with gr.Tab("Step 3 - Conversation with chatbot"):
|
327 |
chatbot = gr.Chatbot(height=300)
|
|
|
|
|
|
|
|
|
328 |
with gr.Accordion("Advanced - Document references", open=False):
|
329 |
with gr.Row():
|
330 |
doc_source1 = gr.Textbox(label="Reference 1", lines=2, container=True, scale=20)
|
@@ -340,7 +349,10 @@ def demo():
|
|
340 |
with gr.Row():
|
341 |
submit_btn = gr.Button("Submit")
|
342 |
clear_btn = gr.ClearButton([msg, chatbot])
|
343 |
-
|
|
|
|
|
|
|
344 |
# Preprocessing events
|
345 |
#upload_btn.upload(upload_file, inputs=[upload_btn], outputs=[document])
|
346 |
db_btn.click(initialize_database, \
|
@@ -353,19 +365,23 @@ def demo():
|
|
353 |
outputs=[chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
354 |
queue=False)
|
355 |
|
356 |
-
#
|
357 |
msg.submit(conversation, \
|
358 |
-
inputs=[qa_chain, msg, chatbot], \
|
359 |
outputs=[qa_chain, msg, chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
360 |
queue=False)
|
361 |
submit_btn.click(conversation, \
|
362 |
-
inputs=[qa_chain, msg, chatbot], \
|
363 |
outputs=[qa_chain, msg, chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
364 |
queue=False)
|
365 |
clear_btn.click(lambda:[None,"",0,"",0,"",0], \
|
366 |
inputs=None, \
|
367 |
outputs=[chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
368 |
queue=False)
|
|
|
|
|
|
|
|
|
369 |
demo.queue().launch(debug=True)
|
370 |
|
371 |
|
|
|
267 |
# return gr.update(value=""), new_history, response_sources[0], response_sources[1]
|
268 |
return qa_chain, gr.update(value=""), new_history, response_source1, response_source1_page, response_source2, response_source2_page, response_source3, response_source3_page
|
269 |
|
270 |
+
def download_csv(chat_history):
|
271 |
+
df = pd.DataFrame(chat_history, columns=['User Message', 'Assistant Response', 'Rating'])
|
272 |
+
df.to_csv('conversation_history.csv', index=False)
|
273 |
+
return 'conversation_history.csv'
|
274 |
|
275 |
+
|
276 |
def upload_file(file_obj):
|
277 |
list_file_path = []
|
278 |
for idx, file in enumerate(file_obj):
|
|
|
330 |
|
331 |
with gr.Tab("Step 3 - Conversation with chatbot"):
|
332 |
chatbot = gr.Chatbot(height=300)
|
333 |
+
# Add rating slider
|
334 |
+
with gr.Row():
|
335 |
+
rating_slider = gr.Slider(minimum=1, maximum=5, label="Rate the message:", interactive=True)
|
336 |
+
|
337 |
with gr.Accordion("Advanced - Document references", open=False):
|
338 |
with gr.Row():
|
339 |
doc_source1 = gr.Textbox(label="Reference 1", lines=2, container=True, scale=20)
|
|
|
349 |
with gr.Row():
|
350 |
submit_btn = gr.Button("Submit")
|
351 |
clear_btn = gr.ClearButton([msg, chatbot])
|
352 |
+
|
353 |
+
with gr.Row():
|
354 |
+
download_btn = gr.Button("Download Conversation History as CSV")
|
355 |
+
|
356 |
# Preprocessing events
|
357 |
#upload_btn.upload(upload_file, inputs=[upload_btn], outputs=[document])
|
358 |
db_btn.click(initialize_database, \
|
|
|
365 |
outputs=[chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
366 |
queue=False)
|
367 |
|
368 |
+
# Conversation events
|
369 |
msg.submit(conversation, \
|
370 |
+
inputs=[qa_chain, msg, chatbot, rating_slider], \
|
371 |
outputs=[qa_chain, msg, chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
372 |
queue=False)
|
373 |
submit_btn.click(conversation, \
|
374 |
+
inputs=[qa_chain, msg, chatbot, rating_slider], \
|
375 |
outputs=[qa_chain, msg, chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
376 |
queue=False)
|
377 |
clear_btn.click(lambda:[None,"",0,"",0,"",0], \
|
378 |
inputs=None, \
|
379 |
outputs=[chatbot, doc_source1, source1_page, doc_source2, source2_page, doc_source3, source3_page], \
|
380 |
queue=False)
|
381 |
+
|
382 |
+
# Add download button event
|
383 |
+
download_btn.click(download_csv, inputs=[chatbot], outputs=None)
|
384 |
+
|
385 |
demo.queue().launch(debug=True)
|
386 |
|
387 |
|