Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,16 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
def
|
4 |
-
st.title("AI Memory
|
5 |
-
st.write("This
|
6 |
|
7 |
-
# JavaScript code for the animation
|
8 |
js_code = """
|
9 |
-
<
|
10 |
|
11 |
<script>
|
12 |
-
const
|
13 |
-
const
|
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
|
25 |
-
|
26 |
-
|
27 |
-
const d = mag(k, e)**2 / 99;
|
28 |
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
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 |
-
|
41 |
-
const lightness = 50 + Math.cos(t/2) * 20;
|
42 |
-
return `hsla(${hue}, ${saturation}%, ${lightness}%, 0.5)`;
|
43 |
}
|
44 |
|
45 |
-
function
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
const
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
}
|
62 |
}
|
63 |
|
64 |
-
t += Math.PI /
|
65 |
-
requestAnimationFrame(
|
66 |
}
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
83 |
}
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
|
|
|
|
|
|
|
88 |
|
89 |
-
|
|
|
90 |
|
91 |
if __name__ == "__main__":
|
92 |
-
|
|
|
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()
|