import gradio as gr from typing import Dict, List, Union from src.frontend import chatbot, progress_screen sidebar = gr.Sidebar( open=True, visible=False, key='sidebar', preserved_by_key='key' ) chatbot_button = gr.Button( value='Viewing Chatbot!', variant='secondary', visible=False, interactive=False, key='chatbot_button', preserved_by_key='key' ) progress_button = gr.Button( value='View Your Story Progress!', variant='primary', visible=False, interactive=True, key='progress_button', preserved_by_key='key' ) def get_widgets() -> List[Union[gr.Sidebar, gr.Button]]: return [sidebar, chatbot_button, progress_button] def view_screen() -> Dict[Union[gr.Sidebar, gr.Button], gr.update]: return { widget: gr.update(visible=True) for widget in get_widgets() } def on_chatbot_button_click(): chatbot_screen_updates = chatbot.control_screen(True) progress_screen_updates = progress_screen.control_screen(False) chatbot_button_update = gr.update( value='Viewing Chatbot!', variant='secondary', interactive=False ) progress_button_update = gr.update( value='View Your Story Progress!', variant='primary', interactive=True ) return { chatbot_button: chatbot_button_update, progress_button: progress_button_update } | \ chatbot_screen_updates | progress_screen_updates def on_progress_button_click(): chatbot_screen_updates = chatbot.control_screen(False) progress_screen_updates = progress_screen.control_screen(True) chatbot_button_update = gr.update( value='Come & Explore!', variant='primary', interactive=True ) progress_button_update = gr.update( value='Viewing Your Story Progress!', variant='secondary', interactive=False ) return { chatbot_button: chatbot_button_update, progress_button: progress_button_update } | \ chatbot_screen_updates | progress_screen_updates def render(): sidebar.render() with sidebar: chatbot_button.render() progress_button.render() chatbot_button.click( fn=on_chatbot_button_click, inputs=[], outputs=[chatbot_button, progress_button] + \ chatbot.control_screen_widgets() + \ progress_screen.control_screen_widgets() ) progress_button.click( fn=on_progress_button_click, inputs=[], outputs=[chatbot_button, progress_button] + \ chatbot.control_screen_widgets() + \ progress_screen.control_screen_widgets() )