Spaces:
Running
Running
there is a square but there is no clouds in it. Do you understand the words that are coming out of my mouth?
Browse files- index.html +3 -2
- script.js +75 -86
- style.css +5 -5
index.html
CHANGED
|
@@ -33,7 +33,7 @@
|
|
| 33 |
<!-- Clouds will be dynamically inserted here -->
|
| 34 |
</div>
|
| 35 |
|
| 36 |
-
|
| 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 -->
|
|
@@ -41,10 +41,11 @@
|
|
| 41 |
</div>
|
| 42 |
</main>
|
| 43 |
<script src="components/background-clouds.js"></script>
|
|
|
|
| 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>
|
|
|
|
| 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 -->
|
|
|
|
| 41 |
</div>
|
| 42 |
</main>
|
| 43 |
<script src="components/background-clouds.js"></script>
|
| 44 |
+
<script src="components/cloud.js"></script>
|
| 45 |
<script src="script.js"></script>
|
| 46 |
<script>
|
| 47 |
feather.replace();
|
| 48 |
</script>
|
| 49 |
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 50 |
</body>
|
| 51 |
+
</html>
|
script.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
|
| 2 |
document.addEventListener('DOMContentLoaded', async function() {
|
| 3 |
-
// Initialize cloud data
|
| 4 |
const cloudData = [
|
| 5 |
{ text: "Happiness", percentage: 0 },
|
| 6 |
{ text: "Adventure", percentage: 0 },
|
|
@@ -32,6 +32,7 @@ document.addEventListener('DOMContentLoaded', async function() {
|
|
| 32 |
|
| 33 |
// Create initial clouds
|
| 34 |
createClouds();
|
|
|
|
| 35 |
// Add event listeners
|
| 36 |
analyzeBtn.addEventListener('click', () => {
|
| 37 |
analyzeBtn.disabled = true;
|
|
@@ -50,58 +51,50 @@ document.addEventListener('DOMContentLoaded', async function() {
|
|
| 50 |
analyzeBtn.click();
|
| 51 |
}
|
| 52 |
});
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
const containerWidth = cloudContainer.offsetWidth;
|
| 57 |
-
const containerHeight = cloudContainer.offsetHeight;
|
| 58 |
-
|
| 59 |
-
// Create a circular layout for initial clouds
|
| 60 |
-
const centerX = containerWidth / 2;
|
| 61 |
-
const centerY = containerHeight / 2;
|
| 62 |
-
const radius = Math.min(containerWidth, containerHeight) * 0.35;
|
| 63 |
-
|
| 64 |
-
cloudData.forEach((cloud, i) => {
|
| 65 |
-
const angle = (i / cloudData.length) * Math.PI * 2;
|
| 66 |
-
const x = centerX + Math.cos(angle) * radius;
|
| 67 |
-
const y = centerY + Math.sin(angle) * radius;
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
| 99 |
const inputText = textInput.value.trim();
|
| 100 |
if (!inputText) {
|
| 101 |
alert('Please enter some text to analyze');
|
| 102 |
return;
|
| 103 |
}
|
| 104 |
-
|
|
|
|
| 105 |
// Generate embeddings for input text and cloud texts
|
| 106 |
const inputEmbedding = await model.embed([inputText]);
|
| 107 |
const cloudTexts = cloudData.map(c => c.text);
|
|
@@ -125,47 +118,43 @@ try {
|
|
| 125 |
// Update UI with results
|
| 126 |
updateClouds();
|
| 127 |
showResults(inputText, similarities);
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
const containerWidth = cloudContainer.offsetWidth;
|
| 139 |
-
const containerHeight = cloudContainer.offsetHeight;
|
| 140 |
-
|
| 141 |
-
// Sort clouds by percentage (highest first)
|
| 142 |
-
const sortedClouds = [...cloudData].sort((a, b) => b.percentage - a.percentage);
|
| 143 |
-
|
| 144 |
-
// Position clouds in a circular layout
|
| 145 |
-
const centerX = containerWidth / 2;
|
| 146 |
-
const centerY = containerHeight / 2;
|
| 147 |
-
const radius = Math.min(containerWidth, containerHeight) * 0.35;
|
| 148 |
-
|
| 149 |
-
sortedClouds.forEach((cloud, i) => {
|
| 150 |
-
// Calculate angle for positioning
|
| 151 |
-
const angle = (i / sortedClouds.length) * Math.PI * 2;
|
| 152 |
|
| 153 |
-
|
| 154 |
-
const
|
| 155 |
-
const y = centerY + Math.sin(angle) * radius;
|
| 156 |
|
| 157 |
-
//
|
| 158 |
-
const
|
| 159 |
-
createCloud(cloud, x, y, baseSize);
|
| 160 |
|
| 161 |
-
//
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
resultsSection.classList.remove('hidden');
|
| 170 |
similarityResults.innerHTML = '';
|
| 171 |
|
|
@@ -232,4 +221,4 @@ function showResults(inputText, similarities) {
|
|
| 232 |
createClouds();
|
| 233 |
}
|
| 234 |
});
|
| 235 |
-
});
|
|
|
|
| 1 |
|
| 2 |
document.addEventListener('DOMContentLoaded', async function() {
|
| 3 |
+
// Initialize cloud data
|
| 4 |
const cloudData = [
|
| 5 |
{ text: "Happiness", percentage: 0 },
|
| 6 |
{ text: "Adventure", percentage: 0 },
|
|
|
|
| 32 |
|
| 33 |
// Create initial clouds
|
| 34 |
createClouds();
|
| 35 |
+
|
| 36 |
// Add event listeners
|
| 37 |
analyzeBtn.addEventListener('click', () => {
|
| 38 |
analyzeBtn.disabled = true;
|
|
|
|
| 51 |
analyzeBtn.click();
|
| 52 |
}
|
| 53 |
});
|
| 54 |
+
|
| 55 |
+
function createClouds() {
|
| 56 |
+
cloudContainer.innerHTML = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
const containerWidth = cloudContainer.offsetWidth;
|
| 59 |
+
const containerHeight = cloudContainer.offsetHeight;
|
| 60 |
+
|
| 61 |
+
// Create a circular layout for initial clouds
|
| 62 |
+
const centerX = containerWidth / 2;
|
| 63 |
+
const centerY = containerHeight / 2;
|
| 64 |
+
const radius = Math.min(containerWidth, containerHeight) * 0.35;
|
| 65 |
+
|
| 66 |
+
cloudData.forEach((cloud, i) => {
|
| 67 |
+
const angle = (i / cloudData.length) * Math.PI * 2;
|
| 68 |
+
const x = centerX + Math.cos(angle) * radius;
|
| 69 |
+
const y = centerY + Math.sin(angle) * radius;
|
| 70 |
+
|
| 71 |
+
// Create cloud with base size
|
| 72 |
+
createCloud(cloud, x, y, 40);
|
| 73 |
+
});
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
function createCloud(data, x, y, baseSize) {
|
| 77 |
+
const cloud = document.createElement('custom-cloud');
|
| 78 |
+
cloud.setAttribute('text', data.text);
|
| 79 |
+
cloud.setAttribute('percentage', data.percentage);
|
| 80 |
+
|
| 81 |
+
// Position the cloud
|
| 82 |
+
cloud.style.position = 'absolute';
|
| 83 |
+
cloud.style.left = `${x}px`;
|
| 84 |
+
cloud.style.top = `${y}px`;
|
| 85 |
+
|
| 86 |
+
cloudContainer.appendChild(cloud);
|
| 87 |
+
return cloud;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
async function analyzeText() {
|
| 91 |
const inputText = textInput.value.trim();
|
| 92 |
if (!inputText) {
|
| 93 |
alert('Please enter some text to analyze');
|
| 94 |
return;
|
| 95 |
}
|
| 96 |
+
|
| 97 |
+
try {
|
| 98 |
// Generate embeddings for input text and cloud texts
|
| 99 |
const inputEmbedding = await model.embed([inputText]);
|
| 100 |
const cloudTexts = cloudData.map(c => c.text);
|
|
|
|
| 118 |
// Update UI with results
|
| 119 |
updateClouds();
|
| 120 |
showResults(inputText, similarities);
|
| 121 |
+
} catch (err) {
|
| 122 |
+
console.error('Error analyzing text:', err);
|
| 123 |
+
resultsSection.classList.add('hidden');
|
| 124 |
+
alert('An error occurred while analyzing your text. Please try again.');
|
| 125 |
+
throw err; // Re-throw to ensure button state is reset
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
function updateClouds() {
|
| 130 |
+
cloudContainer.innerHTML = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
const containerWidth = cloudContainer.offsetWidth;
|
| 133 |
+
const containerHeight = cloudContainer.offsetHeight;
|
|
|
|
| 134 |
|
| 135 |
+
// Sort clouds by percentage (highest first)
|
| 136 |
+
const sortedClouds = [...cloudData].sort((a, b) => b.percentage - a.percentage);
|
|
|
|
| 137 |
|
| 138 |
+
// Position clouds in a circular layout
|
| 139 |
+
const centerX = containerWidth / 2;
|
| 140 |
+
const centerY = containerHeight / 2;
|
| 141 |
+
const radius = Math.min(containerWidth, containerHeight) * 0.35;
|
| 142 |
+
|
| 143 |
+
sortedClouds.forEach((cloud, i) => {
|
| 144 |
+
// Calculate angle for positioning
|
| 145 |
+
const angle = (i / sortedClouds.length) * Math.PI * 2;
|
| 146 |
+
|
| 147 |
+
// Calculate position
|
| 148 |
+
const x = centerX + Math.cos(angle) * radius;
|
| 149 |
+
const y = centerY + Math.sin(angle) * radius;
|
| 150 |
+
|
| 151 |
+
// Create cloud with size based on percentage
|
| 152 |
+
const baseSize = 40 + (cloud.percentage * 0.8);
|
| 153 |
+
createCloud(cloud, x, y, baseSize);
|
| 154 |
+
});
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function showResults(inputText, similarities) {
|
| 158 |
resultsSection.classList.remove('hidden');
|
| 159 |
similarityResults.innerHTML = '';
|
| 160 |
|
|
|
|
| 221 |
createClouds();
|
| 222 |
}
|
| 223 |
});
|
| 224 |
+
});
|
style.css
CHANGED
|
@@ -61,24 +61,24 @@ body {
|
|
| 61 |
overflow: hidden;
|
| 62 |
}
|
| 63 |
custom-cloud {
|
| 64 |
-
display:
|
| 65 |
position: absolute;
|
| 66 |
transition: all 0.5s ease;
|
| 67 |
animation: float 3s ease-in-out infinite;
|
| 68 |
will-change: transform;
|
| 69 |
cursor: pointer;
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
custom-cloud:hover {
|
| 73 |
-
transform: scale(1.1) !important;
|
| 74 |
z-index: 100;
|
| 75 |
}
|
| 76 |
.cloud-text {
|
| 77 |
position: relative;
|
| 78 |
z-index: 2;
|
| 79 |
-
|
| 80 |
}
|
| 81 |
-
|
| 82 |
.cloud-percentage {
|
| 83 |
font-size: 0.6em;
|
| 84 |
display: block;
|
|
@@ -96,4 +96,4 @@ custom-cloud:hover {
|
|
| 96 |
|
| 97 |
#analyze-btn:hover {
|
| 98 |
transform: translateY(-50%) scale(1.1);
|
| 99 |
-
}
|
|
|
|
| 61 |
overflow: hidden;
|
| 62 |
}
|
| 63 |
custom-cloud {
|
| 64 |
+
display: block;
|
| 65 |
position: absolute;
|
| 66 |
transition: all 0.5s ease;
|
| 67 |
animation: float 3s ease-in-out infinite;
|
| 68 |
will-change: transform;
|
| 69 |
cursor: pointer;
|
| 70 |
+
transform: translate(-50%, -50%);
|
| 71 |
}
|
| 72 |
|
| 73 |
custom-cloud:hover {
|
| 74 |
+
transform: translate(-50%, -50%) scale(1.1) !important;
|
| 75 |
z-index: 100;
|
| 76 |
}
|
| 77 |
.cloud-text {
|
| 78 |
position: relative;
|
| 79 |
z-index: 2;
|
| 80 |
+
text-align: center;
|
| 81 |
}
|
|
|
|
| 82 |
.cloud-percentage {
|
| 83 |
font-size: 0.6em;
|
| 84 |
display: block;
|
|
|
|
| 96 |
|
| 97 |
#analyze-btn:hover {
|
| 98 |
transform: translateY(-50%) scale(1.1);
|
| 99 |
+
}
|