Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/interface.py +37 -0
ui/interface.py
CHANGED
|
@@ -193,4 +193,41 @@ def render_shroom_tab():
|
|
| 193 |
# Notice how we completely removed all the markdown/buttons!
|
| 194 |
# Just the beautiful animation now.
|
| 195 |
gr.HTML(value=cute_mushroom_garden_html())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
# Notice how we completely removed all the markdown/buttons!
|
| 194 |
# Just the beautiful animation now.
|
| 195 |
gr.HTML(value=cute_mushroom_garden_html())
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
import gradio as gr
|
| 199 |
+
from game.engine import get_myco_narrative
|
| 200 |
+
|
| 201 |
+
def render_shroom_tab():
|
| 202 |
+
with gr.Blocks() as demo:
|
| 203 |
+
# The Canvas
|
| 204 |
+
gr.HTML("<canvas id='garden-canvas'></canvas>")
|
| 205 |
+
|
| 206 |
+
# The Narrative Container
|
| 207 |
+
# We wrap it in a Column so it stays positioned correctly
|
| 208 |
+
with gr.Column():
|
| 209 |
+
narrative = gr.Markdown(value=get_myco_narrative(), elem_id="narrative-box")
|
| 210 |
+
# A invisible button to trigger the refresh
|
| 211 |
+
refresh_btn = gr.Button("Refresh", visible=False)
|
| 212 |
+
|
| 213 |
+
# The Logic: Timer clicks the button, button calls the function
|
| 214 |
+
gr.Timer(10).tick(fn=get_myco_narrative, outputs=narrative)
|
| 215 |
+
|
| 216 |
+
# Ensure the canvas draws
|
| 217 |
+
gr.HTML("""
|
| 218 |
+
<script>
|
| 219 |
+
const canvas = document.getElementById('garden-canvas');
|
| 220 |
+
// Ensure size is set
|
| 221 |
+
canvas.width = canvas.parentElement.clientWidth;
|
| 222 |
+
canvas.height = 400;
|
| 223 |
+
const ctx = canvas.getContext('2d');
|
| 224 |
|
| 225 |
+
function drawLoop() {
|
| 226 |
+
// Your mushroom animation logic here
|
| 227 |
+
requestAnimationFrame(drawLoop);
|
| 228 |
+
}
|
| 229 |
+
drawLoop();
|
| 230 |
+
</script>
|
| 231 |
+
""")
|
| 232 |
+
return demo
|
| 233 |
+
|