Spaces:
Sleeping

byte-vortex commited on
Commit
c28b40f
·
verified ·
1 Parent(s): 2ecfba7

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/gradio_app.py +263 -59
ui/gradio_app.py CHANGED
@@ -270,66 +270,26 @@ def _safe_pos(position):
270
  return (max(0, min(2, int(x))), max(0, min(2, int(y))))
271
 
272
  HOME_MARKDOWN = """
273
- <div style="
274
- background: linear-gradient(135deg, rgba(11, 29, 18, 0.85) 0%, rgba(20, 50, 26, 0.95) 100%);
275
- border: 1px solid rgba(74, 222, 128, 0.3);
276
- border-left: 5px solid #4ade80;
277
- border-radius: 16px;
278
- padding: 24px;
279
- margin-bottom: 20px;
280
- box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
281
- backdrop-filter: blur(4px);
282
- color: #e2e8f0;
283
- ">
284
- <h2 style="
285
- color: #4ade80;
286
- margin-top: 0;
287
- font-family: 'Segoe UI', Roboto, sans-serif;
288
- letter-spacing: 0.5px;
289
- display: flex;
290
- align-items: center;
291
- gap: 8px;
292
- ">
293
- 🍄 Welcome to the Myco Forest
294
- </h2>
295
-
296
- <p style="font-size: 1.1em; line-height: 1.6; color: #cbd5e1; margin-bottom: 20px;">
297
- Myco is a tiny AI-powered forest game.
298
- </p>
299
-
300
- <div style="
301
- display: grid;
302
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
303
- gap: 12px;
304
- margin-bottom: 24px;
305
- ">
306
- <div style="background: rgba(255,255,255,0.05); padding: 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.05);">
307
- <strong>🎮 Play</strong><br><span style="font-size: 0.9em; color: #94a3b8;">Search for hidden mushrooms.</span>
308
- </div>
309
- <div style="background: rgba(255,255,255,0.05); padding: 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.05);">
310
- <strong>📖 MycoDex</strong><br><span style="font-size: 0.9em; color: #94a3b8;">Review your growing collection.</span>
311
- </div>
312
- <div style="background: rgba(255,255,255,0.05); padding: 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.05);">
313
- <strong>🧭 Guide</strong><br><span style="font-size: 0.9em; color: #94a3b8;">Get help on your journey.</span>
314
- </div>
315
- </div>
316
 
317
- <div style="
318
- border-top: 1px dashed rgba(74, 222, 128, 0.2);
319
- padding-top: 16px;
320
- background: rgba(74, 222, 128, 0.05);
321
- padding: 16px;
322
- border-radius: 12px;
323
- ">
324
- <span style="color: #4ade80; font-weight: bold; text-transform: uppercase; font-size: 0.85em; letter-spacing: 1px; display: block; margin-bottom: 4px;">
325
- Main Objective
326
- </span>
327
- <p style="margin: 0; font-style: italic; color: #e2e8f0; line-height: 1.5;">
328
- Solve one mystery — why does Myco remember a forest that vanished before it was born?
329
- Follow clues until the <strong>Impossible Mushroom</strong> blooms inside the MycoDex.
330
- </p>
331
- </div>
332
- </div>
 
 
333
  """
334
 
335
  GUIDE_MARKDOWN = """
@@ -440,6 +400,250 @@ def build_app():
440
  interactive=False
441
  )
442
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  # ── Event wiring ──
444
  start_play_button.click(open_play_tab, outputs=[tabs])
445
 
 
270
  return (max(0, min(2, int(x))), max(0, min(2, int(y))))
271
 
272
  HOME_MARKDOWN = """
273
+ # 🍄 Welcome to the Myco Forest
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
 
275
+ ---
276
+
277
+ Myco is a tiny **AI-powered forest game**.
278
+
279
+ ### 🗺️ Quick Navigation
280
+ * **🎮 Play** — Search for hidden mushrooms.
281
+ * **📖 MycoDex** — Review your expanding collection.
282
+ * **🧭 Guide** — Get help and instructions for your journey.
283
+
284
+ ---
285
+
286
+ > ### 🧭 **The Main Objective**
287
+ >
288
+ > Solve one mystery — **why does Myco remember a forest that vanished before it was born?**
289
+ >
290
+ > *Follow clues until the **Impossible Mushroom** blooms inside the MycoDex.*
291
+
292
+ ---
293
  """
294
 
295
  GUIDE_MARKDOWN = """
 
400
  interactive=False
401
  )
402
 
