byte-vortex commited on
Commit
4b5c4ea
·
verified ·
1 Parent(s): d2c9128

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/interface.py +67 -203
ui/interface.py CHANGED
@@ -1,206 +1,10 @@
1
  import gradio as gr
2
  import html
3
-
4
- def cute_mushroom_garden_html() -> str:
5
- """
6
- Pure iframe srcdoc implementation of a cute mushroom garden.
7
- Generates happy, blinking mushrooms that grow, sway, and shrink.
8
- """
9
- iframe_content = """
10
- <!DOCTYPE html>
11
- <html>
12
- <head>
13
- <style>
14
- body {
15
- margin: 0;
16
- overflow: hidden;
17
- /* Soft magical forest background */
18
- background: linear-gradient(180deg, #1a2b4c 0%, #2a4c5e 50%, #4a7c59 100%);
19
- }
20
- canvas { display: block; }
21
- </style>
22
- </head>
23
- <body>
24
- <canvas id="cute-canvas"></canvas>
25
- <script>
26
- const canvas = document.getElementById('cute-canvas');
27
- const ctx = canvas.getContext('2d');
28
-
29
- function resize() {
30
- canvas.width = window.innerWidth;
31
- canvas.height = window.innerHeight;
32
- }
33
- window.addEventListener('resize', resize);
34
- resize();
35
-
36
- const mushrooms = [];
37
- const fireflies = [];
38
-
39
- // Helper to draw a single cute mushroom
40
- function drawMushroom(m, time) {
41
- ctx.save();
42
- ctx.translate(m.x, m.y);
43
-
44
- // Bouncing and swaying math
45
- const sway = Math.sin(time * 0.002 + m.phase) * 0.1;
46
- const bounce = Math.sin(time * 0.005 + m.phase) * 0.05 + 1;
47
-
48
- ctx.rotate(sway);
49
- ctx.scale(m.currentSize, m.currentSize * bounce);
50
-
51
- // 1. Draw Stem
52
- ctx.fillStyle = '#fff4e6';
53
- ctx.beginPath();
54
- ctx.roundRect(-12, 0, 24, 35, 10);
55
- ctx.fill();
56
-
57
- // 2. Draw Cute Face
58
- ctx.fillStyle = '#4a3b32';
59
- const isBlinking = (time % m.blinkInterval) < 150;
60
-
61
- if (isBlinking) {
62
- // Closed eyes (wincing/blinking)
63
- ctx.fillRect(-7, 12, 4, 2);
64
- ctx.fillRect(3, 12, 4, 2);
65
- } else {
66
- // Open eyes
67
- ctx.beginPath(); ctx.arc(-5, 12, 2.5, 0, Math.PI*2); ctx.fill();
68
- ctx.beginPath(); ctx.arc(5, 12, 2.5, 0, Math.PI*2); ctx.fill();
69
- }
70
-
71
- // Tiny smile
72
- ctx.strokeStyle = '#4a3b32';
73
- ctx.lineWidth = 1.5;
74
- ctx.beginPath();
75
- ctx.arc(0, 15, 3, 0, Math.PI, false);
76
- ctx.stroke();
77
-
78
- // Blush
79
- ctx.fillStyle = 'rgba(255, 150, 150, 0.5)';
80
- ctx.beginPath(); ctx.arc(-9, 16, 3, 0, Math.PI*2); ctx.fill();
81
- ctx.beginPath(); ctx.arc(9, 16, 3, 0, Math.PI*2); ctx.fill();
82
-
83
- // 3. Draw Cap
84
- ctx.fillStyle = `hsl(${m.hue}, 80%, 75%)`; // Soft pastel colors
85
- ctx.beginPath();
86
- ctx.moveTo(-35, 5);
87
- // Bezier curves make it look like a puffy umbrella
88
- ctx.bezierCurveTo(-35, -30, 35, -30, 35, 5);
89
- ctx.bezierCurveTo(35, 15, -35, 15, -35, 5);
90
- ctx.fill();
91
-
92
- // Cap Shadow/Detail
93
- ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
94
- ctx.beginPath(); ctx.arc(-15, -12, 6, 0, Math.PI*2); ctx.fill();
95
- ctx.beginPath(); ctx.arc(12, -8, 4, 0, Math.PI*2); ctx.fill();
96
- ctx.beginPath(); ctx.arc(0, -18, 5, 0, Math.PI*2); ctx.fill();
97
-
98
- ctx.restore();
99
- }
100
-
101
- function animate(time) {
102
- ctx.clearRect(0, 0, canvas.width, canvas.height);
103
-
104
- // --- Fireflies Logic ---
105
- if (Math.random() < 0.1 && fireflies.length < 50) {
106
- fireflies.push({
107
- x: Math.random() * canvas.width,
108
- y: canvas.height + 10,
109
- size: Math.random() * 2 + 1,
110
- speed: Math.random() * 1 + 0.5,
111
- wobble: Math.random() * Math.PI * 2
112
- });
113
- }
114
-
115
- ctx.fillStyle = '#fffae6';
116
- for (let i = fireflies.length - 1; i >= 0; i--) {
117
- let f = fireflies[i];
118
- f.y -= f.speed;
119
- f.x += Math.sin(time * 0.002 + f.wobble) * 0.5;
120
-
121
- ctx.globalAlpha = Math.sin(time * 0.005 + f.wobble) * 0.5 + 0.5;
122
- ctx.beginPath();
123
- ctx.arc(f.x, f.y, f.size, 0, Math.PI * 2);
124
- ctx.fill();
125
-
126
- if (f.y < -10) fireflies.splice(i, 1);
127
- }
128
- ctx.globalAlpha = 1.0;
129
-
130
- // --- Mushroom Logic ---
131
- // Randomly spawn new mushrooms
132
- if (Math.random() < 0.02 && mushrooms.length < 35) {
133
- mushrooms.push({
134
- x: Math.random() * canvas.width,
135
- y: (canvas.height * 0.4) + (Math.random() * canvas.height * 0.6), // Spawn in bottom 60%
136
- targetSize: Math.random() * 1.5 + 0.8,
137
- currentSize: 0,
138
- hue: Math.random() * 360,
139
- phase: Math.random() * Math.PI * 2,
140
- blinkInterval: Math.floor(Math.random() * 3000) + 2000,
141
- life: Math.random() * 500 + 300 // How long they stay before shrinking
142
- });
143
- }
144
-
145
- // Sort mushrooms by Y coordinate so closer ones draw on top (Depth sorting)
146
- mushrooms.sort((a, b) => a.y - b.y);
147
-
148
- for (let i = mushrooms.length - 1; i >= 0; i--) {
149
- let m = mushrooms[i];
150
-
151
- m.life--;
152
- if (m.life < 0) {
153
- m.targetSize = 0; // Shrink away
154
- }
155
-
156
- // Smoothly grow or shrink
157
- m.currentSize += (m.targetSize - m.currentSize) * 0.05;
158
-
159
- drawMushroom(m, time);
160
-
161
- // Remove if totally shrunk
162
- if (m.life < 0 && m.currentSize < 0.05) {
163
- mushrooms.splice(i, 1);
164
- }
165
- }
166
-
167
- requestAnimationFrame(animate);
168
- }
169
-
170
- requestAnimationFrame(animate);
171
- </script>
172
- </body>
173
- </html>
174
- """
175
-
176
- # Safely escape the HTML
177
- escaped_srcdoc = html.escape(iframe_content)
178
-
179
- # Return a clean, borderless container
180
- return f'''
181
- <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);">
182
- <iframe
183
- srcdoc="{escaped_srcdoc}"
184
- style="width: 100%; height: 100%; border: none;"
185
- scrolling="no">
186
- </iframe>
187
- </div>
188
- '''
189
-
190
- def render_shroom_tab():
191
- with gr.Tabs():
192
- with gr.Tab("✨ Magic Mushroom Garden"):
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(css="""
203
- #garden-canvas { width: 100%; height: 400px; background: #050a08; border-radius: 12px; }
204
  #narrative-box {
205
  font-family: 'Courier New', monospace;
206
  font-size: 15px;
@@ -210,23 +14,83 @@ def render_shroom_tab():
210
  border-radius: 8px;
211
  border: 1px solid rgba(82, 255, 107, 0.3);
212
  text-align: center;
 
213
  }
214
  """) as demo:
