import gradio as gr css=""" #col-container {max-width: 1400px; margin-left: auto; margin-right: auto;} """ # title = """ #
#

Chat with PDF

#

Upload a .PDF from your computer, click the "UPLoad PDF" button,C-V your openai access token, press enter.
# when everything is ready, you can start asking questions about the pdf ;)

# Duplicate Space #
# """ title = """

Chat with PDF

""" def toggle_sidebar(state): ''' sidebar状态转换 ''' state = not state return gr.update(visible = state), state # Gradio application setup def _create_demo(): with gr.Blocks(css=css, theme = "Soft" # Change the theme here ) 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') # Create a Gradio block 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" # Change the theme here ) 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') # Create a Gradio block 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(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(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()