File size: 2,503 Bytes
753b62e
07afa1d
753b62e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)