Spaces:
Runtime error
Runtime error
File size: 8,646 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 | <!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</title>
<link rel="stylesheet" href="style.css" />
<style>
.visual-forward-flow {
text-align: center;
}
table {
margin: 0 auto;
border-collapse: collapse;
width: 80%;
}
th,
td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
.calculate-similarity {
margin-top: 20px;
padding: 10px 20px;
background-color: #333;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
}
.calculate-similarity:hover {
background-color: #555;
}
.dropdown {
margin-top: 20px;
}
select {
padding: 5px;
font-size: 16px;
}
.results {
margin-top: 20px;
}
</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="visual-forward-flow">
<h2><strong>What is your Visual 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="img-text-form">
<div class="image-selection">
<label for="image-options">Choose an Image:</label>
<select id="image-options">
<option value="img1.jpg" selected>Image 1</option>
<option value="img2.jpg">Image 2</option>
<option value="img3.jpg">Image 3</option>
<option value="img4.jpg">Image 4</option>
<option value="img5.jpg">Image 5</option>
</select>
</div>
<img
id="selected-image"
src=""
alt="Selected Image"
class="center"
style="
display: none;
margin-top: 20px;
max-width: 30%;
height: auto;
"
/>
<div class="text-input">
<br />
<br />
<h2><b>Enter sentences</b></h2>
<table>
<tr>
<th>Sentence</th>
<th>Input</th>
</tr>
<tr>
<td>sentence 1</td>
<td><input type="text" name="sentence 1" /></td>
</tr>
<tr>
<td>sentence 2</td>
<td><input type="text" name="sentence 2" /></td>
</tr>
<tr>
<td>sentence 3</td>
<td><input type="text" name="sentence 3" /></td>
</tr>
<tr>
<td>sentence 4</td>
<td><input type="text" name="sentence 4" /></td>
</tr>
<tr>
<td>sentence 5</td>
<td><input type="text" name="sentence 5" /></td>
</tr>
<tr>
<td>sentence 6</td>
<td><input type="text" name="sentence 6" /></td>
</tr>
<tr>
<td>sentence 7</td>
<td><input type="text" name="sentence 7" /></td>
</tr>
<tr>
<td>sentence 8</td>
<td><input type="text" name="sentence 8" /></td>
</tr>
<tr>
<td>sentence 9</td>
<td><input type="text" name="sentence 9" /></td>
</tr>
<tr>
<td>sentence 10</td>
<td><input type="text" name="sentence 10" /></td>
<br />
<br />
</tr>
</table>
</div>
<br />
<button
class="calculate-similarity"
onclick="calculatesimilarity(event)"
>
Calculate Visual Forward Flow
</button>
</form>
<div class="results">
<h3>Similarity Scores</h3>
<table id="results-table">
<thead>
<tr>
<th>Sentence ID</th>
<th>Score</th>
<!-- Table headers will be appended here -->
</tr>
</thead>
<tbody>
<!-- score will be appended here -->
</tbody>
</table>
</div>
</section>
</main>
<footer class="footer">
<p>Copyright © 2024 Forward Flow</p>
</footer>
<script>
document.addEventListener("DOMContentLoaded", function () {
const imageSelect = document.getElementById("image-options");
const selectedImage = document.getElementById("selected-image");
selectedImage.src = imageSelect.value;
selectedImage.style.display = "block";
imageSelect.addEventListener("change", function () {
const imagePath = imageSelect.value;
selectedImage.src = imagePath;
selectedImage.style.display = "block";
});
function calculatesimilarity(event) {
event.preventDefault();
const form = document.getElementById("img-text-form");
// Collect form data
// Collect form data
const formData = new FormData(form);
const image = document.getElementById("image-options").value; // Get image path directly from the select element
//const image = formData.get("image-options"); // Updated this line to correctly retrieve image URL
console.log(image);
console.log("img was null");
const sentences = Array.from(formData.entries())
.filter(
([key, value]) =>
key.startsWith("sentence") && value.trim() !== ""
)
.map(([key, value]) => value);
fetch("/image_text", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ image, sentences }),
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const contentType = response.headers.get("content-type");
if (!contentType || !contentType.includes("application/json")) {
throw new TypeError("Response not in JSON format");
}
return response.json();
})
.then((data) => {
console.log("Similarity scores:", data.scores);
const scores = data.scores;
displayScores(data.scores);
})
.catch((error) => {
console.error("Error:", error);
alert(
"An error occurred while calculating similarity. Please try again later."
);
});
}
function displayScores(scores) {
const resultsTable = document
.getElementById("results-table")
.getElementsByTagName("tbody")[0];
resultsTable.innerHTML = ""; // Clear previous results
scores.forEach((score, index) => {
const tr = document.createElement("tr");
const imageTd = document.createElement("td");
imageTd.textContent = `Sentence ${index + 1}`;
tr.appendChild(imageTd);
const scoreTd = document.createElement("td");
scoreTd.textContent = score.toFixed(3);
tr.appendChild(scoreTd);
resultsTable.appendChild(tr);
});
}
document
.querySelector(".calculate-similarity")
.addEventListener("click", calculatesimilarity);
});
</script>
<script src="script.js"></script>
</body>
</html>
|