215
 
216
- # 1. The Animation
217
  gr.HTML("<canvas id='garden-canvas'></canvas>")
218
 
219
- # 2. The Narrative (Directly populated by the Discovery Engine)
220
  narrative = gr.Markdown(value="Waiting for the forest to wake...", elem_id="narrative-box")
221
 
222
- # 3. Timer (Auto-triggers discovery event)
223
  gr.Timer(20).tick(fn=get_myco_narrative, outputs=narrative)
224
 
225
- # 4. Animation Script
226
  gr.HTML("""
227
  <script>
228
- // JS drawing code...
229
- // The canvas now acts as a visual backdrop to your discovery narrative
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  </script>
231
  """)
232
  return demo
 
 
1
  import gradio as gr
2
  import html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from game.engine import get_myco_narrative
4
 
5
  def render_shroom_tab():
6
  with gr.Blocks(css="""
7
+ #garden-canvas { width: 100%; height: 400px; background: linear-gradient(180deg, #1a2b4c 0%, #2a4c5e 50%, #4a7c59 100%); border-radius: 12px; }
8
  #narrative-box {
9
  font-family: 'Courier New', monospace;
10
  font-size: 15px;
 
14
  border-radius: 8px;
15
  border: 1px solid rgba(82, 255, 107, 0.3);
16
  text-align: center;
17
+ margin-top: 10px;
18
  }
19
  """) as demo:
