Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/gradio_app.py +174 -176
ui/gradio_app.py
CHANGED
|
@@ -1,61 +1,56 @@
|
|
| 1 |
-
"""Gradio
|
| 2 |
|
| 3 |
from typing import Any, cast
|
| 4 |
-
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
from game.engine import (
|
| 8 |
-
collect_current,
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
follow_whisper,
|
| 12 |
-
hf_companion_status,
|
| 13 |
-
myco_reply,
|
| 14 |
-
pick_current,
|
| 15 |
-
study_current,
|
| 16 |
)
|
| 17 |
from game.state import welcome_history
|
| 18 |
from models.mushroom import Mushroom
|
| 19 |
from ui.renderers import (
|
| 20 |
-
dex_markdown,
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
game_status_markdown,
|
| 24 |
-
hero_markdown,
|
| 25 |
-
home_forest_markdown,
|
| 26 |
-
mushroom_card,
|
| 27 |
-
play_hook_markdown,
|
| 28 |
-
progress_markdown,
|
| 29 |
world_map_markdown,
|
| 30 |
)
|
| 31 |
|
| 32 |
EMPTY_COLLECTION = None
|
| 33 |
-
START_POSITION
|
| 34 |
|
| 35 |
HOME_MARKDOWN = """
|
| 36 |
## Welcome to the Myco forest
|
| 37 |
|
| 38 |
-
Myco is a tiny forest game
|
| 39 |
-
visit **๐ MycoDex** to review
|
| 40 |
|
| 41 |
-
**Goal:** solve one mystery
|
| 42 |
-
|
| 43 |
"""
|
| 44 |
|
| 45 |
GUIDE_MARKDOWN = """
|
| 46 |
## How to play
|
| 47 |
|
| 48 |
-
1. Go to **๐ฎ Play**.
|
| 49 |
-
2.
|
| 50 |
-
3.
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
"""
|
| 55 |
|
| 56 |
|
| 57 |
def mushroom_card_from_state(current):
|
| 58 |
-
"""Render a mushroom card from Gradio state."""
|
| 59 |
if current is None:
|
| 60 |
return mushroom_card(None)
|
| 61 |
return mushroom_card(
|
|
@@ -67,12 +62,11 @@ def mushroom_card_from_state(current):
|
|
| 67 |
|
| 68 |
|
| 69 |
def search_forest(collection, position):
|
| 70 |
-
"""Explore the forest and refresh every visible gameplay panel."""
|
| 71 |
mushroom, current, history = discover_mushroom(collection)
|
| 72 |
-
|
| 73 |
return (
|
| 74 |
-
forest_scene(current, collection,
|
| 75 |
-
game_status_markdown(current, collection,
|
| 76 |
mushroom_card_from_state(current),
|
| 77 |
current,
|
| 78 |
history,
|
|
@@ -82,235 +76,239 @@ def search_forest(collection, position):
|
|
| 82 |
|
| 83 |
|
| 84 |
def ask_companion(message, history, current, collection, position):
|
| 85 |
-
"""Ask Myco about the active discovery and current journey."""
|
| 86 |
return myco_reply(message, history, current, collection, position)
|
| 87 |
|
| 88 |
|
| 89 |
def collect_discovery(current, collection, history, position):
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
player_position = _safe_position(position)
|
| 93 |
return (
|
| 94 |
-
|
| 95 |
-
forest_scene(current,
|
| 96 |
-
game_status_markdown(current,
|
| 97 |
-
dex_markdown(
|
| 98 |
-
world_map_markdown(
|
| 99 |
-
|
| 100 |
-
progress_markdown(
|
| 101 |
)
|
| 102 |
|
| 103 |
|
| 104 |
def pick_discovery(current, collection, history, position):
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
player_position = _safe_position(position)
|
| 108 |
return (
|
| 109 |
-
|
| 110 |
updated_current,
|
| 111 |
-
forest_scene(updated_current,
|
| 112 |
-
game_status_markdown(updated_current,
|
| 113 |
mushroom_card_from_state(updated_current),
|
| 114 |
-
dex_markdown(
|
| 115 |
-
world_map_markdown(
|
| 116 |
-
|
| 117 |
-
progress_markdown(
|
| 118 |
)
|
| 119 |
|
| 120 |
|
| 121 |
def follow_story_whisper(current, collection, history, position):
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
player_position = _safe_position(position)
|
| 125 |
return (
|
| 126 |
updated_current,
|
| 127 |
-
forest_scene(updated_current, collection,
|
| 128 |
-
game_status_markdown(updated_current, collection,
|
| 129 |
mushroom_card_from_state(updated_current),
|
| 130 |
-
|
| 131 |
)
|
| 132 |
|
| 133 |
|
| 134 |
def study_discovery(current, history, collection, position):
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
player_position = _safe_position(position)
|
| 138 |
return (
|
| 139 |
updated_current,
|
| 140 |
-
forest_scene(updated_current, collection,
|
| 141 |
-
game_status_markdown(updated_current, collection,
|
| 142 |
mushroom_card_from_state(updated_current),
|
| 143 |
-
|
| 144 |
)
|
| 145 |
|
| 146 |
|
| 147 |
def move_player(position, direction, current, collection):
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
elif direction == "
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
x -= 1
|
| 156 |
-
elif direction == "east":
|
| 157 |
-
x += 1
|
| 158 |
-
next_position = _safe_position((x, y))
|
| 159 |
-
return (
|
| 160 |
-
next_position,
|
| 161 |
-
forest_scene(current, collection, next_position),
|
| 162 |
-
game_status_markdown(current, collection, next_position),
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
def _safe_position(position):
|
| 167 |
-
"""Return a valid 3x3 player position for Gradio state."""
|
| 168 |
-
if position is None:
|
| 169 |
-
return START_POSITION
|
| 170 |
-
x, y = position
|
| 171 |
-
return (max(0, min(2, int(x))), max(0, min(2, int(y))))
|
| 172 |
|
| 173 |
|
| 174 |
def block_unsafe_eating(current, history):
|
| 175 |
-
"""Let Myco prevent unsafe eating while preserving chat state."""
|
| 176 |
return eat_current(current, history)
|
| 177 |
|
| 178 |
|
| 179 |
def open_play_tab():
|
| 180 |
-
"""Switch from the Home postcard into the playable forest tab."""
|
| 181 |
return gr.update(selected="play")
|
| 182 |
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
def build_app():
|
| 185 |
-
"
|
| 186 |
-
|
|
|
|
| 187 |
current_mushroom = gr.State(None)
|
| 188 |
-
collection
|
| 189 |
-
player_position
|
|
|
|
|
|
|
| 190 |
gr.HTML(hero_markdown())
|
| 191 |
|
| 192 |
with gr.Tabs(selected="home") as tabs:
|
|
|
|
|
|
|
| 193 |
with gr.Tab("๐ Home", id="home"):
|
| 194 |
gr.Markdown(HOME_MARKDOWN)
|
| 195 |
gr.HTML(home_forest_markdown())
|
| 196 |
-
start_play_button = gr.Button(
|
| 197 |
-
|
|
|
|
|
|
|
| 198 |
|
|
|
|
| 199 |
with gr.Tab("๐ฎ Play", id="play"):
|
| 200 |
gr.HTML(game_intro_markdown())
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
with gr.Row():
|
| 207 |
-
|
|
|
|
|
|
|
| 208 |
with gr.Row():
|
| 209 |
-
west_button
|
| 210 |
-
pick_button
|
| 211 |
-
east_button
|
| 212 |
with gr.Row():
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
)
|
| 235 |
-
|
| 236 |
-
prompt = gr.Textbox(
|
| 237 |
-
label="Ask Myco",
|
| 238 |
-
placeholder="Ask Myco what the forest is hiding",
|
| 239 |
-
scale=4,
|
| 240 |
-
)
|
| 241 |
-
ask_button = gr.Button("Ask Myco ๐", scale=1, variant="primary")
|
| 242 |
|
|
|
|
| 243 |
with gr.Tab("๐ MycoDex"):
|
| 244 |
with gr.Row():
|
| 245 |
-
progress = gr.Markdown(
|
| 246 |
-
|
| 247 |
-
elem_id="progress-panel",
|
| 248 |
-
)
|
| 249 |
-
dex = gr.Markdown(
|
| 250 |
-
dex_markdown(EMPTY_COLLECTION),
|
| 251 |
-
elem_id="mycodex",
|
| 252 |
-
)
|
| 253 |
|
|
|
|
| 254 |
with gr.Tab("๐บ๏ธ World Map"):
|
| 255 |
world_map = gr.HTML(world_map_markdown(EMPTY_COLLECTION))
|
| 256 |
|
|
|
|
| 257 |
with gr.Tab("๐งญ Guide"):
|
| 258 |
gr.Markdown(GUIDE_MARKDOWN)
|
| 259 |
|
| 260 |
-
|
|
|
|
| 261 |
|
| 262 |
search_button.click(
|
| 263 |
search_forest,
|
| 264 |
-
inputs=
|
| 265 |
-
outputs=
|
| 266 |
)
|
|
|
|
| 267 |
ask_button.click(
|
| 268 |
ask_companion,
|
| 269 |
-
inputs=
|
| 270 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
)
|
| 272 |
|
| 273 |
-
for direction, button in
|
| 274 |
-
("north", north_button),
|
| 275 |
-
("
|
| 276 |
-
|
| 277 |
-
("east", east_button),
|
| 278 |
-
):
|
| 279 |
button.click(
|
| 280 |
move_player,
|
| 281 |
-
inputs=
|
| 282 |
-
outputs=
|
| 283 |
)
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
|
|
|
| 288 |
)
|
| 289 |
collect_button.click(
|
| 290 |
collect_discovery,
|
| 291 |
-
inputs=
|
| 292 |
-
outputs=
|
| 293 |
)
|
| 294 |
pick_button.click(
|
| 295 |
pick_discovery,
|
| 296 |
-
inputs=
|
| 297 |
-
outputs=
|
| 298 |
)
|
| 299 |
whisper_button.click(
|
| 300 |
follow_story_whisper,
|
| 301 |
-
inputs=
|
| 302 |
-
outputs=
|
| 303 |
-
)
|
| 304 |
-
study_button.click(
|
| 305 |
-
study_discovery,
|
| 306 |
-
inputs=(current_mushroom, chat, collection, player_position),
|
| 307 |
-
outputs=(current_mushroom, scene, status, discovery, chat),
|
| 308 |
)
|
| 309 |
eat_button.click(
|
| 310 |
block_unsafe_eating,
|
| 311 |
-
inputs=
|
| 312 |
-
outputs=
|
| 313 |
)
|
| 314 |
|
| 315 |
-
|
| 316 |
return demo
|
|
|
|
|
|
| 1 |
+
"""Gradio game UI for Myco โ LLM-powered forest adventure."""
|
| 2 |
|
| 3 |
from typing import Any, cast
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
from game.engine import (
|
| 7 |
+
collect_current, discover_mushroom, eat_current,
|
| 8 |
+
follow_whisper, hf_companion_status, myco_reply,
|
| 9 |
+
pick_current, study_current,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
)
|
| 11 |
from game.state import welcome_history
|
| 12 |
from models.mushroom import Mushroom
|
| 13 |
from ui.renderers import (
|
| 14 |
+
dex_markdown, forest_scene, game_intro_markdown,
|
| 15 |
+
game_status_markdown, hero_markdown, home_forest_markdown,
|
| 16 |
+
mushroom_card, play_hook_markdown, progress_markdown,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
world_map_markdown,
|
| 18 |
)
|
| 19 |
|
| 20 |
EMPTY_COLLECTION = None
|
| 21 |
+
START_POSITION = (1, 1)
|
| 22 |
|
| 23 |
HOME_MARKDOWN = """
|
| 24 |
## Welcome to the Myco forest
|
| 25 |
|
| 26 |
+
Myco is a tiny AI-powered forest game. Open **๐ฎ Play** to search for mushrooms,
|
| 27 |
+
visit **๐ MycoDex** to review your collection, and use **๐งญ Guide** for help.
|
| 28 |
|
| 29 |
+
**Goal:** solve one mystery โ why does Myco remember a forest that vanished before it was born?
|
| 30 |
+
Follow clues until the Impossible Mushroom blooms inside the MycoDex.
|
| 31 |
"""
|
| 32 |
|
| 33 |
GUIDE_MARKDOWN = """
|
| 34 |
## How to play
|
| 35 |
|
| 36 |
+
1. Go to **๐ฎ Play** and click **๐ฎ Search Clearing** to discover a mushroom.
|
| 37 |
+
2. **Myco (the AI) reacts** โ read what it senses about the mushroom.
|
| 38 |
+
3. Choose your action:
|
| 39 |
+
- **๐ Study** โ Myco examines the mushroom and updates its magic field.
|
| 40 |
+
- **๐ Pick** โ grab it as a game item. Poisonous picks = Game Over!
|
| 41 |
+
- **๐ Collect** โ add it to the MycoDex for safe keeping and score.
|
| 42 |
+
- **๐ Follow Whisper** โ reveal mystery fragments. Risky on unstudied mushrooms!
|
| 43 |
+
- **๐ฝ๏ธ Eat?** โ Myco will stop you every time (for good reason).
|
| 44 |
+
4. **Ask Myco** anything in the chat โ it knows the forest, the mystery, and the mushrooms.
|
| 45 |
+
5. Use **โฌ๏ธโฌ๏ธโฌ
๏ธโก๏ธ** to move through the 3ร3 forest grid.
|
| 46 |
+
|
| 47 |
+
**Scoring:** Common = 10 spores ยท Rare = 35 ยท Legendary = 100 ยท Poison = โ25 + Game Over
|
| 48 |
+
|
| 49 |
+
**Poisonous mushrooms:** Ghost Gill ยท Pepper Pixie ยท Ruby Knuckle ยท Clockwork Chanterelle
|
| 50 |
"""
|
| 51 |
|
| 52 |
|
| 53 |
def mushroom_card_from_state(current):
|
|
|
|
| 54 |
if current is None:
|
| 55 |
return mushroom_card(None)
|
| 56 |
return mushroom_card(
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
def search_forest(collection, position):
|
|
|
|
| 65 |
mushroom, current, history = discover_mushroom(collection)
|
| 66 |
+
pos = _safe_pos(position)
|
| 67 |
return (
|
| 68 |
+
forest_scene(current, collection, pos),
|
| 69 |
+
game_status_markdown(current, collection, pos),
|
| 70 |
mushroom_card_from_state(current),
|
| 71 |
current,
|
| 72 |
history,
|
|
|
|
| 76 |
|
| 77 |
|
| 78 |
def ask_companion(message, history, current, collection, position):
|
|
|
|
| 79 |
return myco_reply(message, history, current, collection, position)
|
| 80 |
|
| 81 |
|
| 82 |
def collect_discovery(current, collection, history, position):
|
| 83 |
+
updated_coll, updated_hist = collect_current(current, collection, history)
|
| 84 |
+
pos = _safe_pos(position)
|
|
|
|
| 85 |
return (
|
| 86 |
+
updated_coll,
|
| 87 |
+
forest_scene(current, updated_coll, pos),
|
| 88 |
+
game_status_markdown(current, updated_coll, pos),
|
| 89 |
+
dex_markdown(updated_coll),
|
| 90 |
+
world_map_markdown(updated_coll),
|
| 91 |
+
updated_hist,
|
| 92 |
+
progress_markdown(updated_coll),
|
| 93 |
)
|
| 94 |
|
| 95 |
|
| 96 |
def pick_discovery(current, collection, history, position):
|
| 97 |
+
updated_coll, updated_current, updated_hist = pick_current(current, collection, history)
|
| 98 |
+
pos = _safe_pos(position)
|
|
|
|
| 99 |
return (
|
| 100 |
+
updated_coll,
|
| 101 |
updated_current,
|
| 102 |
+
forest_scene(updated_current, updated_coll, pos),
|
| 103 |
+
game_status_markdown(updated_current, updated_coll, pos),
|
| 104 |
mushroom_card_from_state(updated_current),
|
| 105 |
+
dex_markdown(updated_coll),
|
| 106 |
+
world_map_markdown(updated_coll),
|
| 107 |
+
updated_hist,
|
| 108 |
+
progress_markdown(updated_coll),
|
| 109 |
)
|
| 110 |
|
| 111 |
|
| 112 |
def follow_story_whisper(current, collection, history, position):
|
| 113 |
+
updated_current, updated_hist = follow_whisper(current, collection, history)
|
| 114 |
+
pos = _safe_pos(position)
|
|
|
|
| 115 |
return (
|
| 116 |
updated_current,
|
| 117 |
+
forest_scene(updated_current, collection, pos),
|
| 118 |
+
game_status_markdown(updated_current, collection, pos),
|
| 119 |
mushroom_card_from_state(updated_current),
|
| 120 |
+
updated_hist,
|
| 121 |
)
|
| 122 |
|
| 123 |
|
| 124 |
def study_discovery(current, history, collection, position):
|
| 125 |
+
updated_current, updated_hist = study_current(current, history)
|
| 126 |
+
pos = _safe_pos(position)
|
|
|
|
| 127 |
return (
|
| 128 |
updated_current,
|
| 129 |
+
forest_scene(updated_current, collection, pos),
|
| 130 |
+
game_status_markdown(updated_current, collection, pos),
|
| 131 |
mushroom_card_from_state(updated_current),
|
| 132 |
+
updated_hist,
|
| 133 |
)
|
| 134 |
|
| 135 |
|
| 136 |
def move_player(position, direction, current, collection):
|
| 137 |
+
x, y = _safe_pos(position)
|
| 138 |
+
if direction == "north": y -= 1
|
| 139 |
+
elif direction == "south": y += 1
|
| 140 |
+
elif direction == "west": x -= 1
|
| 141 |
+
elif direction == "east": x += 1
|
| 142 |
+
pos = _safe_pos((x, y))
|
| 143 |
+
return pos, forest_scene(current, collection, pos), game_status_markdown(current, collection, pos)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
|
| 146 |
def block_unsafe_eating(current, history):
|
|
|
|
| 147 |
return eat_current(current, history)
|
| 148 |
|
| 149 |
|
| 150 |
def open_play_tab():
|
|
|
|
| 151 |
return gr.update(selected="play")
|
| 152 |
|
| 153 |
|
| 154 |
+
def _safe_pos(position):
|
| 155 |
+
if position is None:
|
| 156 |
+
return START_POSITION
|
| 157 |
+
x, y = position
|
| 158 |
+
return (max(0, min(2, int(x))), max(0, min(2, int(y))))
|
| 159 |
+
|
| 160 |
+
|
| 161 |
def build_app():
|
| 162 |
+
with gr.Blocks(title="Myco โ AI Forest Game", theme=gr.themes.Soft()) as demo:
|
| 163 |
+
|
| 164 |
+
# โโ State โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 165 |
current_mushroom = gr.State(None)
|
| 166 |
+
collection = gr.State([])
|
| 167 |
+
player_position = gr.State(START_POSITION)
|
| 168 |
+
|
| 169 |
+
# โโ Hero โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 170 |
gr.HTML(hero_markdown())
|
| 171 |
|
| 172 |
with gr.Tabs(selected="home") as tabs:
|
| 173 |
+
|
| 174 |
+
# โโ HOME โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 175 |
with gr.Tab("๐ Home", id="home"):
|
| 176 |
gr.Markdown(HOME_MARKDOWN)
|
| 177 |
gr.HTML(home_forest_markdown())
|
| 178 |
+
start_play_button = gr.Button(
|
| 179 |
+
"๐ Enter the Forest", variant="primary", size="lg"
|
| 180 |
+
)
|
| 181 |
+
gr.Markdown(f"*{hf_companion_status()}*")
|
| 182 |
|
| 183 |
+
# โโ PLAY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 184 |
with gr.Tab("๐ฎ Play", id="play"):
|
| 185 |
gr.HTML(game_intro_markdown())
|
| 186 |
+
|
| 187 |
+
# Forest scene + controls
|
| 188 |
+
scene = gr.HTML(forest_scene(None, EMPTY_COLLECTION, START_POSITION))
|
| 189 |
+
|
| 190 |
+
with gr.Row():
|
| 191 |
+
with gr.Column(scale=1):
|
| 192 |
+
search_button = gr.Button("๐ฎ Search Clearing", variant="primary", size="lg")
|
| 193 |
+
with gr.Column(scale=1):
|
| 194 |
+
gr.Markdown("**Move Myco**")
|
| 195 |
with gr.Row():
|
| 196 |
+
gr.HTML("<div></div>")
|
| 197 |
+
north_button = gr.Button("โฌ๏ธ", size="sm")
|
| 198 |
+
gr.HTML("<div></div>")
|
| 199 |
with gr.Row():
|
| 200 |
+
west_button = gr.Button("โฌ
๏ธ", size="sm")
|
| 201 |
+
pick_button = gr.Button("๐ Pick", variant="primary", size="sm")
|
| 202 |
+
east_button = gr.Button("โก๏ธ", size="sm")
|
| 203 |
with gr.Row():
|
| 204 |
+
gr.HTML("<div></div>")
|
| 205 |
+
south_button = gr.Button("โฌ๏ธ", size="sm")
|
| 206 |
+
gr.HTML("<div></div>")
|
| 207 |
+
|
| 208 |
+
# Quest log
|
| 209 |
+
status = gr.Markdown(
|
| 210 |
+
game_status_markdown(None, EMPTY_COLLECTION, START_POSITION)
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
# Discovery card + action buttons + chat
|
| 214 |
+
with gr.Row(equal_height=True):
|
| 215 |
+
with gr.Column(scale=2):
|
| 216 |
+
gr.Markdown("### ๐ Current Discovery")
|
| 217 |
+
discovery = gr.Markdown(mushroom_card(None))
|
| 218 |
+
with gr.Row():
|
| 219 |
+
study_button = gr.Button("๐ Study", variant="secondary")
|
| 220 |
+
collect_button = gr.Button("๐ Collect", variant="secondary")
|
| 221 |
+
with gr.Row():
|
| 222 |
+
whisper_button = gr.Button("๐ Follow Whisper", variant="secondary")
|
| 223 |
+
eat_button = gr.Button("๐ฝ๏ธ Eat?", variant="stop")
|
| 224 |
+
|
| 225 |
+
with gr.Column(scale=3):
|
| 226 |
+
gr.Markdown("### ๐ฌ Myco Chat")
|
| 227 |
+
chat = gr.Chatbot(
|
| 228 |
+
value=cast(Any, welcome_history()),
|
| 229 |
+
label="Myco",
|
| 230 |
+
height=400,
|
| 231 |
+
show_label=False,
|
| 232 |
+
)
|
| 233 |
+
with gr.Row():
|
| 234 |
+
prompt = gr.Textbox(
|
| 235 |
+
placeholder="Ask Myco anything about the forest...",
|
| 236 |
+
show_label=False,
|
| 237 |
+
scale=4,
|
| 238 |
+
lines=1,
|
| 239 |
)
|
| 240 |
+
ask_button = gr.Button("Ask ๐", variant="primary", scale=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
+
# โโ MYCODEX โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 243 |
with gr.Tab("๐ MycoDex"):
|
| 244 |
with gr.Row():
|
| 245 |
+
progress = gr.Markdown(progress_markdown(EMPTY_COLLECTION))
|
| 246 |
+
dex = gr.Markdown(dex_markdown(EMPTY_COLLECTION))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
+
# โโ WORLD MAP โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 249 |
with gr.Tab("๐บ๏ธ World Map"):
|
| 250 |
world_map = gr.HTML(world_map_markdown(EMPTY_COLLECTION))
|
| 251 |
|
| 252 |
+
# โโ GUIDE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 253 |
with gr.Tab("๐งญ Guide"):
|
| 254 |
gr.Markdown(GUIDE_MARKDOWN)
|
| 255 |
|
| 256 |
+
# โโ Event wiring โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 257 |
+
start_play_button.click(open_play_tab, outputs=[tabs])
|
| 258 |
|
| 259 |
search_button.click(
|
| 260 |
search_forest,
|
| 261 |
+
inputs=[collection, player_position],
|
| 262 |
+
outputs=[scene, status, discovery, current_mushroom, chat, dex, progress],
|
| 263 |
)
|
| 264 |
+
|
| 265 |
ask_button.click(
|
| 266 |
ask_companion,
|
| 267 |
+
inputs=[prompt, chat, current_mushroom, collection, player_position],
|
| 268 |
+
outputs=[prompt, chat],
|
| 269 |
+
)
|
| 270 |
+
prompt.submit(
|
| 271 |
+
ask_companion,
|
| 272 |
+
inputs=[prompt, chat, current_mushroom, collection, player_position],
|
| 273 |
+
outputs=[prompt, chat],
|
| 274 |
)
|
| 275 |
|
| 276 |
+
for direction, button in [
|
| 277 |
+
("north", north_button), ("south", south_button),
|
| 278 |
+
("west", west_button), ("east", east_button),
|
| 279 |
+
]:
|
|
|
|
|
|
|
| 280 |
button.click(
|
| 281 |
move_player,
|
| 282 |
+
inputs=[player_position, gr.State(direction), current_mushroom, collection],
|
| 283 |
+
outputs=[player_position, scene, status],
|
| 284 |
)
|
| 285 |
+
|
| 286 |
+
study_button.click(
|
| 287 |
+
study_discovery,
|
| 288 |
+
inputs=[current_mushroom, chat, collection, player_position],
|
| 289 |
+
outputs=[current_mushroom, scene, status, discovery, chat],
|
| 290 |
)
|
| 291 |
collect_button.click(
|
| 292 |
collect_discovery,
|
| 293 |
+
inputs=[current_mushroom, collection, chat, player_position],
|
| 294 |
+
outputs=[collection, scene, status, dex, world_map, chat, progress],
|
| 295 |
)
|
| 296 |
pick_button.click(
|
| 297 |
pick_discovery,
|
| 298 |
+
inputs=[current_mushroom, collection, chat, player_position],
|
| 299 |
+
outputs=[collection, current_mushroom, scene, status, discovery, dex, world_map, chat, progress],
|
| 300 |
)
|
| 301 |
whisper_button.click(
|
| 302 |
follow_story_whisper,
|
| 303 |
+
inputs=[current_mushroom, collection, chat, player_position],
|
| 304 |
+
outputs=[current_mushroom, scene, status, discovery, chat],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
)
|
| 306 |
eat_button.click(
|
| 307 |
block_unsafe_eating,
|
| 308 |
+
inputs=[current_mushroom, chat],
|
| 309 |
+
outputs=[chat],
|
| 310 |
)
|
| 311 |
|
| 312 |
+
demo.queue()
|
| 313 |
return demo
|
| 314 |
+
|