Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- game/engine.py +6 -0
- ui/gradio_app.py +11 -0
game/engine.py
CHANGED
|
@@ -39,6 +39,11 @@ def discover_mushroom(collection=None, catalog=None):
|
|
| 39 |
current_collection = _safe_collection(collection)
|
| 40 |
mushroom = choose_mushroom(catalog)
|
| 41 |
current = mushroom.to_dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
history = welcome_history()
|
| 43 |
history.append(
|
| 44 |
_assistant_message(
|
|
@@ -89,6 +94,7 @@ def myco_reply(
|
|
| 89 |
else:
|
| 90 |
answer = "Let's explore first. The forest usually reveals a mushroom when we move slowly and listen."
|
| 91 |
|
|
|
|
| 92 |
next_history.append(_assistant_message(answer))
|
| 93 |
return "", next_history
|
| 94 |
|
|
|
|
| 39 |
current_collection = _safe_collection(collection)
|
| 40 |
mushroom = choose_mushroom(catalog)
|
| 41 |
current = mushroom.to_dict()
|
| 42 |
+
message = (
|
| 43 |
+
f"We found a {mushroom.name}! Ask me about it, then decide whether to "
|
| 44 |
+
f"eat, collect, or study it. Your MycoDex has {len(current_collection)} entries."
|
| 45 |
+
)
|
| 46 |
+
history = _append_assistant(welcome_history(), message)
|
| 47 |
history = welcome_history()
|
| 48 |
history.append(
|
| 49 |
_assistant_message(
|
|
|
|
| 94 |
else:
|
| 95 |
answer = "Let's explore first. The forest usually reveals a mushroom when we move slowly and listen."
|
| 96 |
|
| 97 |
+
return "", [*next_history, _assistant_message(answer)]
|
| 98 |
next_history.append(_assistant_message(answer))
|
| 99 |
return "", next_history
|
| 100 |
|
ui/gradio_app.py
CHANGED
|
@@ -4,6 +4,10 @@ Callbacks intentionally avoid complex type annotations because Hugging Face Spac
|
|
| 4 |
was serving an older broken annotated version of this file.
|
| 5 |
"""
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from __future__ import annotations
|
| 8 |
|
| 9 |
import gradio as gr
|
|
@@ -15,6 +19,7 @@ from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_car
|
|
| 15 |
|
| 16 |
|
| 17 |
# Keep Gradio callback signatures plain for Hugging Face Spaces parser stability.
|
|
|
|
| 18 |
def explore(collection: CollectionState) -> tuple[str, str, MushroomState, list[dict[str, str]], str, str]:
|
| 19 |
"""Gradio callback for the Start Exploring button."""
|
| 20 |
mushroom, current, history = discover_mushroom(collection)
|
|
@@ -28,6 +33,7 @@ def explore(collection: CollectionState) -> tuple[str, str, MushroomState, list[
|
|
| 28 |
)
|
| 29 |
|
| 30 |
|
|
|
|
| 31 |
def ask_myco(
|
| 32 |
message: str,
|
| 33 |
history: list[dict[str, str]],
|
|
@@ -37,6 +43,7 @@ def ask_myco(
|
|
| 37 |
return myco_reply(message, history, current)
|
| 38 |
|
| 39 |
|
|
|
|
| 40 |
def add_to_dex(
|
| 41 |
current: MushroomState | None,
|
| 42 |
collection: CollectionState,
|
|
@@ -53,6 +60,7 @@ def add_to_dex(
|
|
| 53 |
)
|
| 54 |
|
| 55 |
|
|
|
|
| 56 |
def study_mushroom(
|
| 57 |
current: MushroomState | None,
|
| 58 |
history: list[dict[str, str]],
|
|
@@ -68,6 +76,7 @@ def study_mushroom(
|
|
| 68 |
)
|
| 69 |
|
| 70 |
|
|
|
|
| 71 |
def eat_mushroom(
|
| 72 |
current: MushroomState | None,
|
| 73 |
history: list[dict[str, str]],
|
|
@@ -76,6 +85,7 @@ def eat_mushroom(
|
|
| 76 |
return eat_current(current, history)
|
| 77 |
|
| 78 |
|
|
|
|
| 79 |
def mushroom_card_from_state(current: MushroomState | None) -> str:
|
| 80 |
"""Render a mushroom card from Gradio state."""
|
| 81 |
if current is None:
|
|
@@ -83,6 +93,7 @@ def mushroom_card_from_state(current: MushroomState | None) -> str:
|
|
| 83 |
return mushroom_card(Mushroom.from_dict(current))
|
| 84 |
|
| 85 |
|
|
|
|
| 86 |
def build_app() -> gr.Blocks:
|
| 87 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 88 |
with gr.Blocks(title="Myco") as demo:
|
|
|
|
| 4 |
was serving an older broken annotated version of this file.
|
| 5 |
"""
|
| 6 |
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
from game.engine import collect_current, discover_mushroom, eat_current, myco_reply, study_current
|
| 10 |
+
from game.state import welcome_history
|
| 11 |
from __future__ import annotations
|
| 12 |
|
| 13 |
import gradio as gr
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
# Keep Gradio callback signatures plain for Hugging Face Spaces parser stability.
|
| 22 |
+
def explore(collection):
|
| 23 |
def explore(collection: CollectionState) -> tuple[str, str, MushroomState, list[dict[str, str]], str, str]:
|
| 24 |
"""Gradio callback for the Start Exploring button."""
|
| 25 |
mushroom, current, history = discover_mushroom(collection)
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
|
| 36 |
+
def ask_myco(message, history, current):
|
| 37 |
def ask_myco(
|
| 38 |
message: str,
|
| 39 |
history: list[dict[str, str]],
|
|
|
|
| 43 |
return myco_reply(message, history, current)
|
| 44 |
|
| 45 |
|
| 46 |
+
def add_to_dex(current, collection, history):
|
| 47 |
def add_to_dex(
|
| 48 |
current: MushroomState | None,
|
| 49 |
collection: CollectionState,
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
|
| 63 |
+
def study_mushroom(current, history, collection):
|
| 64 |
def study_mushroom(
|
| 65 |
current: MushroomState | None,
|
| 66 |
history: list[dict[str, str]],
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
|
| 79 |
+
def eat_mushroom(current, history):
|
| 80 |
def eat_mushroom(
|
| 81 |
current: MushroomState | None,
|
| 82 |
history: list[dict[str, str]],
|
|
|
|
| 85 |
return eat_current(current, history)
|
| 86 |
|
| 87 |
|
| 88 |
+
def mushroom_card_from_state(current):
|
| 89 |
def mushroom_card_from_state(current: MushroomState | None) -> str:
|
| 90 |
"""Render a mushroom card from Gradio state."""
|
| 91 |
if current is None:
|
|
|
|
| 93 |
return mushroom_card(Mushroom.from_dict(current))
|
| 94 |
|
| 95 |
|
| 96 |
+
def build_app():
|
| 97 |
def build_app() -> gr.Blocks:
|
| 98 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 99 |
with gr.Blocks(title="Myco") as demo:
|