Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- tests/test_myco_core.py +5 -0
- ui/gradio_app.py +64 -0
tests/test_myco_core.py
CHANGED
|
@@ -96,6 +96,11 @@ class MycoCoreTests(unittest.TestCase):
|
|
| 96 |
self.assertEqual(duplicates, {}, f"duplicate functions in {path}")
|
| 97 |
self.assertNotIn(future_import, source, f"future import in {path}")
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
def test_gradio_app_avoids_fragile_multiline_return_tuples(self):
|
| 100 |
source = Path("ui/gradio_app.py").read_text()
|
| 101 |
self.assertNotIn("return (", source)
|
|
|
|
| 96 |
self.assertEqual(duplicates, {}, f"duplicate functions in {path}")
|
| 97 |
self.assertNotIn(future_import, source, f"future import in {path}")
|
| 98 |
|
| 99 |
+
def test_gradio_app_avoids_fragile_delimiters(self):
|
| 100 |
+
source = Path("ui/gradio_app.py").read_text()
|
| 101 |
+
self.assertNotIn("return (", source)
|
| 102 |
+
self.assertNotIn("[", source)
|
| 103 |
+
self.assertNotIn("]", source)
|
| 104 |
def test_gradio_app_avoids_fragile_multiline_return_tuples(self):
|
| 105 |
source = Path("ui/gradio_app.py").read_text()
|
| 106 |
self.assertNotIn("return (", source)
|
ui/gradio_app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
"""Gradio app composition for Myco."""
|
| 2 |
"""Gradio app composition for Myco.
|
| 3 |
|
|
@@ -10,6 +11,29 @@ import gradio as gr
|
|
| 10 |
from game.engine import collect_current, discover_mushroom, eat_current, myco_reply, study_current
|
| 11 |
from game.state import welcome_history
|
| 12 |
from models.mushroom import Mushroom
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from ui.renderers import (
|
| 14 |
dex_markdown,
|
| 15 |
forest_scene,
|
|
@@ -30,6 +54,12 @@ def mushroom_card_from_state(current):
|
|
| 30 |
def search_forest(collection):
|
| 31 |
"""Explore the forest and refresh every visible gameplay panel."""
|
| 32 |
mushroom, current, history = discover_mushroom(collection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
outputs = [
|
| 34 |
forest_scene(current, collection),
|
| 35 |
game_status_markdown(current, collection),
|
|
@@ -72,6 +102,11 @@ def ask_companion(message, history, current):
|
|
| 72 |
def collect_discovery(current, collection, history):
|
| 73 |
"""Collect the active mushroom and refresh collection-dependent panels."""
|
| 74 |
updated_collection, updated_history = collect_current(current, collection, history)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
outputs = [
|
| 76 |
def ask_myco(message, history, current):
|
| 77 |
def ask_myco(
|
|
@@ -106,6 +141,10 @@ def add_to_dex(
|
|
| 106 |
def study_discovery(current, history, collection):
|
| 107 |
"""Study the active mushroom and refresh the discovery card."""
|
| 108 |
updated_current, updated_history = study_current(current, history)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
outputs = [
|
| 110 |
def study_mushroom(current, history, collection):
|
| 111 |
def study_mushroom(
|
|
@@ -133,6 +172,9 @@ def block_unsafe_eating(current, history):
|
|
| 133 |
|
| 134 |
def build_app():
|
| 135 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
def eat_mushroom(current, history):
|
| 138 |
def eat_mushroom(
|
|
@@ -203,6 +245,15 @@ def build_app() -> gr.Blocks:
|
|
| 203 |
|
| 204 |
with gr.Tabs():
|
| 205 |
with gr.Tab("๐ Home"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
gr.Markdown(
|
| 207 |
"""
|
| 208 |
## Welcome to the Myco forest
|
|
@@ -234,6 +285,7 @@ def build_app() -> gr.Blocks:
|
|
| 234 |
with gr.Column(scale=3):
|
| 235 |
chat = gr.Chatbot(value=welcome_history(), label="Myco Chat", height=360)
|
| 236 |
with gr.Row():
|
|
|
|
| 237 |
prompt = gr.Textbox(
|
| 238 |
textbox_component = gr.Textbox
|
| 239 |
prompt = textbox_component(
|
|
@@ -245,6 +297,18 @@ def build_app() -> gr.Blocks:
|
|
| 245 |
|
| 246 |
with gr.Tab("๐ MycoDex"):
|
| 247 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
progress = gr.Markdown(progress_markdown([]), elem_id="progress-panel")
|
| 249 |
dex = gr.Markdown(dex_markdown([]), elem_id="mycodex")
|
| 250 |
|
|
|
|
| 1 |
+
"""Clean Gradio app composition for Myco."""
|
| 2 |
"""Gradio app composition for Myco."""
|
| 3 |
"""Gradio app composition for Myco.
|
| 4 |
|
|
|
|
| 11 |
from game.engine import collect_current, discover_mushroom, eat_current, myco_reply, study_current
|
| 12 |
from game.state import welcome_history
|
| 13 |
from models.mushroom import Mushroom
|
| 14 |
+
from ui.renderers import dex_markdown, forest_scene, game_status_markdown, hero_markdown, mushroom_card, progress_markdown
|
| 15 |
+
|
| 16 |
+
EMPTY_COLLECTION = tuple()
|
| 17 |
+
|
| 18 |
+
HOME_MARKDOWN = """
|
| 19 |
+
## Welcome to the Myco forest
|
| 20 |
+
|
| 21 |
+
Myco is a tiny forest game portal. Open **๐ฎ Play** to search for mushrooms,
|
| 22 |
+
visit **๐ MycoDex** to review progress, and use **๐งญ Guide** for the loop.
|
| 23 |
+
|
| 24 |
+
**Goal:** discover strange mushrooms, ask Myco what they might be, study them safely,
|
| 25 |
+
and build a magical MycoDex collection.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
GUIDE_MARKDOWN = """
|
| 29 |
+
## How to play
|
| 30 |
+
|
| 31 |
+
1. Go to **๐ฎ Play**.
|
| 32 |
+
2. Click **Start Exploring** to reveal a mushroom in the forest scene.
|
| 33 |
+
3. Ask Myco about the mushroom.
|
| 34 |
+
4. Choose **Study** for a safer hint, **Collect** for the MycoDex, or **Eat** to see Myco stop you.
|
| 35 |
+
5. Check **๐ MycoDex** to track discoveries and area unlocks.
|
| 36 |
+
"""
|
| 37 |
from ui.renderers import (
|
| 38 |
dex_markdown,
|
| 39 |
forest_scene,
|
|
|
|
| 54 |
def search_forest(collection):
|
| 55 |
"""Explore the forest and refresh every visible gameplay panel."""
|
| 56 |
mushroom, current, history = discover_mushroom(collection)
|
| 57 |
+
scene = forest_scene(current, collection)
|
| 58 |
+
status = game_status_markdown(current, collection)
|
| 59 |
+
card = mushroom_card(mushroom)
|
| 60 |
+
dex = dex_markdown(collection)
|
| 61 |
+
progress = progress_markdown(collection)
|
| 62 |
+
return scene, status, card, current, history, dex, progress
|
| 63 |
outputs = [
|
| 64 |
forest_scene(current, collection),
|
| 65 |
game_status_markdown(current, collection),
|
|
|
|
| 102 |
def collect_discovery(current, collection, history):
|
| 103 |
"""Collect the active mushroom and refresh collection-dependent panels."""
|
| 104 |
updated_collection, updated_history = collect_current(current, collection, history)
|
| 105 |
+
scene = forest_scene(current, updated_collection)
|
| 106 |
+
status = game_status_markdown(current, updated_collection)
|
| 107 |
+
dex = dex_markdown(updated_collection)
|
| 108 |
+
progress = progress_markdown(updated_collection)
|
| 109 |
+
return updated_collection, scene, status, dex, updated_history, progress
|
| 110 |
outputs = [
|
| 111 |
def ask_myco(message, history, current):
|
| 112 |
def ask_myco(
|
|
|
|
| 141 |
def study_discovery(current, history, collection):
|
| 142 |
"""Study the active mushroom and refresh the discovery card."""
|
| 143 |
updated_current, updated_history = study_current(current, history)
|
| 144 |
+
scene = forest_scene(updated_current, collection)
|
| 145 |
+
status = game_status_markdown(updated_current, collection)
|
| 146 |
+
card = mushroom_card_from_state(updated_current)
|
| 147 |
+
return updated_current, scene, status, card, updated_history
|
| 148 |
outputs = [
|
| 149 |
def study_mushroom(current, history, collection):
|
| 150 |
def study_mushroom(
|
|
|
|
| 172 |
|
| 173 |
def build_app():
|
| 174 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 175 |
+
with gr.Blocks(title="Myco") as demo:
|
| 176 |
+
current_mushroom = gr.State(None)
|
| 177 |
+
collection = gr.State(EMPTY_COLLECTION)
|
| 178 |
|
| 179 |
def eat_mushroom(current, history):
|
| 180 |
def eat_mushroom(
|
|
|
|
| 245 |
|
| 246 |
with gr.Tabs():
|
| 247 |
with gr.Tab("๐ Home"):
|
| 248 |
+
gr.Markdown(HOME_MARKDOWN)
|
| 249 |
+
|
| 250 |
+
with gr.Tab("๐ฎ Play"):
|
| 251 |
+
scene = gr.HTML(forest_scene(None, EMPTY_COLLECTION))
|
| 252 |
+
status = gr.Markdown(game_status_markdown(None, EMPTY_COLLECTION), elem_id="quest-log")
|
| 253 |
+
with gr.Row():
|
| 254 |
+
with gr.Column(scale=2):
|
| 255 |
+
discovery = gr.Markdown(mushroom_card(None), elem_id="discovery-card")
|
| 256 |
+
search_button = gr.Button("Start Exploring", variant="primary")
|
| 257 |
gr.Markdown(
|
| 258 |
"""
|
| 259 |
## Welcome to the Myco forest
|
|
|
|
| 285 |
with gr.Column(scale=3):
|
| 286 |
chat = gr.Chatbot(value=welcome_history(), label="Myco Chat", height=360)
|
| 287 |
with gr.Row():
|
| 288 |
+
prompt = gr.Textbox(label="Ask Myco", placeholder="Ask Myco about this mushroom", scale=4)
|
| 289 |
prompt = gr.Textbox(
|
| 290 |
textbox_component = gr.Textbox
|
| 291 |
prompt = textbox_component(
|
|
|
|
| 297 |
|
| 298 |
with gr.Tab("๐ MycoDex"):
|
| 299 |
with gr.Row():
|
| 300 |
+
progress = gr.Markdown(progress_markdown(EMPTY_COLLECTION), elem_id="progress-panel")
|
| 301 |
+
dex = gr.Markdown(dex_markdown(EMPTY_COLLECTION), elem_id="mycodex")
|
| 302 |
+
|
| 303 |
+
with gr.Tab("๐งญ Guide"):
|
| 304 |
+
gr.Markdown(GUIDE_MARKDOWN)
|
| 305 |
+
|
| 306 |
+
search_button.click(search_forest, inputs=(collection,), outputs=(scene, status, discovery, current_mushroom, chat, dex, progress))
|
| 307 |
+
ask_button.click(ask_companion, inputs=(prompt, chat, current_mushroom), outputs=(prompt, chat))
|
| 308 |
+
prompt.submit(ask_companion, inputs=(prompt, chat, current_mushroom), outputs=(prompt, chat))
|
| 309 |
+
collect_button.click(collect_discovery, inputs=(current_mushroom, collection, chat), outputs=(collection, scene, status, dex, chat, progress))
|
| 310 |
+
study_button.click(study_discovery, inputs=(current_mushroom, chat, collection), outputs=(current_mushroom, scene, status, discovery, chat))
|
| 311 |
+
eat_button.click(block_unsafe_eating, inputs=(current_mushroom, chat), outputs=(chat,))
|
| 312 |
progress = gr.Markdown(progress_markdown([]), elem_id="progress-panel")
|
| 313 |
dex = gr.Markdown(dex_markdown([]), elem_id="mycodex")
|
| 314 |
|