DAN_Chat / app.py
oliverwang15's picture
init
07afa1d
import gradio as gr
from backend import Backend
with gr.Blocks() as demo:
backend = Backend()
with gr.Row():
gr.Markdown(f'<center> <h1> <b> DAN_PDF_CHAT </b> </h1> </center>')
with gr.Row():
with gr.Column(scale = 0.5):
with gr.Group():
gr.Markdown(f'<center> <h3> <b> Setup for the Agent </b> </h3> </center>')
openai_key = gr.Textbox(
label='Enter your OpenAI API key here',
type='password')
assistant_id = gr.Textbox(
label='Enter the OpenAI assistant ID here, or you can use the default one',
value = 'asst_FXsUUX2RacJ5GxEs6sCXL7nY',
type = 'password',
)
with gr.Group():
gr.Markdown(f'<center> <h3> <b> Setup for the User </b> </h3> </center>')
file = gr.File(label='Upload your .txt or .pdf file here', file_types=['.txt', '.pdf'], file_count = 'single')
btn_submit_txt_online = gr.Button(value='Submit passage')
with gr.Column(scale=1):
# with gr.Group():
chatbot = gr.Chatbot(show_copy_button = True)
question_box = gr.Textbox(label='Enter your question here',
placeholder = 'What is the animal mentioned in this passage?',
value = 'What is the animal mentioned in this passage?'
)
with gr.Row():
btn_submit_question_txt = gr.Button(value='Submit')
btn_reset_question_txt = gr.Button(value='Reset')
btn_show_html = gr.Button(value='Show reference')
btn_hide_html = gr.Button(value='Hide reference')
with gr.Row():
html = gr.HTML(visible = False, label='HTML', value='<h1> References would be shown HERE.</h1>')
btn_submit_txt_online.click(
fn = backend.submit_passage,
inputs = [openai_key, assistant_id, file],
)
btn_submit_question_txt.click(
fn = backend.submit_question,
inputs = [question_box],
# outputs = [chatbot],
outputs = [chatbot, html],
)
btn_show_html.click(
fn = lambda: gr.update(visible=True),
outputs=html,
)
btn_hide_html.click(
fn = lambda: gr.update(visible=False),
outputs=html,
)
demo.queue()
demo.launch(show_error=True)