CoolFace
Apppublic

oliverwang15/DAN_Chat

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py63 linesDownload Raw Back to root
1import gradio as gr2from backend import Backend3 4with gr.Blocks() as demo:5    backend = Backend()6    with gr.Row():7        gr.Markdown(f'<center> <h1> <b> DAN_PDF_CHAT </b> </h1> </center>')8    with gr.Row():9        with gr.Column(scale = 0.5):10            with gr.Group():11                gr.Markdown(f'<center> <h3> <b> Setup for the Agent </b> </h3> </center>')12                openai_key = gr.Textbox(13                        label='Enter your OpenAI API key here',14                        type='password')15                assistant_id = gr.Textbox(16                        label='Enter the OpenAI assistant ID here, or you can use the default one',17                        value = 'asst_FXsUUX2RacJ5GxEs6sCXL7nY',18                        type = 'password',19                        ) 20            with gr.Group():21                gr.Markdown(f'<center> <h3> <b> Setup for the User </b> </h3> </center>')22                file = gr.File(label='Upload your .txt or .pdf file here', file_types=['.txt', '.pdf'], file_count = 'single')23                btn_submit_txt_online = gr.Button(value='Submit passage')24                25        with gr.Column(scale=1):26            # with gr.Group():27            chatbot = gr.Chatbot(show_copy_button = True)28            question_box = gr.Textbox(label='Enter your question here',29                                    placeholder = 'What is the animal mentioned in this passage?',30                                    value = 'What is the animal mentioned in this passage?'31            )32            with gr.Row():33                btn_submit_question_txt = gr.Button(value='Submit')34                btn_reset_question_txt = gr.Button(value='Reset')35                btn_show_html = gr.Button(value='Show reference')36                btn_hide_html = gr.Button(value='Hide reference')37 38    with gr.Row():39        html = gr.HTML(visible = False, label='HTML', value='<h1> References would be shown HERE.</h1>')40 41    btn_submit_txt_online.click(42        fn = backend.submit_passage,43        inputs = [openai_key, assistant_id, file],44    )45 46    btn_submit_question_txt.click(47        fn = backend.submit_question,48        inputs = [question_box],49        # outputs = [chatbot],50        outputs = [chatbot, html],51    )52    53    btn_show_html.click(54        fn = lambda:  gr.update(visible=True),55        outputs=html,56    )57    btn_hide_html.click(58        fn = lambda:  gr.update(visible=False),59        outputs=html,60    )61 62demo.queue()63demo.launch(show_error=True)