Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/gradio_app.py +17 -0
ui/gradio_app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
"""Gradio app composition for Myco."""
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -10,6 +14,7 @@ from models.mushroom import Mushroom
|
|
| 10 |
from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_card, progress_markdown
|
| 11 |
|
| 12 |
|
|
|
|
| 13 |
def explore(
|
| 14 |
collection: CollectionState,
|
| 15 |
) -> tuple[str, str, MushroomState, list[dict[str, str]], str, str]:
|
|
@@ -23,6 +28,9 @@ def explore(
|
|
| 23 |
dex_markdown(collection),
|
| 24 |
progress_markdown(collection),
|
| 25 |
)
|
|
|
|
|
|
|
|
|
|
| 26 |
from ui.renderers import dex_markdown, hero_markdown, mushroom_card, progress_markdown
|
| 27 |
|
| 28 |
|
|
@@ -41,6 +49,7 @@ def ask_myco(
|
|
| 41 |
return myco_reply(message, history, current)
|
| 42 |
|
| 43 |
|
|
|
|
| 44 |
def add_to_dex(
|
| 45 |
current: MushroomState | None,
|
| 46 |
collection: CollectionState,
|
|
@@ -55,6 +64,9 @@ def add_to_dex(
|
|
| 55 |
updated_history,
|
| 56 |
progress_markdown(updated_collection),
|
| 57 |
)
|
|
|
|
|
|
|
|
|
|
| 58 |
) -> tuple[CollectionState, str, list[dict[str, str]], str]:
|
| 59 |
"""Gradio callback for collecting the current mushroom."""
|
| 60 |
updated_collection, updated_history = collect_current(current, collection, history)
|
|
@@ -74,6 +86,9 @@ def study_mushroom(
|
|
| 74 |
mushroom_card_from_state(updated_current),
|
| 75 |
updated_history,
|
| 76 |
)
|
|
|
|
|
|
|
|
|
|
| 77 |
) -> tuple[MushroomState | None, str, list[dict[str, str]]]:
|
| 78 |
"""Gradio callback for studying the current mushroom."""
|
| 79 |
updated_current, updated_history = study_current(current, history)
|
|
@@ -88,6 +103,7 @@ def eat_mushroom(
|
|
| 88 |
return eat_current(current, history)
|
| 89 |
|
| 90 |
|
|
|
|
| 91 |
def mushroom_card_from_state(current: MushroomState | None) -> str:
|
| 92 |
"""Render a mushroom card from Gradio state."""
|
| 93 |
if current is None:
|
|
@@ -95,6 +111,7 @@ def mushroom_card_from_state(current: MushroomState | None) -> str:
|
|
| 95 |
return mushroom_card(Mushroom.from_dict(current))
|
| 96 |
|
| 97 |
|
|
|
|
| 98 |
def build_app() -> gr.Blocks:
|
| 99 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 100 |
with gr.Blocks(title="Myco") as demo:
|
|
|
|
| 1 |
"""Gradio app composition for Myco."""
|
| 2 |
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from game.engine import collect_current, discover_mushroom, eat_current, myco_reply, study_current
|
| 6 |
+
from game.state import welcome_history
|
| 7 |
from __future__ import annotations
|
| 8 |
|
| 9 |
import gradio as gr
|
|
|
|
| 14 |
from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_card, progress_markdown
|
| 15 |
|
| 16 |
|
| 17 |
+
def explore(collection):
|
| 18 |
def explore(
|
| 19 |
collection: CollectionState,
|
| 20 |
) -> tuple[str, str, MushroomState, list[dict[str, str]], str, str]:
|
|
|
|
| 28 |
dex_markdown(collection),
|
| 29 |
progress_markdown(collection),
|
| 30 |
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def ask_myco(message, history, current):
|
| 34 |
from ui.renderers import dex_markdown, hero_markdown, mushroom_card, progress_markdown
|
| 35 |
|
| 36 |
|
|
|
|
| 49 |
return myco_reply(message, history, current)
|
| 50 |
|
| 51 |
|
| 52 |
+
def add_to_dex(current, collection, history):
|
| 53 |
def add_to_dex(
|
| 54 |
current: MushroomState | None,
|
| 55 |
collection: CollectionState,
|
|
|
|
| 64 |
updated_history,
|
| 65 |
progress_markdown(updated_collection),
|
| 66 |
)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def study_mushroom(current, history, collection):
|
| 70 |
) -> tuple[CollectionState, str, list[dict[str, str]], str]:
|
| 71 |
"""Gradio callback for collecting the current mushroom."""
|
| 72 |
updated_collection, updated_history = collect_current(current, collection, history)
|
|
|
|
| 86 |
mushroom_card_from_state(updated_current),
|
| 87 |
updated_history,
|
| 88 |
)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def eat_mushroom(current, history):
|
| 92 |
) -> tuple[MushroomState | None, str, list[dict[str, str]]]:
|
| 93 |
"""Gradio callback for studying the current mushroom."""
|
| 94 |
updated_current, updated_history = study_current(current, history)
|
|
|
|
| 103 |
return eat_current(current, history)
|
| 104 |
|
| 105 |
|
| 106 |
+
def mushroom_card_from_state(current):
|
| 107 |
def mushroom_card_from_state(current: MushroomState | None) -> str:
|
| 108 |
"""Render a mushroom card from Gradio state."""
|
| 109 |
if current is None:
|
|
|
|
| 111 |
return mushroom_card(Mushroom.from_dict(current))
|
| 112 |
|
| 113 |
|
| 114 |
+
def build_app():
|
| 115 |
def build_app() -> gr.Blocks:
|
| 116 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 117 |
with gr.Blocks(title="Myco") as demo:
|