Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/interface.py +29 -33
ui/interface.py
CHANGED
|
@@ -1,37 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from game.engine import get_myco_narrative
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
</script>
|
| 33 |
-
""")
|
| 34 |
-
|
| 35 |
-
# Use an event to refresh the narrative every 10 seconds
|
| 36 |
-
gr.Timer(10).tick(get_myco_narrative, outputs=narrative_box)
|
| 37 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from game.engine import get_myco_narrative
|
| 3 |
|
| 4 |
+
def render_garden_page():
|
| 5 |
+
with gr.Blocks(css="""
|
| 6 |
+
#garden-canvas { width: 100%; height: 400px; background: #2a4c5e; border-radius: 12px; }
|
| 7 |
+
#narrative-box { font-family: 'Courier New', monospace; font-size: 16px; color: #4a3b32; text-align: center; padding: 20px; }
|
| 8 |
+
""") as demo:
|
| 9 |
+
|
| 10 |
+
# 1. The Canvas
|
| 11 |
+
garden_canvas = gr.HTML("<canvas id='garden-canvas'></canvas>")
|
| 12 |
+
|
| 13 |
+
# 2. The Narrative Text (Updated by the AI engine)
|
| 14 |
+
narrative = gr.Markdown(value=get_myco_narrative(), elem_id="narrative-box")
|
| 15 |
+
|
| 16 |
+
# 3. Refresh Timer (Updates every 10 seconds)
|
| 17 |
+
gr.Timer(10).tick(get_myco_narrative, outputs=narrative)
|
| 18 |
+
|
| 19 |
+
# 4. The Animation Logic (Pure JS injected once)
|
| 20 |
+
gr.HTML("""
|
| 21 |
+
<script>
|
| 22 |
+
const canvas = document.getElementById('garden-canvas');
|
| 23 |
+
const ctx = canvas.getContext('2d');
|
| 24 |
+
// ... [Insert your cute mushroom drawing loop here] ...
|
| 25 |
+
function drawLoop() {
|
| 26 |
+
// Your drawing logic
|
| 27 |
+
requestAnimationFrame(drawLoop);
|
| 28 |
+
}
|
| 29 |
+
drawLoop();
|
| 30 |
+
</script>
|
| 31 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
return demo
|