in gemini/sample-apps/gemini-mesop-cloudrun/main.py [0:0]
def app() -> None:
"""Main Mesop App"""
state = me.state(State)
# Main header
vertex_gemini_header()
# Nav header
nav_menu(state)
# Main content
with me.box(style=_STYLE_MAIN_COLUMN):
me.text(text="Generate a story", type="headline-6")
with me.box(style=me.Style(display="flex", flex_direction="row", gap=15)):
with me.box(style=me.Style(display="flex", flex_direction="column", gap=2)):
me.input(
key="story_character_name",
label="Character name",
value="Mittens",
on_input=on_input,
style=_STORY_INPUT_STYLE,
)
me.input(
key="story_character_type",
label="Type of character",
value="Cat",
on_input=on_input,
style=_STORY_INPUT_STYLE,
)
me.input(
key="story_character_personality",
label="Personality of character",
value="Mitten is a very friendly cat.",
on_input=on_input,
style=_STORY_INPUT_STYLE,
)
me.input(
key="story_character_location",
label="Where does the character live?",
value="Andromeda Galaxy",
on_input=on_input,
style=_STORY_INPUT_STYLE,
)
me.select(
key="story_selected_premises",
label="Story's premise",
options=[
me.SelectOption(label="Love", value="love"),
me.SelectOption(label="Adventure", value="adventure"),
me.SelectOption(label="Mystery", value="mystery"),
me.SelectOption(label="Horror", value="horror"),
me.SelectOption(label="Comedy", value="comedy"),
me.SelectOption(label="Sci-Fi", value="sci-fi"),
me.SelectOption(label="Fantasy", value="fantasy"),
me.SelectOption(label="Thriller", value="thriller"),
],
multiple=True,
on_selection_change=on_selection_change,
value=state.story_selected_premises,
)
me.text("Story creativity")
me.radio(
key="story_temp_value",
on_change=on_story_radio_change,
options=[
me.RadioOption(label="Low", value="low"),
me.RadioOption(label="High", value="high"),
],
value=state.story_temp_value,
)
me.text("Length of story")
me.radio(
key="story_length_value",
on_change=on_story_radio_change,
options=[
me.RadioOption(label="Short", value="short"),
me.RadioOption(label="Long", value="long"),
],
value=state.story_length_value,
)
with me.box(
style=me.Style(
display="flex", gap=10, padding=me.Padding(bottom=20)
)
):
me.button(
"Clear",
color="primary",
type="stroked",
on_click=on_click_clear_story,
)
me.button(
"Generate my story",
color="primary",
type="flat",
on_click=generate_story,
)
with me.box(style=_BOX_STYLE):
me.text("Output", style=me.Style(font_weight=500))
if state.story_progress:
with me.box(style=_SPINNER_STYLE):
me.progress_spinner()
me.text("Generating story with Gemini 2.0 ...")
if state.story_output:
with me.box(
style=me.Style(
display="grid",
justify_content="center",
justify_items="center",
)
):
me.markdown(
key="story_output",
text=state.story_output,
style=me.Style(width="100%", margin=me.Margin(top=10)),
)