Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- game/engine.py +4 -0
- ui/gradio_app.py +15 -0
game/engine.py
CHANGED
|
@@ -27,6 +27,7 @@ def discover_mushroom(collection=None, catalog=None):
|
|
| 27 |
return mushroom, current, history
|
| 28 |
|
| 29 |
|
|
|
|
| 30 |
def myco_reply(message=None, history=None, current=None):
|
| 31 |
from __future__ import annotations
|
| 32 |
|
|
@@ -97,6 +98,9 @@ def myco_reply(
|
|
| 97 |
return "", [*next_history, _assistant_message(answer)]
|
| 98 |
|
| 99 |
|
|
|
|
|
|
|
|
|
|
| 100 |
def collect_current(current=None, collection=None, history=None):
|
| 101 |
"""Add the current mushroom to the MycoDex if it is not already collected."""
|
| 102 |
current_collection = _safe_collection(collection)
|
|
|
|
| 27 |
return mushroom, current, history
|
| 28 |
|
| 29 |
|
| 30 |
+
def companion_reply(message=None, history=None, current=None):
|
| 31 |
def myco_reply(message=None, history=None, current=None):
|
| 32 |
from __future__ import annotations
|
| 33 |
|
|
|
|
| 98 |
return "", [*next_history, _assistant_message(answer)]
|
| 99 |
|
| 100 |
|
| 101 |
+
myco_reply = companion_reply
|
| 102 |
+
|
| 103 |
+
|
| 104 |
def collect_current(current=None, collection=None, history=None):
|
| 105 |
"""Add the current mushroom to the MycoDex if it is not already collected."""
|
| 106 |
current_collection = _safe_collection(collection)
|
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
|
|
@@ -14,6 +18,8 @@ from models.mushroom import Mushroom
|
|
| 14 |
from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_card, progress_markdown
|
| 15 |
|
| 16 |
|
|
|
|
|
|
|
| 17 |
def explore(collection: CollectionState) -> tuple[str, str, MushroomState, list[dict[str, str]], str, str]:
|
| 18 |
"""Gradio callback for the Start Exploring button."""
|
| 19 |
mushroom, current, history = discover_mushroom(collection)
|
|
@@ -27,6 +33,7 @@ def explore(collection: CollectionState) -> tuple[str, str, MushroomState, list[
|
|
| 27 |
)
|
| 28 |
|
| 29 |
|
|
|
|
| 30 |
def ask_myco(
|
| 31 |
message: str,
|
| 32 |
history: list[dict[str, str]],
|
|
@@ -36,6 +43,7 @@ def ask_myco(
|
|
| 36 |
return myco_reply(message, history, current)
|
| 37 |
|
| 38 |
|
|
|
|
| 39 |
def add_to_dex(
|
| 40 |
current: MushroomState | None,
|
| 41 |
collection: CollectionState,
|
|
@@ -52,6 +60,7 @@ def add_to_dex(
|
|
| 52 |
)
|
| 53 |
|
| 54 |
|
|
|
|
| 55 |
def study_mushroom(
|
| 56 |
current: MushroomState | None,
|
| 57 |
history: list[dict[str, str]],
|
|
@@ -67,6 +76,7 @@ def study_mushroom(
|
|
| 67 |
)
|
| 68 |
|
| 69 |
|
|
|
|
| 70 |
def eat_mushroom(
|
| 71 |
current: MushroomState | None,
|
| 72 |
history: list[dict[str, str]],
|
|
@@ -75,6 +85,7 @@ def eat_mushroom(
|
|
| 75 |
return eat_current(current, history)
|
| 76 |
|
| 77 |
|
|
|
|
| 78 |
def mushroom_card_from_state(current: MushroomState | None) -> str:
|
| 79 |
"""Render a mushroom card from Gradio state."""
|
| 80 |
if current is None:
|
|
@@ -82,12 +93,15 @@ def mushroom_card_from_state(current: MushroomState | None) -> str:
|
|
| 82 |
return mushroom_card(Mushroom.from_dict(current))
|
| 83 |
|
| 84 |
|
|
|
|
| 85 |
def build_app() -> gr.Blocks:
|
| 86 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 87 |
with gr.Blocks(title="Myco") as demo:
|
| 88 |
current_mushroom = gr.State(None)
|
| 89 |
collection = gr.State([])
|
| 90 |
|
|
|
|
|
|
|
| 91 |
with gr.Tabs():
|
| 92 |
with gr.Tab("🏠 Home"):
|
| 93 |
gr.Markdown(
|
|
@@ -144,6 +158,7 @@ def build_app() -> gr.Blocks:
|
|
| 144 |
)
|
| 145 |
|
| 146 |
explore_button.click(
|
|
|
|
| 147 |
explore,
|
| 148 |
inputs=[collection],
|
| 149 |
outputs=[scene, discovery, current_mushroom, chat, dex, progress],
|
|
|
|
| 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
|
|
|
|
| 18 |
from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_card, progress_markdown
|
| 19 |
|
| 20 |
|
| 21 |
+
# Keep callback signatures plain for Hugging Face Spaces parser stability.
|
| 22 |
+
def begin_forest_search(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:
|
| 100 |
current_mushroom = gr.State(None)
|
| 101 |
collection = gr.State([])
|
| 102 |
|
| 103 |
+
gr.HTML(hero_markdown())
|
| 104 |
+
|
| 105 |
with gr.Tabs():
|
| 106 |
with gr.Tab("🏠 Home"):
|
| 107 |
gr.Markdown(
|
|
|
|
| 158 |
)
|
| 159 |
|
| 160 |
explore_button.click(
|
| 161 |
+
begin_forest_search,
|
| 162 |
explore,
|
| 163 |
inputs=[collection],
|
| 164 |
outputs=[scene, discovery, current_mushroom, chat, dex, progress],
|