import gradio as gr from backend import Backend with gr.Blocks() as demo: backend = Backend() with gr.Row(): gr.Markdown(f'

DAN_PDF_CHAT

') with gr.Row(): with gr.Column(scale = 0.5): with gr.Group(): gr.Markdown(f'

Setup for the Agent

') 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'

Setup for the User

') 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='

References would be shown HERE.

') 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)