Spaces:
Sleeping
Sleeping
File size: 2,697 Bytes
b151e60 |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
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()
)
|