Spaces:
Sleeping

byte-vortex commited on
Commit
a9ed3c7
·
verified ·
1 Parent(s): 9d21a9a

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/interface.py +148 -77
ui/interface.py CHANGED
@@ -1,27 +1,31 @@
1
  import gradio as gr
2
  import html
3
 
4
- def myco_animation_card_markdown() -> str:
5
  """
6
- Pure iframe srcdoc implementation.
7
- Zero UI cards, zero React interference. Just the spore matrix.
8
  """
9
  iframe_content = """
10
  <!DOCTYPE html>
11
  <html>
12
  <head>
13
  <style>
14
- body { margin: 0; overflow: hidden; background: #050a08; }
 
 
 
 
 
15
  canvas { display: block; }
16
  </style>
17
  </head>
18
  <body>
19
- <canvas id="spore-canvas"></canvas>
20
  <script>
21
- const canvas = document.getElementById('spore-canvas');
22
  const ctx = canvas.getContext('2d');
23
 
24
- // Handles iframe resizing automatically
25
  function resize() {
26
  canvas.width = window.innerWidth;
27
  canvas.height = window.innerHeight;
@@ -29,53 +33,152 @@ def myco_animation_card_markdown() -> str:
29
  window.addEventListener('resize', resize);
30
  resize();
31
 
32
- // Setup Spores
33
- const particles = [];
34
- for(let i = 0; i < 800; i++) {
35
- particles.push({
36
- x: Math.random() * canvas.width,
37
- y: Math.random() * canvas.height,
38
- vx: (Math.random() - 0.5) * 1.5,
39
- vy: (Math.random() - 0.5) * 1.5,
40
- size: Math.random() * 2 + 0.5,
41
- color: Math.random() > 0.85 ? '#00f2fe' : '#52ff6b' // 15% Blue, 85% Green
42
- });
43
- }
 
 
 
 
 
 
 
 
44
 
45
- // Animation Loop
46
- function draw() {
47
- // Creates the trailing effect
48
- ctx.fillStyle = 'rgba(5, 10, 8, 0.2)';
49
- ctx.fillRect(0, 0, canvas.width, canvas.height);
50
 
51
- particles.forEach(p => {
52
- p.x += p.vx;
53
- p.y += p.vy;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- // Seamless screen wrapping
56
- if(p.x < 0) p.x = canvas.width;
57
- if(p.x > canvas.width) p.x = 0;
58
- if(p.y < 0) p.y = canvas.height;
59
- if(p.y > canvas.height) p.y = 0;
60
 
61
- ctx.fillStyle = p.color;
62
- ctx.fillRect(p.x, p.y, p.size, p.size);
63
- });
64
-
65
- requestAnimationFrame(draw);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
- draw();
 
68
  </script>
69
  </body>
70
  </html>
71
  """
72
 
73
- # Safely escape the HTML so Gradio parses it flawlessly
74
  escaped_srcdoc = html.escape(iframe_content)
75
 
76
- # Return it wrapped in an isolated iframe bounding box
77
  return f'''
78
- <div style="width: 100%; height: 400px; border-radius: 8px; overflow: hidden; border: 1px solid rgba(82, 255, 107, 0.3);">
79
  <iframe
80
  srcdoc="{escaped_srcdoc}"
81
  style="width: 100%; height: 100%; border: none;"
@@ -86,40 +189,8 @@ def myco_animation_card_markdown() -> str:
86
 
87
  def render_shroom_tab():
88
  with gr.Tabs():
89
- with gr.Tab("🔮 Mutation Matrix"):
90
- gr.HTML(value=myco_animation_card_markdown())
 
 
91
 
92
- with gr.Tab("🎙️ GEMMA LIVE STREAM"):
93
- with gr.Group():
94
- gr.Markdown("# 🚨 WE ARE LIVE: THE SPORE NATION PODCAST 🚨")
95
-
96
- gr.Markdown(
97
- "> ### 📣 **GEMMA AI:** \"WHAT IS UP MY FELLOW HYPHAE-HEADS?! Smash that mutate button "
98
- "right now! Today we are diving into an ABSOLUTELY INSANE, UNHINGED, "
99
- "100% IMPOSSIBLE MUSHROOM GLITCH DEEP IN THE FOREST CANOPY!!! "
100
- "THE MATRIX IS BREAKING!!! ARE YOU SEEING THESE PARTICLES?! I AM SCREAMING!!!\""
101
- )
102
-
103
- with gr.Row():
104
- like_btn = gr.Button(
105
- "👍 SMASH LIKE (Sync Audio Resonance)",
106
- variant="primary",
107
- size="lg"
108
- )
109
- sub_btn = gr.Button(
110
- "🔔 SUBSCRIBE TO THE SPORES",
111
- variant="secondary"
112
- )
113
-
114
- gr.Markdown("---")
115
- gr.Markdown("### 💬 Hype Live Chat Feed")
116
-
117
- gr.HTML("""
118
- <div style="background: #090e0b; padding: 12px; border-radius: 8px; border: 1px solid rgba(82, 255, 107, 0.2); height: 110px; overflow-y: auto; font-family: 'Courier New', monospace; font-size: 11px; color: #a8ffa2; line-height: 1.5;">
119
- <div><span style="color: #ff4500; font-weight: bold;">[ShroomKing420]:</span> GEMMA IS LITERALLY UNHINGED TODAY LMAOOO 🔥🔥🔥</div>
120
- <div><span style="color: #00f2fe; font-weight: bold;">[Spore_Chaser]:</span> Wait... is the matrix actually glitched?! Look at the canvas tab!!</div>
121
- <div><span style="color: #e91e63; font-weight: bold;">[Mod_Myco]:</span> Click the like button to feed the neural network!</div>
122
- <div><span style="color: #ffeb3b; font-weight: bold;">[Gemma_Stan]:</span> WE ARE WITNESSING FOREST HISTORY RIGHT NOW FOLKS 🍄🍄🍄</div>
123
- </div>
124
- """)
125
-
 
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;
 
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;"
 
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