Spaces:
Sleeping

byte-vortex commited on
Commit
75c2a83
·
verified ·
1 Parent(s): e776060

Deploy Myco from CI

Browse files
Files changed (2) hide show
  1. game/engine.py +4 -0
  2. ui/gradio_app.py +24 -0
game/engine.py CHANGED
@@ -7,6 +7,10 @@ from game.state import collection_contains, mushroom_from_state, welcome_history
7
 
8
 
9
  def choose_mushroom(catalog=None):
 
 
 
 
10
  from __future__ import annotations
11
 
12
  import random
 
7
 
8
 
9
  def choose_mushroom(catalog=None):
10
+ """Choose a mushroom discovery from the catalog."""
11
+ mushrooms = tuple(load_mushrooms() if catalog is None else catalog)
12
+ if not mushrooms:
13
+ raise ValueError("Myco needs at least one mushroom in the catalog.")
14
  from __future__ import annotations
15
 
16
  import random
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,20 @@ 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(collection: CollectionState) -> tuple[str, MushroomState, list[dict[str, str]], str, str]:
14
  """Gradio callback for the Start Exploring button."""
15
  mushroom, current, history = discover_mushroom(collection)
@@ -25,6 +43,7 @@ def ask_myco(
25
  return myco_reply(message, history, current)
26
 
27
 
 
28
  def add_to_dex(
29
  current: MushroomState | None,
30
  collection: CollectionState,
@@ -41,6 +60,7 @@ def add_to_dex(
41
  )
42
 
43
 
 
44
  def study_mushroom(
45
  current: MushroomState | None,
46
  history: list[dict[str, str]],
@@ -56,6 +76,7 @@ def study_mushroom(
56
  )
57
 
58
 
 
59
  def eat_mushroom(
60
  current: MushroomState | None,
61
  history: list[dict[str, str]],
@@ -64,6 +85,7 @@ def eat_mushroom(
64
  return eat_current(current, history)
65
 
66
 
 
67
  def mushroom_card_from_state(current: MushroomState | None) -> str:
68
  """Render a mushroom card from Gradio state."""
69
  if current is None:
@@ -71,6 +93,7 @@ def mushroom_card_from_state(current: MushroomState | None) -> str:
71
  return mushroom_card(Mushroom.from_dict(current))
72
 
73
 
 
74
  def build_app() -> gr.Blocks:
75
  """Build the Gradio interface for Hugging Face Spaces."""
76
  with gr.Blocks(title="Myco") as demo:
@@ -104,6 +127,7 @@ def build_app() -> gr.Blocks:
104
  explore_button.click(
105
  explore,
106
  inputs=[collection],
 
107
  outputs=[discovery, current_mushroom, chat, dex, progress],
108
  )
109
  ask_button.click(ask_myco, inputs=[prompt, chat, current_mushroom], outputs=[prompt, chat])
 
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
+ """Gradio callback for the Start Exploring button."""
19
+ mushroom, current, history = discover_mushroom(collection)
20
+ return (
21
+ forest_scene(current, collection),
22
+ mushroom_card(mushroom),
23
+ current,
24
+ history,
25
+ dex_markdown(collection),
26
+ progress_markdown(collection),
27
+ )
28
+
29
+
30
+ def ask_myco(message, history, current):
31
  def explore(collection: CollectionState) -> tuple[str, MushroomState, list[dict[str, str]], str, str]:
32
  """Gradio callback for the Start Exploring button."""
33
  mushroom, current, history = discover_mushroom(collection)
 
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:
 
127
  explore_button.click(
128
  explore,
129
  inputs=[collection],
130
+ outputs=[scene, discovery, current_mushroom, chat, dex, progress],
131
  outputs=[discovery, current_mushroom, chat, dex, progress],
132
  )
133
  ask_button.click(ask_myco, inputs=[prompt, chat, current_mushroom], outputs=[prompt, chat])