Spaces:
Sleeping

byte-vortex commited on
Commit
9fec91e
Β·
verified Β·
1 Parent(s): f9003ad

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/gradio_app.py +33 -19
ui/gradio_app.py CHANGED
@@ -11,19 +11,25 @@ from typing import Any, cast
11
  import gradio as gr
12
 
13
  from game.engine import (
14
- collect_current, discover_mushroom, eat_current,
15
  follow_whisper, hf_companion_status, myco_reply,
16
  pick_current, study_current, check_auto_pickup,
17
  get_myco_narrative, RARITY_WEIGHTS, POISONOUS,
18
  )
19
  from game.catalog import load_mushrooms
 
 
 
 
 
 
20
  from game.state import welcome_history
21
  from models.mushroom import Mushroom
22
 
23
  from ui.renderers import (
24
- dex_markdown, forest_scene, game_intro_markdown,
25
  game_status_markdown, hero_markdown, home_forest_markdown,
26
- mushroom_card, progress_markdown, world_map_markdown, bubble
27
  )
28
  from ui.interface import render_shroom_tab
29
 
@@ -42,7 +48,6 @@ _ROAM = {
42
  "ticks": 0,
43
  }
44
 
45
-
46
  def _roam_next_pos(x, y):
47
  candidates = []
48
  for dx, dy in [(0,-1),(0,1),(-1,0),(1,0)]:
@@ -205,7 +210,7 @@ def mushroom_card_from_state(current):
205
  def search_forest(position, collection):
206
  pos = _safe_pos(position)
207
  coll = list(collection or [])
208
- catalog = list(load_mushrooms())
209
 
210
  # Spawn 4-6 mushrooms at random grid positions
211
  count = random.randint(4, 6)
@@ -424,18 +429,14 @@ def build_app():
424
  active_mushrooms = gr.State([])
425
 
426
  gr.HTML(hero_markdown())
 
 
427
 
428
- status = gr.HTML()
429
-
430
- timer = gr.Timer(10)
431
-
432
- myco_bubble = gr.HTML()
433
 
434
- timer.tick(
435
- fn=lambda: bubble(get_myco_narrative()),
436
- outputs=myco_bubble
437
- )
438
-
439
 
440
  with gr.Tabs(selected="home") as tabs:
441
 
@@ -524,15 +525,21 @@ def build_app():
524
  # ── Event wiring ──
525
  start_play_button.click(open_play_tab, outputs=[tabs])
526
 
527
-
528
-
529
  # Roam timer β€” autonomous movement, pure Python
530
- timer.tick(
531
  fn=_autonomous_tick,
532
  inputs=[current_mushroom, collection, active_mushrooms, player_position],
533
  outputs=_move_outputs,
534
  )
535
 
 
 
 
 
 
 
 
 
536
  search_button.click(
537
  search_forest,
538
  inputs=[player_position, collection],
@@ -597,5 +604,12 @@ def build_app():
597
  )
598
 
599
  demo.queue()
 
 
 
 
 
 
 
 
600
  return demo
601
-
 
11
  import gradio as gr
12
 
13
  from game.engine import (
14
+ collect_current, eat_current,
15
  follow_whisper, hf_companion_status, myco_reply,
16
  pick_current, study_current, check_auto_pickup,
17
  get_myco_narrative, RARITY_WEIGHTS, POISONOUS,
18
  )
19
  from game.catalog import load_mushrooms
20
+ _CATALOG = None
21
+ def _get_catalog():
22
+ global _CATALOG
23
+ if _CATALOG is None:
24
+ _CATALOG = list(load_mushrooms())
25
+ return _CATALOG
26
  from game.state import welcome_history
27
  from models.mushroom import Mushroom
28
 
29
  from ui.renderers import (
30
+ dex_markdown, forest_scene, forest_scene_styles, game_intro_markdown,
31
  game_status_markdown, hero_markdown, home_forest_markdown,
32
+ mushroom_card, progress_markdown, world_map_markdown,
33
  )
34
  from ui.interface import render_shroom_tab
35
 
 
48
  "ticks": 0,
49
  }
50
 
 
51
  def _roam_next_pos(x, y):
52
  candidates = []
53
  for dx, dy in [(0,-1),(0,1),(-1,0),(1,0)]:
 
210
  def search_forest(position, collection):
211
  pos = _safe_pos(position)
212
  coll = list(collection or [])
213
+ catalog = _get_catalog()
214
 
215
  # Spawn 4-6 mushrooms at random grid positions
216
  count = random.randint(4, 6)
 
429
  active_mushrooms = gr.State([])
430
 
431
  gr.HTML(hero_markdown())
432
+ # Inject CSS once so .pos-x-y selectors work globally
433
+ gr.HTML(forest_scene_styles())
434
 
435
+ # Myco speech bubble β€” updated by timer
436
+ bubble_display = gr.HTML(myco_talking_markdown("The forest is waking up..."))
 
 
 
437
 
438
+ # Autonomous roam timer β€” every 3 seconds, pure Python movement
439
+ roam_timer = gr.Timer(3)
 
 
 
440
 
441
  with gr.Tabs(selected="home") as tabs:
442
 
 
525
  # ── Event wiring ──
526
  start_play_button.click(open_play_tab, outputs=[tabs])
527
 
 
 
528
  # Roam timer β€” autonomous movement, pure Python
529
+ roam_timer.tick(
530
  fn=_autonomous_tick,
531
  inputs=[current_mushroom, collection, active_mushrooms, player_position],
532
  outputs=_move_outputs,
533
  )
534
 
535
+ # Bubble timer β€” LLM narrative, separate so it doesn't block movement
536
+ bubble_timer = gr.Timer(12)
537
+ bubble_timer.tick(
538
+ fn=lambda cur: myco_talking_markdown(get_myco_narrative(cur)),
539
+ inputs=[current_mushroom],
540
+ outputs=[bubble_display],
541
+ )
542
+
543
  search_button.click(
544
  search_forest,
545
  inputs=[player_position, collection],
 
604
  )
605
 
606
  demo.queue()
607
+
608
+ # Auto-spawn mushrooms when app first loads
609
+ demo.load(
610
+ fn=search_forest,
611
+ inputs=[player_position, collection],
612
+ outputs=[scene, status, discovery, current_mushroom,
613
+ active_mushrooms, chat, dex, progress],
614
+ )
615
  return demo