Learn / src /app.py
Yoxas's picture
Update src/app.py
85dde01 verified
from interface import create_demo
from pdfchatbot import PDFChatBot
import csv
import gradio as gr
demo, chat_history, show_img, txt, submit_button, uploaded_pdf, slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k = create_demo()
pdf_chatbot = PDFChatBot()
def download_chat_history(chat_history):
with open("chat_history.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["User", "Bot"]) # header row
for user_text, bot_text in chat_history:
writer.writerow([user_text, bot_text])
return "chat_history.csv"
with demo:
uploaded_pdf.upload(pdf_chatbot.render_file, inputs=[uploaded_pdf,slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k], outputs=[show_img])
submit_button.click(pdf_chatbot.add_text, inputs=[chat_history, txt], outputs=[chat_history], queue=False).\
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]).\
success(pdf_chatbot.render_file, inputs=[uploaded_pdf], outputs=[show_img])
download_button = gr.Button("Download Chat History")
download_output = gr.File()
download_button.click(fn=download_chat_history, inputs=[chat_history], outputs=download_output)
if __name__ == "__main__":
demo.launch()