Create index.html
Browse files- index.html +66 -0
index.html
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Text Embedding and Similarity Search</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h1>Text Embedding and Similarity Search</h1>
|
8 |
+
|
9 |
+
<h2>Embed a string</h2>
|
10 |
+
<form id="embed-form">
|
11 |
+
<label for="embed-input">String to embed:</label><br>
|
12 |
+
<input type="text" id="embed-input" name="embed-input"><br>
|
13 |
+
<input type="submit" value="Embed">
|
14 |
+
</form>
|
15 |
+
|
16 |
+
<h2>Search for a string</h2>
|
17 |
+
<form id="search-form">
|
18 |
+
<label for="search-input">String to search:</label><br>
|
19 |
+
<input type="text" id="search-input" name="search-input"><br>
|
20 |
+
<label for="n-input">Number of results to return:</label><br>
|
21 |
+
<input type="number" id="n-input" name="n-input" min="1" value="5"><br>
|
22 |
+
<input type="submit" value="Search">
|
23 |
+
</form>
|
24 |
+
|
25 |
+
<div id="results"></div>
|
26 |
+
|
27 |
+
<script>
|
28 |
+
document.getElementById("embed-form").addEventListener("submit", function(event) {
|
29 |
+
event.preventDefault();
|
30 |
+
const text = document.getElementById("embed-input").value;
|
31 |
+
fetch("/embed", {
|
32 |
+
method: "POST",
|
33 |
+
headers: {
|
34 |
+
"Content-Type": "application/json"
|
35 |
+
},
|
36 |
+
body: JSON.stringify({text: text})
|
37 |
+
})
|
38 |
+
.then(response => response.json())
|
39 |
+
.then(data => {
|
40 |
+
document.getElementById("results").innerHTML = data.message;
|
41 |
+
});
|
42 |
+
});
|
43 |
+
|
44 |
+
document.getElementById("search-form").addEventListener("submit", function(event) {
|
45 |
+
event.preventDefault();
|
46 |
+
const text = document.getElementById("search-input").value;
|
47 |
+
const n = document.getElementById("n-input").value;
|
48 |
+
fetch("/search", {
|
49 |
+
method: "POST",
|
50 |
+
headers: {
|
51 |
+
"Content-Type": "application/json"
|
52 |
+
},
|
53 |
+
body: JSON.stringify({text: text, n: n})
|
54 |
+
})
|
55 |
+
.then(response => response.json())
|
56 |
+
.then(data => {
|
57 |
+
let resultsHtml = `<h3>Top ${n} results:</h3>`;
|
58 |
+
for (let i = 0; i < data.distances.length; i++) {
|
59 |
+
resultsHtml += `<p>${i+1}. Index: ${data.indices[i]}, Distance: ${data.distances[i]}</p>`;
|
60 |
+
}
|
61 |
+
document.getElementById("results").innerHTML = resultsHtml;
|
62 |
+
});
|
63 |
+
});
|
64 |
+
</script>
|
65 |
+
</body>
|
66 |
+
</html>
|