Update src/app.py
Browse files- src/app.py +11 -1
src/app.py
CHANGED
|
@@ -4,13 +4,23 @@ from pdfchatbot import PDFChatBot
|
|
| 4 |
demo, chat_history, show_img, txt, submit_button, uploaded_pdf, download_chat_history, slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k = create_demo()
|
| 5 |
|
| 6 |
pdf_chatbot = PDFChatBot()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
with demo:
|
| 8 |
uploaded_pdf.upload(pdf_chatbot.render_file, inputs=[uploaded_pdf,slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k], outputs=[show_img])
|
| 9 |
|
| 10 |
submit_button.click(pdf_chatbot.add_text, inputs=[chat_history, txt], outputs=[chat_history], queue=False).\
|
| 11 |
success(pdf_chatbot.generate_response, inputs=[chat_history, txt, uploaded_pdf,slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k], outputs=[chat_history,txt]).\
|
| 12 |
success(pdf_chatbot.render_file, inputs=[uploaded_pdf], outputs=[show_img])
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
if __name__ == "__main__":
|
| 16 |
demo.launch()
|
|
|
|
| 4 |
demo, chat_history, show_img, txt, submit_button, uploaded_pdf, download_chat_history, slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k = create_demo()
|
| 5 |
|
| 6 |
pdf_chatbot = PDFChatBot()
|
| 7 |
+
|
| 8 |
+
def download_chat_history(chat_history):
|
| 9 |
+
with open("chat_history.csv", "w", newline="") as csvfile:
|
| 10 |
+
writer = csv.writer(csvfile)
|
| 11 |
+
writer.writerow(["User", "Bot"]) # header row
|
| 12 |
+
for user_text, bot_text in chat_history:
|
| 13 |
+
writer.writerow([user_text, bot_text])
|
| 14 |
+
return "chat_history.csv"
|
| 15 |
+
|
| 16 |
with demo:
|
| 17 |
uploaded_pdf.upload(pdf_chatbot.render_file, inputs=[uploaded_pdf,slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k], outputs=[show_img])
|
| 18 |
|
| 19 |
submit_button.click(pdf_chatbot.add_text, inputs=[chat_history, txt], outputs=[chat_history], queue=False).\
|
| 20 |
success(pdf_chatbot.generate_response, inputs=[chat_history, txt, uploaded_pdf,slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k], outputs=[chat_history,txt]).\
|
| 21 |
success(pdf_chatbot.render_file, inputs=[uploaded_pdf], outputs=[show_img])
|
| 22 |
+
download_button = gr.Button("Download Chat History")
|
| 23 |
+
download_button.click(fn=download_chat_history, inputs=[chat_history], outputs="file")
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
demo.launch()
|