20
 
21
+ # 1. The Canvas
22
  gr.HTML("<canvas id='garden-canvas'></canvas>")
23
 
24
+ # 2. The Narrative
25
  narrative = gr.Markdown(value="Waiting for the forest to wake...", elem_id="narrative-box")
26
 
27
+ # 3. Refresh Timer
28
  gr.Timer(20).tick(fn=get_myco_narrative, outputs=narrative)
29
 
30
+ # 4. Injected Animation Logic
31
  gr.HTML("""
32
  <script>
33
+ (function() {
34
+ const canvas = document.getElementById('garden-canvas');
35
+ const ctx = canvas.getContext('2d');
36
+
37
+ function resize() {
38
+ canvas.width = canvas.clientWidth;
39
+ canvas.height = canvas.clientHeight;
40
+ }
41
+ window.addEventListener('resize', resize);
42
+ resize();
43
+
44
+ const mushrooms = [];
45
+ const fireflies = [];
46
+
47
+ function drawMushroom(m, time) {
48
+ ctx.save();
49
+ ctx.translate(m.x, m.y);
50
+ const sway = Math.sin(time * 0.002 + m.phase) * 0.1;
51
+ const bounce = Math.sin(time * 0.005 + m.phase) * 0.05 + 1;
52
+ ctx.rotate(sway);
53
+ ctx.scale(m.currentSize, m.currentSize * bounce);
54
+
55
+ ctx.fillStyle = '#fff4e6';
56
+ ctx.beginPath(); ctx.roundRect(-12, 0, 24, 35, 10); ctx.fill();
57
+
58
+ ctx.fillStyle = '#4a3b32';
59
+ const isBlinking = (time % m.blinkInterval) < 150;
60
+ if (isBlinking) { ctx.fillRect(-7, 12, 4, 2); ctx.fillRect(3, 12, 4, 2); }
61
+ else { ctx.beginPath(); ctx.arc(-5, 12, 2.5, 0, Math.PI*2); ctx.fill(); ctx.beginPath(); ctx.arc(5, 12, 2.5, 0, Math.PI*2); ctx.fill(); }
62
+
63
+ ctx.restore();
64
+ }
65
+
66
+ function animate(time) {
67
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
68
+
69
+ if (Math.random() < 0.02 && mushrooms.length < 20) {
70
+ mushrooms.push({
71
+ x: Math.random() * canvas.width,
72
+ y: (canvas.height * 0.5) + (Math.random() * canvas.height * 0.4),
73
+ targetSize: Math.random() * 1.5 + 0.8,
74
+ currentSize: 0,
75
+ blinkInterval: Math.floor(Math.random() * 3000) + 2000,
76
+ phase: Math.random() * Math.PI * 2,
77
+ life: 500
78
+ });
79
+ }
80
+
81
+ mushrooms.forEach((m, i) => {
82
+ m.life--;
83
+ m.currentSize += (m.targetSize - m.currentSize) * 0.05;
84
+ drawMushroom(m, time);
85
+ if (m.life < 0) m.targetSize = 0;
86
+ if (m.life < 0 && m.currentSize < 0.05) mushrooms.splice(i, 1);
87
+ });
88
+
89
+ requestAnimationFrame(animate);
90
+ }
91
+ animate(0);
92
+ })();
93
  </script>
94
  """)
95
  return demo
96
+