403
+ def myco_animation_card_markdown() -> str:
404
+ return """
405
+ <div id="myco-card-container" class="myco-anim-card">
406
+ <style>
407
+ .myco-anim-card {
408
+ position: relative;
409
+ width: 100%;
410
+ max-width: 600px;
411
+ height: 320px;
412
+ margin: 20px auto;
413
+ background: #050a08;
414
+ border: 1px solid rgba(82, 255, 107, 0.15);
415
+ border-radius: 12px;
416
+ overflow: hidden;
417
+ font-family: 'Inter', sans-serif;
418
+ box-shadow: 0 10px 30px rgba(0,0,0,0.5);
419
+ }
420
+
421
+ #myco-card-overlay {
422
+ position: absolute;
423
+ top: 0; left: 0; width: 100%; height: 100%;
424
+ pointer-events: none;
425
+ z-index: 1;
426
+ opacity: 0.12;
427
+ transition: opacity 0.4s ease;
428
+ }
429
+
430
+ .m-grid { background-image: radial-gradient(rgba(255,255,255,0.15) 1px, transparent 1px); background-size: 20px 20px; }
431
+ .m-lines { background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.03) 3px); }
432
+ .m-noise { background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
433
+
434
+ #myco-card-canvas {
435
+ display: block;
436
+ position: absolute;
437
+ top: 0; left: 0;
438
+ width: 100%;
439
+ height: 100%;
440
+ z-index: 2;
441
+ filter: contrast(1.1) brightness(1.1);
442
+ }
443
+
444
+ #myco-card-ui {
445
+ position: absolute; top: 12px; left: 0; width: 100%;
446
+ color: rgba(168, 255, 178, 0.5); font-size: 9px; letter-spacing: 3px;
447
+ pointer-events: none; text-transform: uppercase; z-index: 10;
448
+ text-align: center; line-height: 1.6;
449
+ }
450
+
451
+ #myco-card-footer {
452
+ position: absolute; bottom: 12px; left: 16px; right: 16px;
453
+ color: rgba(255, 255, 255, 0.25); font-size: 8px;
454
+ letter-spacing: 1px; text-transform: uppercase; z-index: 10;
455
+ display: flex; justify-content: space-between;
456
+ }
457
+
458
+ .myco-highlight { color: #00f2fe; font-weight: bold; }
459
+
460
+ @keyframes cardShake {
461
+ 0% { transform: translate(1px, 1px); }
462
+ 20% { transform: translate(-2px, 0px); }
463
+ 40% { transform: translate(1px, -1px); }
464
+ 100% { transform: translate(1px, 1px); }
465
+ }
466
+ .card-shaking { animation: cardShake 0.15s infinite; }
467
+ </style>
468
+
469
+ <div id="myco-card-overlay" class="m-grid"></div>
470
+ <div id="myco-card-ui">
471
+ BIOME MUTATION: <span id="myco-card-msg">SCANNING NETWORKS...</span><br>
472
+ <small style="font-size: 7px; opacity: 0.6; letter-spacing: 0.5px;">(CLICK CARD TO INTERACT WITH AUDIO RESONANCE)</small>
473
+ </div>
474
+
475
+ <canvas id="myco-card-canvas"></canvas>
476
+
477
+ <div id="myco-card-footer">
478
+ <div>ENGINE: <span class="myco-highlight">MYCO MATRIX</span></div>
479
+ <div id="myco-card-date"></div>
480
+ </div>
481
+
482
+ <script>
483
+ (function() {
484
+ const container = document.getElementById('myco-card-container');
485
+ const canvas = document.getElementById('myco-card-canvas');
486
+ const ctx = canvas.getContext('2d');
487
+ const overlay = document.getElementById('myco-card-overlay');
488
+ const msg = document.getElementById('myco-card-msg');
489
+
490
+ let audioCtx = null;
491
+ function initAudio() {
492
+ if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
493
+ if (audioCtx.state === 'suspended') audioCtx.resume();
494
+ }
495
+
496
+ const textures = ['m-grid', 'm-lines', 'm-noise'];
497
+ const sequence = ["🍄", "MYCO", "🍄‍🟫", "SPORE", "GILLS", "🍄", "CAP", "HYPHAE", "ROOTS"];
498
+
499
+ let currentStep = 0;
500
+ let isExposed = false;
501
+ let w, h, dpr, particles = [];
502
+
503
+ const sCanvas = document.createElement('canvas');
504
+ const sCtx = sCanvas.getContext('2d', { willReadFrequently: true });
505
+
506
+ class Particle {
507
+ constructor() {
508
+ this.x = Math.random() * container.clientWidth;
509
+ this.y = Math.random() * container.clientHeight;
510
+ this.tx = this.x; this.ty = this.y;
511
+ this.vx = 0; this.vy = 0;
512
+ this.size = Math.random() * 1.5 + 1;
513
+ this.color = '#fff';
514
+ }
515
+ update() {
516
+ if (isExposed) {
517
+ this.x += this.vx; this.y += this.vy;
518
+ this.vx *= 0.95; this.vy *= 0.95;
519
+ } else {
520
+ this.vx = (this.tx - this.x) * 0.15;
521
+ this.vy = (this.ty - this.y) * 0.15;
522
+ this.x += this.vx; this.y += this.vy;
523
+ }
524
+ }
525
+ draw() {
526
+ ctx.fillStyle = this.color;
527
+ ctx.fillRect(this.x, this.y, this.size, this.size);
528
+ }
529
+ }
530
+
531
+ function resizeCard() {
532
+ if (!container.clientWidth) return;
533
+ dpr = window.devicePixelRatio || 1;
534
+ w = container.clientWidth;
535
+ h = container.clientHeight;
536
+ canvas.width = w * dpr; canvas.height = h * dpr;
537
+ ctx.scale(dpr, dpr);
538
+ sCanvas.width = w; sCanvas.height = h;
539
+ if(!isExposed && currentStep < sequence.length) morph(sequence[currentStep]);
540
+ }
541
+
542
+ function morph(content) {
543
+ sCtx.clearRect(0, 0, w, h);
544
+ sCtx.fillStyle = "white";
545
+ sCtx.textAlign = "center";
546
+ sCtx.textBaseline = "middle";
547
+
548
+ const baseSize = Math.min(w, h) * 0.55;
549
+ const fontSize = content.length > 2 ? baseSize / (content.length * 0.45) : baseSize;
550
+ sCtx.font = `bold ${fontSize}px sans-serif`;
551
+ sCtx.fillText(content, w / 2, h / 2 + 10);
552
+
553
+ overlay.className = textures[currentStep % textures.length];
554
+ overlay.style.opacity = (0.04 + (Math.random() * 0.1)).toString();
555
+
556
+ const imgData = sCtx.getImageData(0, 0, w, h).data;
557
+ const points = [];
558
+ for (let y = 0; y < h; y += 4) {
559
+ for (let x = 0; x < w; x += 4) {
560
+ if (imgData[(y * w + x) * 4 + 3] > 128) points.push({x, y});
561
+ }
562
+ }
563
+
564
+ if (particles.length < points.length) {
565
+ for (let i = particles.length; i < points.length; i++) particles.push(new Particle());
566
+ }
567
+
568
+ particles.forEach((p, i) => {
569
+ const pt = points[i % points.length];
570
+ p.tx = pt.x; p.ty = pt.y;
571
+ if (content === "BLOOM") {
572
+ p.color = "#00f2fe";
573
+ } else {
574
+ p.color = `hsl(${130 + (currentStep * 22)}, 80%, 65%)`;
575
+ }
576
+ });
577
+
578
+ if (content !== "BLOOM") {
579
+ container.classList.add('card-shaking');
580
+ setTimeout(() => container.classList.remove('card-shaking'), 100);
581
+ }
582
+ }
583
+
584
+ function expose() {
585
+ isExposed = true;
586
+ msg.innerText = "SPORE BURST EXTRACTION";
587
+ overlay.className = 'm-noise';
588
+ overlay.style.opacity = "0.35";
589
+
590
+ particles.forEach(p => {
591
+ const angle = Math.random() * Math.PI * 2;
592
+ const vel = Math.random() * 15 + 8;
593
+ p.vx = Math.cos(angle) * vel;
594
+ p.vy = Math.sin(angle) * vel;
595
+ p.color = `hsl(${Math.random() * 40 + 290}, 95%, 65%)`;
596
+ });
597
+
598
+ setTimeout(() => {
599
+ isExposed = false;
600
+ msg.innerText = "BIOME INTEGRATED";
601
+ morph("BLOOM");
602
+ }, 1400);
603
+ }
604
+
605
+ function loop() {
606
+ ctx.fillStyle = 'rgba(5, 10, 8, 0.2)';
607
+ ctx.fillRect(0, 0, w, h);
608
+ particles.forEach(p => { p.update(); p.draw(); });
609
+ requestAnimationFrame(loop);
610
+ }
611
+
612
+ container.addEventListener('mousedown', initAudio);
613
+ window.addEventListener('resize', resizeCard);
614
+ document.getElementById('myco-card-date').textContent = new Date().toLocaleDateString();
615
+
616
+ setTimeout(() => {
617
+ resizeCard();
618
+ const timer = setInterval(() => {
619
+ if (!isExposed && msg.innerText !== "BIOME INTEGRATED") {
620
+ currentStep++;
621
+ if (currentStep < sequence.length) {
622
+ msg.innerText = `MUTATION // ${sequence[currentStep]}`;
623
+ morph(sequence[currentStep]);
624
+ } else {
625
+ clearInterval(timer);
626
+ expose();
627
+ }
628
+ }
629
+ }, 1300);
630
+ loop();
631
+ }, 300);
632
+ })();
633
+ </script>
634
+ </div>
635
+ """
636
+
637
+ # --- Your Gradio Layout Interface ---
638
+ with gr.Blocks() as demo:
639
+ with gr.Tab("Shroom"):
640
+ # We drop the custom HTML component directly into the tab structure
641
+ gr.HTML(value=myco_animation_card_markdown())
642
+
643
+ # You can add your other Shroom tab elements right below it
644
+ gr.Markdown("### Welcome to the Myco Laboratory")
645
+
646
+
647
  # ── Event wiring ──
648
  start_play_button.click(open_play_tab, outputs=[tabs])
649