Spaces:
Runtime error
Runtime error
File size: 13,868 Bytes
9756872 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Try It Out - Forward Flow with Visuals</title>
<link rel="stylesheet" href="style.css" />
<style>
.forward-flow-test {
text-align: center;
}
.container {
display: flex;
justify-content: center;
align-items: center;
}
table {
border-collapse: collapse;
width: 80%;
margin-right: 20px; /* Space between the table and the image */
}
th,
td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
.plot-creativity {
margin-top: 20px;
padding: 10px 20px;
background-color: #333;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
}
.plot-creativity:hover {
background-color: #555;
}
.dropdown {
margin-top: 20px;
}
select {
padding: 5px;
font-size: 16px;
}
.results {
margin-top: 20px;
}
.image-container {
display: flex;
justify-content: center;
align-items: center;
margin-top: 20px;
padding: 20px; /* Added padding around the image */
background-color: #f9f9f9; /* Light background to highlight the image */
border-radius: 10px; /* Rounded corners */
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.1); /* Subtle shadow */
}
.image-container img {
max-width: 400px; /* Adjust the width as needed */
height: 400px; /* Explicit height */
width: auto; /* Maintain aspect ratio */
border-radius: 10px; /* Rounded corners for images */
transition: transform 0.3s, box-shadow 0.3s; /* Smooth transition for hover effects */
}
.image-container img:hover {
transform: scale(1.05); /* Slight zoom on hover */
box-shadow: 0px 6px 20px rgba(0, 0, 0, 0.2); /* Enhanced shadow on hover */
}
#selected-word-image {
max-width: 400px; /* Adjust the width as needed */
height: 400px; /* Explicit height */
width: auto; /* Maintain aspect ratio */
border-radius: 10px; /* Rounded corners for the dynamic image */
}
.large-input {
width: 600px; /* Adjust the width as needed */
height: 10px; /* Adjust the height as needed */
font-size: 12px; /* Adjust the font size as needed */
padding: 6px; /* Adjust the padding as needed */
}
</style>
</head>
<body>
<header class="header">
<h1>Forward Flow</h1>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="page2.html">About Forward Flow</a></li>
<li><a href="page3.html">Try it out</a></li>
<li><a href="page4.html">Analyze data</a></li>
<li><a href="page5.html">Visual Creativity</a></li>
<li><a href="page6.html">Visual Forward Flow</a></li>
</ul>
</nav>
</header>
<main class="main">
<section class="forward-flow-test">
<h2><strong>What is your forward flow?</strong></h2>
<p>
<strong>
Beginning with the word <span id="starting-word">sleep</span>, in
each of the following blanks, write the next word that comes to mind
from the previous word. Please use only single words and no proper
nouns.
</strong>
</p>
<form id="word-form">
<p>Starting word: <strong id="starting-word-text">sleep</strong></p>
<div class="container">
<table>
<tr>
<th>Word</th>
<th>Input</th>
</tr>
<tr>
<td>Word 1</td>
<td>
<input
type="text"
name="word1"
id="word1"
value="sleep"
class="large-input"
readonly
/>
</td>
</tr>
<tr>
<td>Word 2</td>
<td><input type="text" name="word2" class="large-input" /></td>
</tr>
<tr>
<td>Word 3</td>
<td><input type="text" name="word3" class="large-input" /></td>
</tr>
<tr>
<td>Word 4</td>
<td><input type="text" name="word4" class="large-input" /></td>
</tr>
<tr>
<td>Word 5</td>
<td><input type="text" name="word5" class="large-input" /></td>
</tr>
<tr>
<td>Word 6</td>
<td><input type="text" name="word6" class="large-input" /></td>
</tr>
<tr>
<td>Word 7</td>
<td><input type="text" name="word7" class="large-input" /></td>
</tr>
<tr>
<td>Word 8</td>
<td><input type="text" name="word8" class="large-input" /></td>
</tr>
<tr>
<td>Word 9</td>
<td><input type="text" name="word9" class="large-input" /></td>
</tr>
<tr>
<td>Word 10</td>
<td><input type="text" name="word10" class="large-input" /></td>
</tr>
</table>
<div class="image-container" id="image-container">
<!-- Image elements will be dynamically added here -->
</div>
</div>
<div class="dropdown">
<label for="word-options">Choose a word list:</label>
<select id="word-options">
<option value="sleep">Sleep</option>
<option value="I am dreaming of ships">
I am dreaming of ships
</option>
<option value="rest">Rest</option>
<option value="nap">Nap</option>
<option value="joy">Joy</option>
<option value="fear">Fear</option>
<option value="anger">Anger</option>
<option value="love">Love</option>
<option value="hope">Hope</option>
<option value="sadness">Sadness</option>
<option value="peace">Peace</option>
<option value="conflict">Conflict</option>
<option value="freedom">Freedom</option>
<option value="guilt">Guilt</option>
<option value="happiness">Happiness</option>
<option value="trust">Trust</option>
<option value="grief">Grief</option>
<option value="surprise">Surprise</option>
<option value="boredom">Boredom</option>
<option value="toaster">Toaster</option>
<option value="excitement">Excitement</option>
<option value="curiosity">Curiosity</option>
</select>
</div>
<button class="plot-creativity" onclick="plotCreativity(event)">
Plot the Creativity
</button>
</form>
<div class="results">
<h3>Similarity Matrix</h3>
<table id="results-table">
<thead>
<tr>
<th></th>
<!-- Table headers will be appended here -->
</tr>
</thead>
<tbody>
<!-- Matrix will be appended here -->
</tbody>
</table>
<h3>Serial Scores</h3>
<table id="serial-scores-table">
<thead>
<tr>
<th>Word</th>
<th>Serial Score</th>
</tr>
</thead>
<tbody>
<!-- Serial scores will be appended here -->
</tbody>
</table>
<h2>Forward Flow Score</h2>
<p id="forward-flow-score"></p>
</div>
</section>
</main>
<footer class="footer">
<p>Copyright © 2024 Forward Flow</p>
</footer>
<script>
// JavaScript to update the word1 value and image based on dropdown selection
document
.getElementById("word-options")
.addEventListener("change", function () {
const selectedOption = this.value;
document.getElementById("word1").value = selectedOption;
// Update the starting word text
document.getElementById("starting-word-text").textContent =
selectedOption;
// Dynamically change the image based on selection
const imageContainer = document.getElementById("image-container");
const images = {
sleep: "sleep.jpg",
rest: "rest.jpg",
nap: "nap.jpg",
joy: "joy.jpg",
fear: "fear.jpg",
anger: "anger.jpg",
love: "love.jpg",
hope: "hope.jpg",
sadness: "sadness.jpg",
peace: "peace.jpg",
conflict: "conflict.jpg",
freedom: "freedom.jpg",
guilt: "guilt.jpg",
happiness: "happiness.jpg",
trust: "trust.jpg",
grief: "grief.jpg",
surprise: "surprise.jpg",
boredom: "boredom.jpg",
toaster: "toaster.jpg",
excitement: "excitement.jpg",
curiosity: "curiosity.jpg",
};
// Clear the previous image
imageContainer.innerHTML = "";
// Create a new img element and append it
const imgElement = document.createElement("img");
imgElement.src = images[selectedOption];
imgElement.alt = selectedOption;
// Add the new img element to the image container
imageContainer.appendChild(imgElement);
});
let serialsentencearray = [];
function plotCreativity(event) {
event.preventDefault();
// Your existing plot creativity logic here...
const form = document.getElementById("word-form");
const formData = new FormData(form);
const sentences = Array.from(formData.values());
// Send data to the backend
fetch("/similarity", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ sentences }),
})
.then((response) => response.json())
.then((data) => {
console.log("Similarity matrix:", data.matrix);
console.log("Serial score:", data.serial_score);
console.log("Sentiment:", data.sentiments);
serialsentencearray = data.serial_score.map((score, index) => {
return { serial_score: score, sentence: sentences[index] };
});
displayMatrix(data.matrix, sentences);
displaySerialScore(data.serial_score, sentences, data.sentiments);
displayForwardFlowScore(data.serial_score);
navigateToGraph(data.serial_score, sentences);
})
.catch((error) => console.error("Error:", error));
}
function displayMatrix(matrix, sentences) {
const resultsTable = document.getElementById("results-table");
const thead = resultsTable.getElementsByTagName("thead")[0];
const tbody = resultsTable.getElementsByTagName("tbody")[0];
// Clear previous results
thead.innerHTML = "<tr><th></th></tr>";
tbody.innerHTML = "";
// Append headers
sentences.forEach((sentence) => {
const th = document.createElement("th");
th.textContent = sentence;
thead.getElementsByTagName("tr")[0].appendChild(th);
});
// Append matrix values
matrix.forEach((row, i) => {
const tr = document.createElement("tr");
const rowHeader = document.createElement("th");
rowHeader.textContent = sentences[i];
tr.appendChild(rowHeader);
row.forEach((value) => {
const td = document.createElement("td");
td.textContent = value.toFixed(2); // Format score to 2 decimal places
tr.appendChild(td);
});
tbody.appendChild(tr);
});
}
function displaySerialScore(scores, sentences, sentiments) {
const scoresTable = document.getElementById("serial-scores-table");
const tbody = scoresTable.getElementsByTagName("tbody")[0];
tbody.innerHTML = "";
sentences.forEach((sentence, index) => {
const tr = document.createElement("tr");
const wordTd = document.createElement("td");
wordTd.textContent = sentence;
tr.appendChild(wordTd);
const scoreTd = document.createElement("td");
scoreTd.textContent = scores[index].toFixed(2); // Format score to 2 decimal places
tr.appendChild(scoreTd);
const sentimentTd = document.createElement("td");
sentimentTd.textContent = sentiments[index];
tr.appendChild(sentimentTd);
tbody.appendChild(tr);
});
}
function displayForwardFlowScore(scores) {
const forwardFlowScoreElement =
document.getElementById("forward-flow-score");
const total = scores.reduce((sum, score) => sum + score, 0);
const average = total / 9;
forwardFlowScoreElement.textContent = average.toFixed(3);
}
document
.querySelector(".plot-creativity")
.addEventListener("click", plotCreativity);
</script>
<script src="script.js"></script>
</body>
</html>
|