Spaces:
Running
Running
We should have an sky atmoshpehere it should not be a static website. We also need to have a backgorund that represent sky. And I think you should make the clouds looks better.
Browse files- README.md +8 -5
- components/background-clouds.js +79 -0
- components/cloud.js +86 -0
- index.html +50 -19
- script.js +263 -0
- style.css +47 -19
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title: Fluffy Mindscapes
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Fluffy Mindscapes ☁️✨
|
| 3 |
+
colorFrom: gray
|
| 4 |
+
colorTo: pink
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://huggingface.co/deepsite).
|
components/background-clouds.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class BackgroundClouds extends HTMLElement {
|
| 2 |
+
constructor() {
|
| 3 |
+
super();
|
| 4 |
+
this.attachShadow({ mode: 'open' });
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
connectedCallback() {
|
| 8 |
+
this.shadowRoot.innerHTML = `
|
| 9 |
+
<style>
|
| 10 |
+
:host {
|
| 11 |
+
display: block;
|
| 12 |
+
position: fixed;
|
| 13 |
+
top: 0;
|
| 14 |
+
left: 0;
|
| 15 |
+
width: 100%;
|
| 16 |
+
height: 100%;
|
| 17 |
+
pointer-events: none;
|
| 18 |
+
z-index: 0;
|
| 19 |
+
overflow: hidden;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.bg-cloud {
|
| 23 |
+
position: absolute;
|
| 24 |
+
background: white;
|
| 25 |
+
border-radius: 50%;
|
| 26 |
+
opacity: 0.4;
|
| 27 |
+
filter: blur(5px);
|
| 28 |
+
animation: float 20s linear infinite;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.bg-cloud::before, .bg-cloud::after {
|
| 32 |
+
content: '';
|
| 33 |
+
position: absolute;
|
| 34 |
+
background: white;
|
| 35 |
+
border-radius: 50%;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
@keyframes float {
|
| 39 |
+
0% { transform: translateX(0) translateY(0); }
|
| 40 |
+
25% { transform: translateX(5%) translateY(-3%); }
|
| 41 |
+
50% { transform: translateX(10%) translateY(0); }
|
| 42 |
+
75% { transform: translateX(5%) translateY(3%); }
|
| 43 |
+
100% { transform: translateX(0) translateY(0); }
|
| 44 |
+
}
|
| 45 |
+
</style>
|
| 46 |
+
<div id="clouds-container"></div>
|
| 47 |
+
`;
|
| 48 |
+
|
| 49 |
+
this.createClouds();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
createClouds() {
|
| 53 |
+
const container = this.shadowRoot.getElementById('clouds-container');
|
| 54 |
+
const width = window.innerWidth;
|
| 55 |
+
const height = window.innerHeight;
|
| 56 |
+
|
| 57 |
+
for (let i = 0; i < 20; i++) {
|
| 58 |
+
const cloud = document.createElement('div');
|
| 59 |
+
const size = Math.random() * 150 + 50;
|
| 60 |
+
const opacity = Math.random() * 0.5 + 0.1;
|
| 61 |
+
const left = Math.random() * width;
|
| 62 |
+
const top = Math.random() * height;
|
| 63 |
+
const duration = Math.random() * 30 + 30;
|
| 64 |
+
|
| 65 |
+
cloud.className = 'bg-cloud';
|
| 66 |
+
cloud.style.width = `${size}px`;
|
| 67 |
+
cloud.style.height = `${size * 0.6}px`;
|
| 68 |
+
cloud.style.left = `${left}px`;
|
| 69 |
+
cloud.style.top = `${top}px`;
|
| 70 |
+
cloud.style.opacity = opacity;
|
| 71 |
+
cloud.style.animationDuration = `${duration}s`;
|
| 72 |
+
cloud.style.animationDelay = `${Math.random() * 20}s`;
|
| 73 |
+
|
| 74 |
+
container.appendChild(cloud);
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
customElements.define('background-clouds', BackgroundClouds);
|
components/cloud.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CloudElement extends HTMLElement {
|
| 2 |
+
constructor() {
|
| 3 |
+
super();
|
| 4 |
+
this.attachShadow({ mode: 'open' });
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
connectedCallback() {
|
| 8 |
+
const text = this.getAttribute('text') || '';
|
| 9 |
+
const percentage = this.getAttribute('percentage') || '0';
|
| 10 |
+
|
| 11 |
+
this.shadowRoot.innerHTML = `
|
| 12 |
+
<style>
|
| 13 |
+
:host {
|
| 14 |
+
display: inline-block;
|
| 15 |
+
position: relative;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
.cloud {
|
| 19 |
+
background: white;
|
| 20 |
+
border-radius: 50%;
|
| 21 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
| 22 |
+
display: flex;
|
| 23 |
+
align-items: center;
|
| 24 |
+
justify-content: center;
|
| 25 |
+
font-weight: bold;
|
| 26 |
+
color: #333;
|
| 27 |
+
cursor: pointer;
|
| 28 |
+
transition: all 0.5s ease;
|
| 29 |
+
position: relative;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.cloud-text {
|
| 33 |
+
position: relative;
|
| 34 |
+
z-index: 2;
|
| 35 |
+
text-align: center;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.cloud-percentage {
|
| 39 |
+
font-size: 0.6em;
|
| 40 |
+
display: block;
|
| 41 |
+
margin-top: 4px;
|
| 42 |
+
color: #666;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.cloud-circle {
|
| 46 |
+
position: absolute;
|
| 47 |
+
background: white;
|
| 48 |
+
border-radius: 50%;
|
| 49 |
+
}
|
| 50 |
+
</style>
|
| 51 |
+
<div class="cloud">
|
| 52 |
+
<div class="cloud-text">
|
| 53 |
+
${text}
|
| 54 |
+
<span class="cloud-percentage">${percentage}%</span>
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
`;
|
| 58 |
+
|
| 59 |
+
// Set cloud size based on percentage
|
| 60 |
+
const cloud = this.shadowRoot.querySelector('.cloud');
|
| 61 |
+
const baseSize = 60;
|
| 62 |
+
const size = baseSize * (0.5 + (parseInt(percentage) / 200));
|
| 63 |
+
cloud.style.width = `${size}px`;
|
| 64 |
+
cloud.style.height = `${size}px`;
|
| 65 |
+
|
| 66 |
+
// Add cloud shape circles
|
| 67 |
+
const smallCircle1 = document.createElement('div');
|
| 68 |
+
smallCircle1.className = 'cloud-circle';
|
| 69 |
+
smallCircle1.style.width = `${size * 0.6}px`;
|
| 70 |
+
smallCircle1.style.height = `${size * 0.6}px`;
|
| 71 |
+
smallCircle1.style.top = `${-size * 0.2}px`;
|
| 72 |
+
smallCircle1.style.left = `${-size * 0.2}px`;
|
| 73 |
+
|
| 74 |
+
const smallCircle2 = document.createElement('div');
|
| 75 |
+
smallCircle2.className = 'cloud-circle';
|
| 76 |
+
smallCircle2.style.width = `${size * 0.5}px`;
|
| 77 |
+
smallCircle2.style.height = `${size * 0.5}px`;
|
| 78 |
+
smallCircle2.style.bottom = `${-size * 0.1}px`;
|
| 79 |
+
smallCircle2.style.right = `${-size * 0.15}px`;
|
| 80 |
+
|
| 81 |
+
cloud.appendChild(smallCircle1);
|
| 82 |
+
cloud.appendChild(smallCircle2);
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
customElements.define('custom-cloud', CloudElement);
|
index.html
CHANGED
|
@@ -1,19 +1,50 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" class="light">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Cloudy Connections</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 11 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
|
| 12 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder"></script>
|
| 13 |
+
</head>
|
| 14 |
+
<body>
|
| 15 |
+
<div class="cloud-bg" id="background-clouds"></div>
|
| 16 |
+
<main class="container mx-auto px-4 py-8">
|
| 17 |
+
<header class="text-center mb-12">
|
| 18 |
+
<h1 class="text-4xl font-bold text-gray-800 mb-2">Cloudy Connections</h1>
|
| 19 |
+
<p class="text-lg text-gray-600">See how your text relates to our fluffy cloud concepts</p>
|
| 20 |
+
</header>
|
| 21 |
+
|
| 22 |
+
<div class="max-w-2xl mx-auto mb-12">
|
| 23 |
+
<div class="relative">
|
| 24 |
+
<input type="text" id="text-input" placeholder="Type something here..."
|
| 25 |
+
class="w-full px-6 py-4 rounded-full border-2 border-gray-200 focus:outline-none focus:border-blue-400 text-lg shadow-sm">
|
| 26 |
+
<button id="analyze-btn" class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-blue-500 text-white p-2 rounded-full hover:bg-blue-600 transition">
|
| 27 |
+
<i data-feather="search"></i>
|
| 28 |
+
</button>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<div id="cloud-container" class="relative h-96 mb-12">
|
| 33 |
+
<!-- Clouds will be dynamically inserted here -->
|
| 34 |
+
</div>
|
| 35 |
+
|
| 36 |
+
<div id="results" class="hidden bg-white rounded-xl p-6 shadow-md max-w-2xl mx-auto">
|
| 37 |
+
<h2 class="text-xl font-semibold mb-4">Analysis Results</h2>
|
| 38 |
+
<div id="similarity-results" class="space-y-3">
|
| 39 |
+
<!-- Results will be shown here -->
|
| 40 |
+
</div>
|
| 41 |
+
</div>
|
| 42 |
+
</main>
|
| 43 |
+
|
| 44 |
+
<script src="script.js"></script>
|
| 45 |
+
<script>
|
| 46 |
+
feather.replace();
|
| 47 |
+
</script>
|
| 48 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 49 |
+
</body>
|
| 50 |
+
</html>
|
script.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
document.addEventListener('DOMContentLoaded', async function() {
|
| 3 |
+
// Create background clouds
|
| 4 |
+
createBackgroundClouds();
|
| 5 |
+
|
| 6 |
+
// Initialize cloud data
|
| 7 |
+
const cloudData = [
|
| 8 |
+
{ text: "Happiness", percentage: 0 },
|
| 9 |
+
{ text: "Adventure", percentage: 0 },
|
| 10 |
+
{ text: "Creativity", percentage: 0 },
|
| 11 |
+
{ text: "Friendship", percentage: 0 },
|
| 12 |
+
{ text: "Success", percentage: 0 },
|
| 13 |
+
{ text: "Love", percentage: 0 },
|
| 14 |
+
{ text: "Freedom", percentage: 0 },
|
| 15 |
+
{ text: "Peace", percentage: 0 },
|
| 16 |
+
{ text: "Growth", percentage: 0 },
|
| 17 |
+
{ text: "Discovery", percentage: 0 }
|
| 18 |
+
];
|
| 19 |
+
|
| 20 |
+
const cloudContainer = document.getElementById('cloud-container');
|
| 21 |
+
const textInput = document.getElementById('text-input');
|
| 22 |
+
const analyzeBtn = document.getElementById('analyze-btn');
|
| 23 |
+
const resultsSection = document.getElementById('results');
|
| 24 |
+
const similarityResults = document.getElementById('similarity-results');
|
| 25 |
+
|
| 26 |
+
// Load the Universal Sentence Encoder
|
| 27 |
+
let model;
|
| 28 |
+
try {
|
| 29 |
+
model = await use.load();
|
| 30 |
+
console.log('Model loaded successfully');
|
| 31 |
+
} catch (err) {
|
| 32 |
+
console.error('Failed to load model:', err);
|
| 33 |
+
return;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Create initial clouds
|
| 37 |
+
createClouds();
|
| 38 |
+
|
| 39 |
+
analyzeBtn.addEventListener('click', analyzeText);
|
| 40 |
+
textInput.addEventListener('keypress', function(e) {
|
| 41 |
+
if (e.key === 'Enter') {
|
| 42 |
+
analyzeText();
|
| 43 |
+
}
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
function createClouds() {
|
| 47 |
+
cloudContainer.innerHTML = '';
|
| 48 |
+
|
| 49 |
+
// Calculate positions for two rows of clouds
|
| 50 |
+
const containerWidth = cloudContainer.offsetWidth;
|
| 51 |
+
const containerHeight = cloudContainer.offsetHeight;
|
| 52 |
+
|
| 53 |
+
// First row (top)
|
| 54 |
+
for (let i = 0; i < 5; i++) {
|
| 55 |
+
const x = (i + 0.5) * (containerWidth / 5.5);
|
| 56 |
+
const y = containerHeight * 0.3;
|
| 57 |
+
createCloud(cloudData[i], x, y, 60);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// Second row (bottom)
|
| 61 |
+
for (let i = 5; i < 10; i++) {
|
| 62 |
+
const x = (i - 4.5) * (containerWidth / 5.5);
|
| 63 |
+
const y = containerHeight * 0.7;
|
| 64 |
+
createCloud(cloudData[i], x, y, 60);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
function createBackgroundClouds() {
|
| 68 |
+
const bgContainer = document.getElementById('background-clouds');
|
| 69 |
+
const width = window.innerWidth;
|
| 70 |
+
const height = window.innerHeight;
|
| 71 |
+
|
| 72 |
+
for (let i = 0; i < 15; i++) {
|
| 73 |
+
const cloud = document.createElement('div');
|
| 74 |
+
const size = Math.random() * 120 + 80;
|
| 75 |
+
const opacity = Math.random() * 0.7 + 0.3;
|
| 76 |
+
|
| 77 |
+
cloud.className = 'bg-cloud';
|
| 78 |
+
cloud.style.width = `${size}px`;
|
| 79 |
+
cloud.style.height = `${size * 0.6}px`;
|
| 80 |
+
cloud.style.left = `${Math.random() * width}px`;
|
| 81 |
+
cloud.style.top = `${Math.random() * height}px`;
|
| 82 |
+
cloud.style.opacity = opacity;
|
| 83 |
+
cloud.style.animation = `float ${Math.random() * 10 + 10}s linear infinite`;
|
| 84 |
+
cloud.style.animationDelay = `${Math.random() * 10}s`;
|
| 85 |
+
|
| 86 |
+
bgContainer.appendChild(cloud);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
function createCloud(data, x, y, baseSize) {
|
| 91 |
+
const cloud = document.createElement('div');
|
| 92 |
+
cloud.className = 'cloud';
|
| 93 |
+
|
| 94 |
+
// Calculate size based on percentage (default to small)
|
| 95 |
+
const size = baseSize * (0.7 + (data.percentage / 150));
|
| 96 |
+
const blurAmount = Math.min(10, data.percentage / 10);
|
| 97 |
+
cloud.style.width = `${size}px`;
|
| 98 |
+
cloud.style.height = `${size * 0.8}px`;
|
| 99 |
+
cloud.style.left = `${x - size/2}px`;
|
| 100 |
+
cloud.style.top = `${y - size/2}px`;
|
| 101 |
+
cloud.style.filter = `drop-shadow(0 0 ${blurAmount}px rgba(255, 255, 255, 0.8)) blur(${blurAmount/3}px)`;
|
| 102 |
+
// Create cloud shape with multiple circles
|
| 103 |
+
cloud.innerHTML = `
|
| 104 |
+
<div class="cloud-text">
|
| 105 |
+
${data.text}
|
| 106 |
+
<span class="cloud-percentage">${data.percentage}%</span>
|
| 107 |
+
</div>
|
| 108 |
+
`;
|
| 109 |
+
|
| 110 |
+
// Add additional circles for cloud shape
|
| 111 |
+
// Create multiple circles for more realistic cloud shape
|
| 112 |
+
for (let i = 0; i < 5; i++) {
|
| 113 |
+
const circle = document.createElement('div');
|
| 114 |
+
const circleSize = size * (0.3 + Math.random() * 0.4);
|
| 115 |
+
circle.className = 'cloud-circle';
|
| 116 |
+
circle.style.width = `${circleSize}px`;
|
| 117 |
+
circle.style.height = `${circleSize}px`;
|
| 118 |
+
|
| 119 |
+
// Position circles randomly around main cloud
|
| 120 |
+
const angle = Math.random() * Math.PI * 2;
|
| 121 |
+
const distance = size * 0.3;
|
| 122 |
+
circle.style.left = `${Math.cos(angle) * distance}px`;
|
| 123 |
+
circle.style.top = `${Math.sin(angle) * distance}px`;
|
| 124 |
+
|
| 125 |
+
cloud.appendChild(circle);
|
| 126 |
+
}
|
| 127 |
+
cloud.appendChild(smallCircle1);
|
| 128 |
+
cloud.appendChild(smallCircle2);
|
| 129 |
+
|
| 130 |
+
cloudContainer.appendChild(cloud);
|
| 131 |
+
return cloud;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
async function analyzeText() {
|
| 135 |
+
const inputText = textInput.value.trim();
|
| 136 |
+
if (!inputText) return;
|
| 137 |
+
|
| 138 |
+
try {
|
| 139 |
+
// Generate embeddings for input text and cloud texts
|
| 140 |
+
const inputEmbedding = await model.embed([inputText]);
|
| 141 |
+
const cloudTexts = cloudData.map(c => c.text);
|
| 142 |
+
const cloudEmbeddings = await model.embed(cloudTexts);
|
| 143 |
+
|
| 144 |
+
// Calculate cosine similarity between input and each cloud text
|
| 145 |
+
const inputArray = await inputEmbedding.array();
|
| 146 |
+
const cloudArrays = await cloudEmbeddings.array();
|
| 147 |
+
|
| 148 |
+
const similarities = [];
|
| 149 |
+
for (let i = 0; i < cloudData.length; i++) {
|
| 150 |
+
const similarity = cosineSimilarity(inputArray[0], cloudArrays[i]);
|
| 151 |
+
const percentage = Math.round(similarity * 100);
|
| 152 |
+
cloudData[i].percentage = percentage;
|
| 153 |
+
similarities.push({ text: cloudData[i].text, percentage });
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
// Sort by percentage descending
|
| 157 |
+
similarities.sort((a, b) => b.percentage - a.percentage);
|
| 158 |
+
|
| 159 |
+
// Update UI with results
|
| 160 |
+
updateClouds();
|
| 161 |
+
showResults(inputText, similarities);
|
| 162 |
+
|
| 163 |
+
} catch (err) {
|
| 164 |
+
console.error('Error analyzing text:', err);
|
| 165 |
+
alert('An error occurred while analyzing your text. Please try again.');
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function updateClouds() {
|
| 170 |
+
cloudContainer.innerHTML = '';
|
| 171 |
+
|
| 172 |
+
const containerWidth = cloudContainer.offsetWidth;
|
| 173 |
+
const containerHeight = cloudContainer.offsetHeight;
|
| 174 |
+
|
| 175 |
+
// Sort clouds by percentage (highest first)
|
| 176 |
+
const sortedClouds = [...cloudData].sort((a, b) => b.percentage - a.percentage);
|
| 177 |
+
|
| 178 |
+
// Position clouds with highest percentages more centered and larger
|
| 179 |
+
for (let i = 0; i < sortedClouds.length; i++) {
|
| 180 |
+
const cloud = sortedClouds[i];
|
| 181 |
+
|
| 182 |
+
// Calculate position - higher percentage clouds are more centered
|
| 183 |
+
const x = containerWidth * (0.3 + 0.4 * (i / (sortedClouds.length - 1)));
|
| 184 |
+
|
| 185 |
+
// Alternate between top and bottom rows
|
| 186 |
+
const y = i % 2 === 0
|
| 187 |
+
? containerHeight * (0.3 + 0.1 * (1 - cloud.percentage/100))
|
| 188 |
+
: containerHeight * (0.7 - 0.1 * (1 - cloud.percentage/100));
|
| 189 |
+
|
| 190 |
+
// Base size scales with percentage
|
| 191 |
+
const baseSize = 40 + (cloud.percentage * 0.8);
|
| 192 |
+
createCloud(cloud, x, y, baseSize);
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
function showResults(inputText, similarities) {
|
| 197 |
+
resultsSection.classList.remove('hidden');
|
| 198 |
+
similarityResults.innerHTML = '';
|
| 199 |
+
|
| 200 |
+
const heading = document.createElement('h3');
|
| 201 |
+
heading.className = 'font-medium text-lg mb-2';
|
| 202 |
+
heading.textContent = `How "${inputText}" relates to our concepts:`;
|
| 203 |
+
similarityResults.appendChild(heading);
|
| 204 |
+
|
| 205 |
+
similarities.forEach(item => {
|
| 206 |
+
const resultItem = document.createElement('div');
|
| 207 |
+
resultItem.className = 'flex items-center justify-between';
|
| 208 |
+
|
| 209 |
+
const textSpan = document.createElement('span');
|
| 210 |
+
textSpan.className = 'text-gray-700';
|
| 211 |
+
textSpan.textContent = item.text;
|
| 212 |
+
|
| 213 |
+
const percentageBar = document.createElement('div');
|
| 214 |
+
percentageBar.className = 'flex items-center w-1/2';
|
| 215 |
+
|
| 216 |
+
const barContainer = document.createElement('div');
|
| 217 |
+
barContainer.className = 'flex-1 bg-gray-200 rounded-full h-4 mx-2';
|
| 218 |
+
|
| 219 |
+
const bar = document.createElement('div');
|
| 220 |
+
bar.className = 'bg-blue-500 h-4 rounded-full';
|
| 221 |
+
bar.style.width = `${item.percentage}%`;
|
| 222 |
+
|
| 223 |
+
const percentageText = document.createElement('span');
|
| 224 |
+
percentageText.className = 'text-gray-600 w-12 text-right';
|
| 225 |
+
percentageText.textContent = `${item.percentage}%`;
|
| 226 |
+
|
| 227 |
+
barContainer.appendChild(bar);
|
| 228 |
+
percentageBar.appendChild(barContainer);
|
| 229 |
+
percentageBar.appendChild(percentageText);
|
| 230 |
+
|
| 231 |
+
resultItem.appendChild(textSpan);
|
| 232 |
+
resultItem.appendChild(percentageBar);
|
| 233 |
+
similarityResults.appendChild(resultItem);
|
| 234 |
+
});
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
// Helper function to calculate cosine similarity
|
| 238 |
+
function cosineSimilarity(vecA, vecB) {
|
| 239 |
+
let dotProduct = 0;
|
| 240 |
+
let normA = 0;
|
| 241 |
+
let normB = 0;
|
| 242 |
+
|
| 243 |
+
for (let i = 0; i < vecA.length; i++) {
|
| 244 |
+
dotProduct += vecA[i] * vecB[i];
|
| 245 |
+
normA += vecA[i] * vecA[i];
|
| 246 |
+
normB += vecB[i] * vecB[i];
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
normA = Math.sqrt(normA);
|
| 250 |
+
normB = Math.sqrt(normB);
|
| 251 |
+
|
| 252 |
+
return dotProduct / (normA * normB);
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// Handle window resize
|
| 256 |
+
window.addEventListener('resize', () => {
|
| 257 |
+
if (cloudData.some(c => c.percentage > 0)) {
|
| 258 |
+
updateClouds();
|
| 259 |
+
} else {
|
| 260 |
+
createClouds();
|
| 261 |
+
}
|
| 262 |
+
});
|
| 263 |
+
});
|
style.css
CHANGED
|
@@ -1,28 +1,56 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
}
|
| 17 |
|
| 18 |
-
.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
border: 1px solid lightgray;
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
.
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@keyframes float {
|
| 2 |
+
0%, 100% {
|
| 3 |
+
transform: translateY(0);
|
| 4 |
+
}
|
| 5 |
+
50% {
|
| 6 |
+
transform: translateY(-10px);
|
| 7 |
+
}
|
| 8 |
}
|
| 9 |
|
| 10 |
+
.cloud {
|
| 11 |
+
position: absolute;
|
| 12 |
+
background: white;
|
| 13 |
+
border-radius: 50%;
|
| 14 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
| 15 |
+
display: flex;
|
| 16 |
+
align-items: center;
|
| 17 |
+
justify-content: center;
|
| 18 |
+
font-weight: bold;
|
| 19 |
+
color: #333;
|
| 20 |
+
cursor: pointer;
|
| 21 |
+
transition: all 0.5s ease;
|
| 22 |
+
animation: float 3s ease-in-out infinite;
|
| 23 |
+
will-change: transform;
|
| 24 |
}
|
| 25 |
|
| 26 |
+
.cloud::before, .cloud::after {
|
| 27 |
+
content: '';
|
| 28 |
+
position: absolute;
|
| 29 |
+
background: white;
|
| 30 |
+
border-radius: 50%;
|
| 31 |
}
|
| 32 |
|
| 33 |
+
.cloud-text {
|
| 34 |
+
position: relative;
|
| 35 |
+
z-index: 2;
|
| 36 |
+
text-align: center;
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
+
.cloud-percentage {
|
| 40 |
+
font-size: 0.6em;
|
| 41 |
+
display: block;
|
| 42 |
+
margin-top: 4px;
|
| 43 |
+
color: #666;
|
| 44 |
}
|
| 45 |
+
|
| 46 |
+
#text-input:focus {
|
| 47 |
+
box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
#analyze-btn {
|
| 51 |
+
transition: all 0.2s ease;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
#analyze-btn:hover {
|
| 55 |
+
transform: translateY(-50%) scale(1.1);
|
| 56 |
+
}
|