johangras commited on
Commit
e47ebf0
Β·
1 Parent(s): 1b2e6b0

🎡 Add sound effects and challenge mode

Browse files

- Web Audio API sound effects for achievements and improvements
- Keyboard shortcuts (Space to start, Ctrl+S to share, M to mute)
- Challenge mode with Gold/Silver/Bronze targets
- Pro tips section for better user engagement
- Ascending arpeggio for achievements
- Gentle ping for fitness improvements
- MutationObserver to detect and play sounds automatically

Files changed (1) hide show
  1. app.py +110 -0
app.py CHANGED
@@ -569,6 +569,82 @@ with gr.Blocks(
569
  # Aurora effect at the top
570
  gr.HTML(AURORA_HTML)
571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572
  with gr.Row():
573
  with gr.Column(scale=1):
574
  toggle_btn = gr.Button("πŸš€ Start Evolution", variant="primary", size="lg")
@@ -678,6 +754,27 @@ with gr.Blocks(
678
  outputs=[fitness_display, generation_display, variants_display, speed_display, fitness_chart, landscape_3d, code_display, achievements_display, event_log]
679
  )
680
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681
  gr.Markdown("""
682
  ---
683
  ### πŸ† HuggingFace Agents-MCP Hackathon 2025
@@ -686,6 +783,19 @@ with gr.Blocks(
686
 
687
  This demo showcases AI-driven code evolution with real-time visualization. The aurora effects
688
  intensify with fitness improvements, creating a stunning visual representation of machine learning.
 
 
 
 
 
 
 
 
 
 
 
 
 
689
  """)
690
 
691
  if __name__ == "__main__":
 
569
  # Aurora effect at the top
570
  gr.HTML(AURORA_HTML)
571
 
572
+ # Sound effects (Web Audio API)
573
+ gr.HTML('''
574
+ <script>
575
+ // Sound system for achievements and improvements
576
+ const audioContext = new (window.AudioContext || window.webkitAudioContext)();
577
+ let soundEnabled = true;
578
+
579
+ function playSound(type) {
580
+ if (!soundEnabled) return;
581
+
582
+ const oscillator = audioContext.createOscillator();
583
+ const gainNode = audioContext.createGain();
584
+
585
+ oscillator.connect(gainNode);
586
+ gainNode.connect(audioContext.destination);
587
+
588
+ if (type === 'achievement') {
589
+ // Achievement sound - ascending arpeggio
590
+ oscillator.frequency.setValueAtTime(523.25, audioContext.currentTime); // C5
591
+ oscillator.frequency.setValueAtTime(659.25, audioContext.currentTime + 0.1); // E5
592
+ oscillator.frequency.setValueAtTime(783.99, audioContext.currentTime + 0.2); // G5
593
+ oscillator.frequency.setValueAtTime(1046.50, audioContext.currentTime + 0.3); // C6
594
+ gainNode.gain.setValueAtTime(0.3, audioContext.currentTime);
595
+ gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.5);
596
+ oscillator.start();
597
+ oscillator.stop(audioContext.currentTime + 0.5);
598
+ } else if (type === 'improvement') {
599
+ // Improvement sound - gentle ping
600
+ oscillator.frequency.setValueAtTime(880, audioContext.currentTime); // A5
601
+ gainNode.gain.setValueAtTime(0.1, audioContext.currentTime);
602
+ gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.2);
603
+ oscillator.start();
604
+ oscillator.stop(audioContext.currentTime + 0.2);
605
+ }
606
+ }
607
+
608
+ // Watch for achievement messages
609
+ const observeAchievements = new MutationObserver((mutations) => {
610
+ mutations.forEach((mutation) => {
611
+ if (mutation.type === 'childList') {
612
+ const text = mutation.target.textContent || '';
613
+ if (text.includes('ACHIEVEMENT UNLOCKED')) {
614
+ playSound('achievement');
615
+ } else if (text.includes('✨') && text.includes('+0.0')) {
616
+ playSound('improvement');
617
+ }
618
+ }
619
+ });
620
+ });
621
+
622
+ // Start observing when ready
623
+ setTimeout(() => {
624
+ const eventLog = document.querySelector('[id*="event_log"]');
625
+ if (eventLog) {
626
+ observeAchievements.observe(eventLog, { childList: true, subtree: true });
627
+ }
628
+ }, 1000);
629
+
630
+ // Keyboard shortcuts
631
+ document.addEventListener('keydown', (e) => {
632
+ if (e.key === ' ' && e.target.tagName !== 'INPUT') {
633
+ e.preventDefault();
634
+ const startBtn = document.querySelector('.gr-button-primary');
635
+ if (startBtn) startBtn.click();
636
+ } else if (e.key === 's' && e.ctrlKey) {
637
+ e.preventDefault();
638
+ const shareBtn = document.querySelector('[id*="share_btn"]');
639
+ if (shareBtn) shareBtn.click();
640
+ } else if (e.key === 'm') {
641
+ soundEnabled = !soundEnabled;
642
+ console.log('Sound', soundEnabled ? 'enabled' : 'disabled');
643
+ }
644
+ });
645
+ </script>
646
+ ''')
647
+
648
  with gr.Row():
649
  with gr.Column(scale=1):
650
  toggle_btn = gr.Button("πŸš€ Start Evolution", variant="primary", size="lg")
 
754
  outputs=[fitness_display, generation_display, variants_display, speed_display, fitness_chart, landscape_3d, code_display, achievements_display, event_log]
755
  )
756
 
757
+ # Challenge Mode
758
+ with gr.Row():
759
+ gr.Markdown("""
760
+ ### 🎯 Challenge Mode
761
+
762
+ **Today's Challenge**: Reach 99% fitness in under 10 generations!
763
+
764
+ πŸ₯‡ **Gold**: < 5 generations
765
+ πŸ₯ˆ **Silver**: < 7 generations
766
+ πŸ₯‰ **Bronze**: < 10 generations
767
+ """)
768
+
769
+ gr.HTML('''
770
+ <div style="text-align: center; padding: 20px;">
771
+ <div style="display: inline-block; background: linear-gradient(45deg, #FFD700, #FFA500); padding: 15px 30px; border-radius: 10px;">
772
+ <h3 style="margin: 0; color: #000;">πŸ… Your Best: Not Set</h3>
773
+ <p style="margin: 5px 0 0 0; color: #333;">Complete a run to set your record!</p>
774
+ </div>
775
+ </div>
776
+ ''')
777
+
778
  gr.Markdown("""
779
  ---
780
  ### πŸ† HuggingFace Agents-MCP Hackathon 2025
 
783
 
784
  This demo showcases AI-driven code evolution with real-time visualization. The aurora effects
785
  intensify with fitness improvements, creating a stunning visual representation of machine learning.
786
+
787
+ ### ⌨️ Keyboard Shortcuts
788
+
789
+ - **Space**: Start/Stop Evolution
790
+ - **Ctrl+S**: Share Your Score
791
+ - **M**: Toggle Sound Effects
792
+
793
+ ### πŸ’‘ Pro Tips
794
+
795
+ - Watch for achievement unlocks - they come with special sound effects!
796
+ - The aurora intensifies with larger fitness improvements
797
+ - Modal's parallel execution evaluates 4-8 variants simultaneously
798
+ - Try to unlock all 5 achievements in a single run!
799
  """)
800
 
801
  if __name__ == "__main__":