gradio显示和隐藏侧边栏

记一下防止忘记怎么实现的。

可以用于第一次访问页面时控制组件的隐藏和显示。

来自:How make a SideBar hide and show - Gradio - Hugging Face Forums

另外:试了很多方法,没想到最简单的实现方法就是直接返回gr.update。

import gradio as gr
css='./css/template.css'
LANGS = ["ace_Arab", "eng_Latn", "fra_Latn", "spa_Latn"]

app= gr.Blocks(css=css)

# def active():
#     state_bar = not sidebar_right.visible
#     return print(state_bar)


def toggle_sidebar(state):
    state = not state
    return gr.update(visible = state), state


with app:
    with gr.Row():
        with gr.Column(visible=False) as sidebar_left:
            gr.Markdown("SideBar Left")
        with gr.Column() as main:
            with gr.Row():
                nav_bar = gr.Markdown("NavBar")
            with gr.Row():
                with gr.Column():
                    gr.Chatbot()
                    with gr.Row():
                        prompt = gr.TextArea(label="",placeholder="Ask me")
                        btn_a = gr.Button("Audio",size="sm")
                        btn_b = gr.Button("Send",size="sm")
                        btn_c = gr.Button("Clear",size="sm")
                        btn_d = gr.Button("Mute",size="sm")
                        lang = gr.Dropdown(label="Source Language", choices=LANGS)

                        sidebar_state = gr.State(False)

                        btn_toggle_sidebar = gr.Button("Toggle Sidebar")
                        btn_toggle_sidebar.click(toggle_sidebar, [sidebar_state], [sidebar_left, sidebar_state])

                        #btn_a.click(active)

        with gr.Column(visible=False) as sidebar_right:
            gr.Markdown("SideBar Right")

app.launch()

你可能感兴趣的:(大模型,python)