Spaces:
Sleeping

byte-vortex commited on
Commit
5928c11
·
verified ·
1 Parent(s): f3d4702

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/interface.py +36 -52
ui/interface.py CHANGED
@@ -176,60 +176,44 @@ def cute_mushroom_garden_html() -> str:
176
  </html>
177
  """
178
 
179
- # Safely escape the HTML
180
- escaped_srcdoc = html.escape(iframe_content)
181
-
182
- # Return a clean, borderless container
183
- return f'''
184
- <div style="width: 100%; height: 500px; border-radius: 16px; overflow: hidden; border: 4px solid #f8c8dc; box-shadow: 0 8px 32px rgba(0,0,0,0.15);">
185
- <iframe
186
- srcdoc="{escaped_srcdoc}"
187
- style="width: 100%; height: 100%; border: none;"
188
- scrolling="no">
189
- </iframe>
190
- </div>
191
- '''
192
 
193
  def render_shroom_tab():
194
- """
195
- Build the Myco tab UI. This version is self-contained and uses inline lambdas
196
- for gr.load so it won't require external poll_scene/poll_myco_bubble_html names.
197
- """
198
- scene_html = gr.HTML()
199
- thought_html = gr.HTML() # use HTML so markup is not escaped
200
- dex_md = gr.Markdown()
201
-
202
- # Local helper to build the scene HTML from STATE safely
203
- def _get_scene_html():
204
- try:
205
- with _STATE_LOCK:
206
- state_copy = copy.deepcopy(STATE)
207
- except Exception:
208
- state_copy = {}
209
- state_for_renderer = {
210
- "active_mushrooms": state_copy.get("active_mushrooms", []),
211
- "score_total": state_copy.get("score_total", 0),
212
- "health": state_copy.get("health", 3),
213
- "event_emoji": "✨",
214
- "event_title": state_copy.get("thought", ""),
215
- "mystery_title": "The Wrong Memory",
216
- "picked": "No",
217
- "game_over": "No",
218
- }
219
- return forest_scene(state_for_renderer, state_copy.get("collection", []), state_copy.get("position"))
220
-
221
- # Bind polling: update scene and thought periodically (inline lambdas avoid NameError)
222
- gr.load(fn=lambda: _get_scene_html(), outputs=scene_html, every=1.5)
223
- gr.load(fn=lambda: myco_talking_markdown(STATE.get("thought", "")), outputs=thought_html, every=1.5)
224
-
225
- # Optional: dex button
226
- def show_dex():
227
- with _STATE_LOCK:
228
- coll = copy.deepcopy(STATE.get("collection", []))
229
- return dex_markdown(coll) if coll else EMPTY_DEX
230
-
231
- show_dex_btn = gr.Button("Show MycoDex")
232
- show_dex_btn.click(fn=show_dex, inputs=None, outputs=dex_md)
233
 
234
  return scene_html, thought_html, dex_md
235
 
 
176
  </html>
177
  """
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  def render_shroom_tab():
181
+ # 1. Assign the block to 'demo' so it can be returned
182
+ with gr.Blocks() as demo:
183
+ with gr.Tabs():
184
+ with gr.Tab("✨ Magic Mushroom Garden"):
185
+ # The pure animation
186
+ gr.HTML(value=cute_mushroom_garden_html())
187
+
188
+ # Subtle attribution
189
+ gr.Markdown(
190
+ "<sub>*Story generated by Myco AI*</sub>",
191
+ elem_id="ai-attribution"
192
+ )
193
+
194
+ # 2. Define the narrative component ONCE (use HTML so we can render the Myco bubble markup)
195
+ narrative = gr.HTML(
196
+ value=myco_talking_markdown("Myco is searching for a story hidden in the moss..."),
197
+ elem_id="narrative-card"
198
+ )
199
+
200
+ # 3. Timer updates the ONE narrative component periodically.
201
+ # Use a short interval so the UI feels responsive; the function called
202
+ # will fetch/clean the latest narrative and return HTML for the bubble.
203
+ # We wrap get_myco_narrative with myco_talking_markdown to ensure HTML bubble output.
204
+ def _narrative_tick():
205
+ try:
206
+ raw = get_myco_narrative()
207
+ except Exception:
208
+ raw = "The forest feels deep today... ✨"
209
+ return myco_talking_markdown(raw)
210
+
211
+ # Poll every 1.5 seconds for a fresh narrative
212
+ gr.Timer(1.5).tick(fn=_narrative_tick, outputs=narrative)
213
+
214
+ return demo
215
+
216
+
 
 
 
217
 
218
  return scene_html, thought_html, dex_md
219