Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- 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 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 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 |
|