| | import gradio as gr |
| |
|
| | css=""" |
| | #col-container {max-width: 1400px; margin-left: auto; margin-right: auto;} |
| | """ |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | title = """ |
| | <div style="text-align: center;max-width: 1200px;"> |
| | <h1>Chat with PDF</h1> |
| | </div> |
| | """ |
| |
|
| |
|
| | def toggle_sidebar(state): |
| | ''' |
| | sidebarηΆζθ½¬ζ’ |
| | ''' |
| | state = not state |
| | return gr.update(visible = state), state |
| |
|
| |
|
| | |
| | def _create_demo(): |
| | with gr.Blocks(css=css, |
| | theme = "Soft" |
| | ) as demo: |
| | |
| | with gr.Row(): |
| | with gr.Column(elem_id="col-sidebar",scale=0.1,visible=False) as sidebar: |
| | nothing = gr.Button('This is sidebar') |
| | |
| | with gr.Column(elem_id="col-container"): |
| | gr.HTML(title) |
| | |
| | with gr.Column(): |
| | with gr.Row(): |
| | with gr.Column(scale=0.8): |
| | api_key = gr.Textbox( |
| | placeholder='Enter your OpenAI API key', |
| | show_label=False, |
| | interactive=True, |
| | container=False) |
| | |
| | with gr.Column(scale=0.2): |
| | change_api_key = gr.Button('Update API Key',interactive = False) |
| |
|
| | with gr.Row(): |
| | with gr.Column(scale=1): |
| | upload_btn = gr.UploadButton("π Upload PDF", file_types=[".pdf"],scale=0.9) |
| | sidebar_state = gr.State(False) |
| | toggle_sidebar_btn = gr.Button("π«΅") |
| | toggle_sidebar_btn.click(toggle_sidebar, [sidebar_state], [sidebar, sidebar_state]) |
| |
|
| |
|
| | with gr.Row(): |
| | with gr.Column(elem_id='pdf-preview-container'): |
| | show_img = gr.Image(label='PDF Preview', height=680) |
| |
|
| | with gr.Column(elem_id='chatbot-container'): |
| | with gr.Row(): |
| | chatbot = gr.Chatbot(value=[], elem_id='chatbot', height=625) |
| | with gr.Row(): |
| | |
| | text_input = gr.Textbox( |
| | show_label=False, |
| | placeholder="Ask your pdf?", |
| | container=False,scale=0.9) |
| |
|
| | |
| | submit_btn = gr.Button('π',scale=0.1) |
| |
|
| |
|
| | return demo, api_key, change_api_key, chatbot, show_img, text_input, submit_btn, upload_btn |
| |
|
| | smbtn_css = """ |
| | #small_btn { |
| | margin: 0.6em 0em 0.55em 0; |
| | max-width: 1em; |
| | min-width: 1em !important; |
| | height: 1em; |
| | } |
| | """ |
| | def create_demo(): |
| | ''' |
| | Interface with no api component |
| | ''' |
| | with gr.Blocks(css=css, |
| | theme = "Soft" |
| | ) as demo: |
| | |
| | with gr.Row(): |
| | with gr.Column(elem_id="col-sidebar",scale=0.1,visible=False) as sidebar: |
| | nothing = gr.Button('This is sidebar') |
| | |
| | with gr.Column(elem_id="col-container"): |
| | |
| | gr.HTML(title) |
| | |
| | with gr.Row(): |
| | sidebar_state = gr.State(False) |
| | toggle_sidebar_btn = gr.Button(">>",size='sm',scale=1) |
| | toggle_sidebar_btn.click(toggle_sidebar, [sidebar_state], [sidebar, sidebar_state]) |
| | |
| | upload_btn = gr.UploadButton("π Upload PDF", file_types=[".pdf"],scale=9) |
| | |
| | |
| | with gr.Column(): |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| |
|
| |
|
| | with gr.Row(): |
| | with gr.Column(elem_id='pdf-preview-container'): |
| | show_img = gr.Image(label='PDF Preview', height=680) |
| |
|
| | with gr.Column(elem_id='chatbot-container'): |
| | with gr.Row(): |
| | chatbot = gr.Chatbot(value=[], elem_id='chatbot', height=625) |
| | with gr.Row(): |
| | |
| | text_input = gr.Textbox( |
| | show_label=False, |
| | placeholder="Ask your pdf?", |
| | container=False,scale=8) |
| |
|
| | |
| | submit_btn = gr.Button('π',scale=1) |
| |
|
| |
|
| | return demo, chatbot, show_img, text_input, submit_btn, upload_btn |
| |
|
| |
|
| | if __name__ == '__main__': |
| | demo, api_key, change_api_key, chatbot, show_img, text_input, submit_btn, upload_btn = create_demo() |
| | demo.queue() |
| | demo.launch() |
| |
|