in infrastructure/movie-search-app/movie_search.py [0:0]
def page():
bot_user = "model"
print("starting")
global db
# initialize db within request context
if not db:
# initiate a connection pool to a Postgres database
db = init_connection_pool()
model_picker_dialog()
def toggle_theme(e: me.ClickEvent):
if me.theme_brightness() == "light":
me.set_theme_mode("dark")
else:
me.set_theme_mode("light")
def on_input_enter(e: me.InputEnterEvent):
state = me.state(State)
state.input = e.value
print(state.input)
yield from send_prompt(e)
with me.box(style=_STYLE_APP_CONTAINER):
with me.content_button(
type="icon",
style=me.Style(position="absolute", right=4, top=8),
on_click=toggle_theme,
):
me.icon("light_mode" if me.theme_brightness() == "dark" else "dark_mode")
title = "Movie Search Virtual Assistant"
if title:
me.text(title, type="headline-5", style=_STYLE_TITLE)
with me.box(style=_STYLE_CHAT_BOX):
state = me.state(State)
for conversation in state.conversations:
for message in conversation.messages:
with me.box(style=_make_style_chat_bubble_wrapper(message.role)):
if message.role == _ROLE_ASSISTANT:
me.text(bot_user, style=_STYLE_CHAT_BUBBLE_NAME)
with me.box(style=_make_chat_bubble_style(message.role)):
if message.role == _ROLE_USER:
me.text(message.content, style=_STYLE_CHAT_BUBBLE_PLAINTEXT)
else:
me.markdown(message.content)
with me.box(style=_STYLE_CHAT_INPUT_BOX):
with me.box(style=me.Style(flex_grow=1)):
me.input(
label=_LABEL_INPUT,
# Workaround: update key to clear input.
key=f"input-{len(state.conversations)}",
on_blur=on_blur,
on_enter=on_input_enter,
style=_STYLE_CHAT_INPUT,
)
with me.box(
style=me.Style(
display="flex",
padding=me.Padding(left=12, bottom=12),
cursor="pointer",
),
on_click=switch_model,
):
me.text(
"Backend:",
style=me.Style(font_weight=500, padding=me.Padding(right=6)),
)
if state.models:
me.text(", ".join(state.models))
else:
me.text("(no backend selected)")
with me.content_button(
color="primary",
type="flat",
disabled=state.in_progress,
on_click=send_prompt,
style=_STYLE_CHAT_BUTTON,
):
me.icon(
_LABEL_BUTTON_IN_PROGRESS if state.in_progress else _LABEL_BUTTON
)