awacke1 commited on
Commit
a7d2ddc
·
verified ·
1 Parent(s): 57b3cfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -59
app.py CHANGED
@@ -1,19 +1,16 @@
1
  import streamlit as st
2
 
3
- def create_animation_app():
4
- st.title("AI Memory Enhancement Visualization")
5
- st.write("This animation represents how AI might continually remember and build upon what users care about.")
6
 
7
- # JavaScript code for the animation
8
  js_code = """
9
- <canvas id="animationCanvas"></canvas>
10
 
11
  <script>
12
- const canvas = document.getElementById('animationCanvas');
13
- const ctx = canvas.getContext('2d');
14
-
15
- canvas.width = 400;
16
- canvas.height = 400;
17
 
18
  let t = 0;
19
 
@@ -21,72 +18,78 @@ def create_animation_app():
21
  return Math.sqrt(x * x + y * y);
22
  }
23
 
24
- function a(x, y) {
25
- const k = x/8 - 25;
26
- const e = y/8 - 25;
27
- const d = mag(k, e)**2 / 99;
28
 
29
- const q = x/3 + k * 0.5 / Math.cos(y*5) * Math.sin(d*d - t);
30
- const c = d/2 - t/8;
31
 
32
- const xPos = q * Math.sin(c) + e * Math.sin(d + k - t) + 200;
33
- const yPos = (q + y/8 + d*9) * Math.cos(c) + 200;
34
 
35
  return[xPos, yPos];
36
  }
37
 
38
  function getColor(x, y, t) {
39
  const hue = (Math.sin(t/2) * 360 + x/3 + y/3) % 360;
40
- const saturation = 70 + Math.sin(t) * 30;
41
- const lightness = 50 + Math.cos(t/2) * 20;
42
- return `hsla(${hue}, ${saturation}%, ${lightness}%, 0.5)`;
43
  }
44
 
45
- function draw() {
46
- ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
47
- ctx.fillRect(0, 0, canvas.width, canvas.height);
48
-
49
- ctx.lineWidth = 1.5;
50
-
51
- for(let y = 99; y < 300; y += 4) {
52
- for(let x = 99; x < 300; x += 2) {
53
- const[px, py] = a(x, y);
54
- const color = getColor(x, y, t);
55
-
56
- ctx.strokeStyle = color;
57
- ctx.beginPath();
58
- ctx.moveTo(px, py);
59
- ctx.lineTo(px + 1, py + 1);
60
- ctx.stroke();
 
 
61
  }
62
  }
63
 
64
- t += Math.PI / 120;
65
- requestAnimationFrame(draw);
66
  }
67
 
68
- ctx.fillStyle = 'black';
69
- ctx.fillRect(0, 0, canvas.width, canvas.height);
70
- draw();
71
- </script>
72
- """
73
-
74
- css = """
75
- <style>
76
- canvas {
77
- display: block;
78
- margin: auto;
79
- background: black;
80
- }
81
- .stApp {
82
- background-color: black;
 
 
 
83
  }
84
- </style>
85
- """
86
 
87
- html_content = css + js_code
 
 
 
88
 
89
- st.components.v1.html(html_content, height=450)
 
90
 
91
  if __name__ == "__main__":
92
- create_animation_app()
 
1
  import streamlit as st
2
 
3
+ def create_brain_animation_app():
4
+ st.title("AI Memory & Brain Visualization")
5
+ st.write("This visualization represents AI learning and memory enhancement, shaped like a brain's neocortex.")
6
 
7
+ # JavaScript code for the brain-shaped animation with SVG text
8
  js_code = """
9
+ <svg id="brainCanvas" width="100%" height="100%" style="position:fixed; top:0; left:0;"></svg>
10
 
11
  <script>
12
+ const svg = document.getElementById('brainCanvas');
13
+ const ns = 'http://www.w3.org/2000/svg';
 
 
 
14
 
15
  let t = 0;
16
 
 
18
  return Math.sqrt(x * x + y * y);
19
  }
20
 
21
+ function brainShape(x, y) {
22
+ let k = x/8 - 25, e = y/8 - 25;
23
+ let d = mag(k, e)**2 / 99;
 
24
 
25
+ let q = x/3 + k * 0.5 / Math.cos(y*5) * Math.sin(d*d - t);
26
+ let c = d/2 - t/8;
27
 
28
+ let xPos = q * Math.sin(c) + e * Math.sin(d + k - t) + svg.clientWidth / 2;
29
+ let yPos = (q + y/8 + d*9) * Math.cos(c) + svg.clientHeight / 2;
30
 
31
  return[xPos, yPos];
32
  }
33
 
34
  function getColor(x, y, t) {
35
  const hue = (Math.sin(t/2) * 360 + x/3 + y/3) % 360;
36
+ return `hsl(${hue}, 70%, 50%)`;
 
 
37
  }
38
 
39
+ function drawBrain() {
40
+ // Clear previous circles
41
+ while (svg.firstChild) {
42
+ svg.removeChild(svg.firstChild);
43
+ }
44
+
45
+ const circleRadius = 1;
46
+ for (let y = 99; y < svg.clientHeight - 99; y += 4) {
47
+ for (let x = 99; x < svg.clientWidth - 99; x += 2) {
48
+ const[px, py] = brainShape(x, y);
49
+ if (Math.sqrt(px*px + py*py) > svg.clientWidth * 0.3 && Math.sqrt(px*px + py*py) < svg.clientWidth * 0.6) { // Brain shape mask
50
+ const circle = document.createElementNS(ns, 'circle');
51
+ circle.setAttribute('cx', px);
52
+ circle.setAttribute('cy', py);
53
+ circle.setAttribute('r', circleRadius);
54
+ circle.setAttribute('fill', getColor(x, y, t));
55
+ svg.appendChild(circle);
56
+ }
57
  }
58
  }
59
 
60
+ t += Math.PI / 180; // Adjust animation speed
61
+ requestAnimationFrame(drawBrain);
62
  }
63
 
64
+ // SVG Text for scrolling
65
+ function addScrollingText(text) {
66
+ const textElement = document.createElementNS(ns, 'text');
67
+ textElement.setAttribute('x', '50%');
68
+ textElement.setAttribute('y', '10%');
69
+ textElement.setAttribute('dy', '0.3em');
70
+ textElement.setAttribute('text-anchor', 'middle');
71
+ textElement.setAttribute('fill', 'white');
72
+ textElement.setAttribute('font-size', '20px');
73
+ textElement.textContent = text;
74
+
75
+ svg.appendChild(textElement);
76
+
77
+ let startX = 0;
78
+ function animateText() {
79
+ startX = (startX - 1) % (svg.clientWidth + 200); // Adjust speed and text length
80
+ textElement.setAttribute('transform', `translate(${startX}, 0)`);
81
+ requestAnimationFrame(animateText);
82
  }
83
+ animateText();
84
+ }
85
 
86
+ drawBrain();
87
+ addScrollingText("AI Memory & Brain Visualization");
88
+ </script>
89
+ """
90
 
91
+ html_content = js_code
92
+ st.components.v1.html(html_content, height=st._legacy_dataframe._config.get_option('page_height'))
93
 
94
  if __name__ == "__main__":
95
+ create_brain_animation_app()