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

πŸ† Add gamification with achievements system

Browse files

- 5 unlockable achievements (First Evolution, Fast Learner, Perfectionist, Speed Demon, Marathon)
- Achievement notifications with special styling
- High score tracking
- Social sharing functionality with pre-formatted text
- Achievement grid display with gradient cards
- Motivates users to push for better results
- Makes the demo more engaging and viral

Files changed (1) hide show
  1. app.py +134 -5
app.py CHANGED
@@ -19,7 +19,18 @@ state = {
19
  "iteration": 0,
20
  "running": False,
21
  "variants_evaluated": 0,
22
- "start_time": None
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
  # HTML for aurora effect with epic intro
@@ -312,6 +323,9 @@ def simulate_evolution():
312
 
313
  state["fitness_history"].append(new_fitness)
314
 
 
 
 
315
  # Add event
316
  event = {
317
  "time": datetime.now().strftime("%H:%M:%S"),
@@ -320,6 +334,14 @@ def simulate_evolution():
320
  }
321
  state["events"].append(event)
322
 
 
 
 
 
 
 
 
 
323
  return event
324
 
325
  def get_evolved_code():
@@ -393,14 +415,99 @@ def format_code_display():
393
  '''
394
  return html
395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  def format_events():
397
  """Format events for display."""
398
  html = '<div style="background: #0A0A2A; padding: 15px; border-radius: 10px; height: 300px; overflow-y: auto; font-family: monospace;">'
399
 
400
  for event in state["events"][-20:][::-1]:
401
- color = "#FFD700" if event["type"] == "improvement" else "#00FF88"
402
- icon = "✨" if event["type"] == "improvement" else "πŸ“Š"
403
- html += f'<div style="color: {color}; padding: 5px;">{icon} [{event["time"]}] {event["message"]}</div>'
 
 
 
 
 
 
 
 
 
 
 
404
 
405
  html += '</div>'
406
  return html
@@ -497,6 +604,19 @@ with gr.Blocks(
497
  gr.Markdown("### 🧬 Live Code Evolution")
498
  code_display = gr.HTML(value=format_code_display())
499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  with gr.Row():
501
  with gr.Column():
502
  gr.Markdown("### πŸ”οΈ Fitness Landscape")
@@ -516,12 +636,20 @@ with gr.Blocks(
516
  new_state = not running
517
  return new_state, toggle_evolution(new_state)
518
 
 
 
 
519
  toggle_btn.click(
520
  fn=on_toggle,
521
  inputs=[running_state],
522
  outputs=[running_state, toggle_btn]
523
  )
524
 
 
 
 
 
 
525
  def update_all():
526
  if state["running"]:
527
  simulate_evolution()
@@ -541,12 +669,13 @@ with gr.Blocks(
541
  fitness_chart: create_fitness_chart(),
542
  landscape_3d: create_3d_landscape(),
543
  code_display: format_code_display(),
 
544
  event_log: format_events()
545
  }
546
 
547
  timer.tick(
548
  fn=update_all,
549
- outputs=[fitness_display, generation_display, variants_display, speed_display, fitness_chart, landscape_3d, code_display, event_log]
550
  )
551
 
552
  gr.Markdown("""
 
19
  "iteration": 0,
20
  "running": False,
21
  "variants_evaluated": 0,
22
+ "start_time": None,
23
+ "achievements": [],
24
+ "high_score": 0.9333
25
+ }
26
+
27
+ # Achievement definitions
28
+ ACHIEVEMENTS = {
29
+ "first_evolution": {"name": "🎯 First Evolution!", "desc": "Started your first evolution", "threshold": 1},
30
+ "fast_learner": {"name": "⚑ Fast Learner", "desc": "Reached 95% fitness", "threshold": 0.95},
31
+ "perfectionist": {"name": "πŸ’Ž Perfectionist", "desc": "Reached 99% fitness", "threshold": 0.99},
32
+ "speed_demon": {"name": "🏎️ Speed Demon", "desc": "Process 10+ variants/sec", "threshold": 10},
33
+ "marathon": {"name": "πŸƒ Marathon Runner", "desc": "Run 10+ generations", "threshold": 10}
34
  }
35
 
36
  # HTML for aurora effect with epic intro
 
323
 
324
  state["fitness_history"].append(new_fitness)
325
 
326
+ # Check for new achievements
327
+ new_achievements = check_achievements()
328
+
329
  # Add event
330
  event = {
331
  "time": datetime.now().strftime("%H:%M:%S"),
 
334
  }
335
  state["events"].append(event)
336
 
337
+ # Add achievement events
338
+ for ach in new_achievements:
339
+ state["events"].append({
340
+ "time": datetime.now().strftime("%H:%M:%S"),
341
+ "type": "achievement",
342
+ "message": f"πŸ† ACHIEVEMENT UNLOCKED: {ach['name']}"
343
+ })
344
+
345
  return event
346
 
347
  def get_evolved_code():
 
415
  '''
416
  return html
417
 
418
+ def check_achievements():
419
+ """Check and award achievements."""
420
+ new_achievements = []
421
+
422
+ # First evolution
423
+ if state["iteration"] >= 1 and "first_evolution" not in state["achievements"]:
424
+ state["achievements"].append("first_evolution")
425
+ new_achievements.append(ACHIEVEMENTS["first_evolution"])
426
+
427
+ # Fitness achievements
428
+ current_fitness = state["fitness_history"][-1] if state["fitness_history"] else 0
429
+
430
+ if current_fitness >= 0.95 and "fast_learner" not in state["achievements"]:
431
+ state["achievements"].append("fast_learner")
432
+ new_achievements.append(ACHIEVEMENTS["fast_learner"])
433
+
434
+ if current_fitness >= 0.99 and "perfectionist" not in state["achievements"]:
435
+ state["achievements"].append("perfectionist")
436
+ new_achievements.append(ACHIEVEMENTS["perfectionist"])
437
+
438
+ # Speed achievement
439
+ if state["start_time"] and state["variants_evaluated"] > 0:
440
+ elapsed = time.time() - state["start_time"]
441
+ if elapsed > 0:
442
+ speed = state["variants_evaluated"] / elapsed
443
+ if speed >= 10 and "speed_demon" not in state["achievements"]:
444
+ state["achievements"].append("speed_demon")
445
+ new_achievements.append(ACHIEVEMENTS["speed_demon"])
446
+
447
+ # Marathon achievement
448
+ if state["iteration"] >= 10 and "marathon" not in state["achievements"]:
449
+ state["achievements"].append("marathon")
450
+ new_achievements.append(ACHIEVEMENTS["marathon"])
451
+
452
+ # Update high score
453
+ if current_fitness > state["high_score"]:
454
+ state["high_score"] = current_fitness
455
+
456
+ return new_achievements
457
+
458
+ def format_achievements():
459
+ """Format achievements display."""
460
+ html = '<div style="background: #0A0A2A; padding: 20px; border-radius: 10px;">'
461
+ html += '<h3 style="color: #FFD700; margin-top: 0;">πŸ† Achievements</h3>'
462
+ html += '<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px;">'
463
+
464
+ for ach_id in state["achievements"]:
465
+ ach = ACHIEVEMENTS.get(ach_id, {})
466
+ html += f'''
467
+ <div style="background: linear-gradient(45deg, #7B3FF2, #00AAFF); padding: 10px; border-radius: 8px; text-align: center;">
468
+ <div style="font-size: 24px;">{ach.get("name", "")}</div>
469
+ <div style="font-size: 12px; color: #FFD700;">{ach.get("desc", "")}</div>
470
+ </div>
471
+ '''
472
+
473
+ if not state["achievements"]:
474
+ html += '<div style="color: #666; text-align: center; width: 100%;">Start evolving to unlock achievements!</div>'
475
+
476
+ html += '</div>'
477
+ html += f'<div style="margin-top: 20px; text-align: center; color: #00FF88; font-size: 20px;">High Score: {state["high_score"]:.4f}</div>'
478
+ html += '</div>'
479
+ return html
480
+
481
+ def get_share_text():
482
+ """Generate share text for social media."""
483
+ fitness = state["fitness_history"][-1] if state["fitness_history"] else 0.9333
484
+ achievements_count = len(state["achievements"])
485
+
486
+ text = f"🌟 Evolution Aurora: I evolved AI to {fitness:.2%} fitness with {achievements_count} achievements unlocked! Can you beat my score?\n\n"
487
+ text += "Try it yourself: https://huggingface.co/spaces/Agents-MCP-Hackathon/Evolution\n"
488
+ text += "#EvolutionAurora #AIEvolution #HuggingFace"
489
+
490
+ return text
491
+
492
  def format_events():
493
  """Format events for display."""
494
  html = '<div style="background: #0A0A2A; padding: 15px; border-radius: 10px; height: 300px; overflow-y: auto; font-family: monospace;">'
495
 
496
  for event in state["events"][-20:][::-1]:
497
+ if event["type"] == "achievement":
498
+ color = "#FFD700"
499
+ icon = "πŸ†"
500
+ style = "font-size: 16px; font-weight: bold; background: linear-gradient(45deg, #7B3FF2, #00AAFF); padding: 10px; border-radius: 5px; margin: 5px 0;"
501
+ elif event["type"] == "improvement":
502
+ color = "#00FF88"
503
+ icon = "✨"
504
+ style = "padding: 5px;"
505
+ else:
506
+ color = "#00AAFF"
507
+ icon = "πŸ“Š"
508
+ style = "padding: 5px;"
509
+
510
+ html += f'<div style="color: {color}; {style}">{icon} [{event["time"]}] {event["message"]}</div>'
511
 
512
  html += '</div>'
513
  return html
 
604
  gr.Markdown("### 🧬 Live Code Evolution")
605
  code_display = gr.HTML(value=format_code_display())
606
 
607
+ # Achievements Display
608
+ gr.Markdown("### πŸ† Achievements & Leaderboard")
609
+ achievements_display = gr.HTML(value=format_achievements())
610
+
611
+ with gr.Row():
612
+ share_btn = gr.Button("πŸ“± Share Your Score", variant="secondary")
613
+ share_text = gr.Textbox(
614
+ value=get_share_text(),
615
+ label="Copy & Share:",
616
+ interactive=True,
617
+ visible=False
618
+ )
619
+
620
  with gr.Row():
621
  with gr.Column():
622
  gr.Markdown("### πŸ”οΈ Fitness Landscape")
 
636
  new_state = not running
637
  return new_state, toggle_evolution(new_state)
638
 
639
+ def on_share():
640
+ return gr.update(visible=True, value=get_share_text())
641
+
642
  toggle_btn.click(
643
  fn=on_toggle,
644
  inputs=[running_state],
645
  outputs=[running_state, toggle_btn]
646
  )
647
 
648
+ share_btn.click(
649
+ fn=on_share,
650
+ outputs=[share_text]
651
+ )
652
+
653
  def update_all():
654
  if state["running"]:
655
  simulate_evolution()
 
669
  fitness_chart: create_fitness_chart(),
670
  landscape_3d: create_3d_landscape(),
671
  code_display: format_code_display(),
672
+ achievements_display: format_achievements(),
673
  event_log: format_events()
674
  }
675
 
676
  timer.tick(
677
  fn=update_all,
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("""