byte-vortex commited on
Commit
d85ba64
·
verified ·
1 Parent(s): 8e4b6c8

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/gradio_app.py +58 -0
ui/gradio_app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  """Gradio app composition for Myco.
2
 
3
  Callbacks intentionally avoid complex type annotations because Hugging Face Spaces
@@ -18,6 +19,7 @@ from models.mushroom import Mushroom
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]:
@@ -94,6 +96,44 @@ def mushroom_card_from_state(current: MushroomState | None) -> str:
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:
@@ -108,6 +148,8 @@ def build_app() -> gr.Blocks:
108
  """
109
  ## Welcome to the Myco forest
110
 
 
 
111
  Myco now plays more like a tiny game portal: open **🎮 Play** to explore,
112
  visit **📖 MycoDex** to review progress, and use **🧭 Guide** when you need a reminder.
113
 
@@ -123,6 +165,7 @@ def build_app() -> gr.Blocks:
123
  with gr.Column(scale=2):
124
  discovery = gr.Markdown(mushroom_card(None), elem_id="discovery-card")
125
  with gr.Row():
 
126
  explore_button = gr.Button("Start Exploring", variant="primary")
127
  with gr.Row():
128
  eat_button = gr.Button("Eat")
@@ -131,6 +174,7 @@ def build_app() -> gr.Blocks:
131
  with gr.Column(scale=3):
132
  chat = gr.Chatbot(value=welcome_history(), label="Myco Chat", height=360)
133
  with gr.Row():
 
134
  textbox_component = gr.Textbox
135
  prompt = textbox_component(
136
  label="Ask Myco",
@@ -157,6 +201,15 @@ def build_app() -> gr.Blocks:
157
  """
158
  )
159
 
 
 
 
 
 
 
 
 
 
160
  explore_button.click(
161
  begin_forest_search,
162
  explore,
@@ -171,6 +224,11 @@ def build_app() -> gr.Blocks:
171
  outputs=[collection, scene, dex, chat, progress],
172
  )
173
  study_button.click(
 
 
 
 
 
174
  study_mushroom,
175
  inputs=[current_mushroom, chat, collection],
176
  outputs=[current_mushroom, scene, discovery, chat],
 
1
+ """Gradio app composition for Myco."""
2
  """Gradio app composition for Myco.
3
 
4
  Callbacks intentionally avoid complex type annotations because Hugging Face Spaces
 
19
  from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_card, progress_markdown
20
 
21
 
22
+ def mushroom_card_from_state(current):
23
  # Keep callback signatures plain for Hugging Face Spaces parser stability.
24
  def begin_forest_search(collection):
25
  def explore(collection: CollectionState) -> tuple[str, str, MushroomState, list[dict[str, str]], str, str]:
 
96
 
97
 
98
  def build_app():
99
+ """Build the Gradio interface for Hugging Face Spaces."""
100
+
101
+ def search_forest(collection):
102
+ mushroom, current, history = discover_mushroom(collection)
103
+ return (
104
+ forest_scene(current, collection),
105
+ mushroom_card(mushroom),
106
+ current,
107
+ history,
108
+ dex_markdown(collection),
109
+ progress_markdown(collection),
110
+ )
111
+
112
+ def ask_companion(message, history, current):
113
+ return myco_reply(message, history, current)
114
+
115
+ def collect_discovery(current, collection, history):
116
+ updated_collection, updated_history = collect_current(current, collection, history)
117
+ return (
118
+ updated_collection,
119
+ forest_scene(current, updated_collection),
120
+ dex_markdown(updated_collection),
121
+ updated_history,
122
+ progress_markdown(updated_collection),
123
+ )
124
+
125
+ def study_discovery(current, history, collection):
126
+ updated_current, updated_history = study_current(current, history)
127
+ return (
128
+ updated_current,
129
+ forest_scene(updated_current, collection),
130
+ mushroom_card_from_state(updated_current),
131
+ updated_history,
132
+ )
133
+
134
+ def block_unsafe_eating(current, history):
135
+ return eat_current(current, history)
136
+
137
  def build_app() -> gr.Blocks:
138
  """Build the Gradio interface for Hugging Face Spaces."""
139
  with gr.Blocks(title="Myco") as demo:
 
148
  """
149
  ## Welcome to the Myco forest
150
 
151
+ Myco is a tiny forest game portal. Open **🎮 Play** to search for mushrooms,
152
+ visit **📖 MycoDex** to review progress, and use **🧭 Guide** for the loop.
153
  Myco now plays more like a tiny game portal: open **🎮 Play** to explore,
154
  visit **📖 MycoDex** to review progress, and use **🧭 Guide** when you need a reminder.
155
 
 
165
  with gr.Column(scale=2):
166
  discovery = gr.Markdown(mushroom_card(None), elem_id="discovery-card")
167
  with gr.Row():
168
+ search_button = gr.Button("Start Exploring", variant="primary")
169
  explore_button = gr.Button("Start Exploring", variant="primary")
170
  with gr.Row():
171
  eat_button = gr.Button("Eat")
 
174
  with gr.Column(scale=3):
175
  chat = gr.Chatbot(value=welcome_history(), label="Myco Chat", height=360)
176
  with gr.Row():
177
+ prompt = gr.Textbox(
178
  textbox_component = gr.Textbox
179
  prompt = textbox_component(
180
  label="Ask Myco",
 
201
  """
202
  )
203
 
204
+ search_button.click(
205
+ search_forest,
206
+ inputs=[collection],
207
+ outputs=[scene, discovery, current_mushroom, chat, dex, progress],
208
+ )
209
+ ask_button.click(ask_companion, inputs=[prompt, chat, current_mushroom], outputs=[prompt, chat])
210
+ prompt.submit(ask_companion, inputs=[prompt, chat, current_mushroom], outputs=[prompt, chat])
211
+ collect_button.click(
212
+ collect_discovery,
213
  explore_button.click(
214
  begin_forest_search,
215
  explore,
 
224
  outputs=[collection, scene, dex, chat, progress],
225
  )
226
  study_button.click(
227
+ study_discovery,
228
+ inputs=[current_mushroom, chat, collection],
229
+ outputs=[current_mushroom, scene, discovery, chat],
230
+ )
231
+ eat_button.click(block_unsafe_eating, inputs=[current_mushroom, chat], outputs=[chat])
232
  study_mushroom,
233
  inputs=[current_mushroom, chat, collection],
234
  outputs=[current_mushroom, scene, discovery, chat],