-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (61 loc) · 2.09 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shower Thoughts Weaviate Demo</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>Shower thoughts Weaviate demo</h1>
<div>
<p>
Hi, I'm Dan! This is a demo of <a href="https://weaviate.io">Weaviate</a>, the AI-powered search engine (vector database) that I work on. I <a href="https://www.youtube.com/watch?v=FwD7Av2lsnE">love shower thoughts</a> so I made this semantic search engine for <a href="https://reddit.com/r/showerthoughts">shower thoughts</a> on a given topic (e.g. <code>cats</code>). Check out the <a href="https://github.com/dandv/shower-thoughts-weaviate">source code</a> or try it out below!
</p>
</div>
<form id="search">
<label>
<em>Fun topics to search for: cats, internet, battery, garbage, search, machine learning, dinosaurs...</em>
<input type="text" name="topic" placeholder="cats / internet / battery / ..." autofocus />
</label>
<button type="submit">Search</button>
</form>
<ul id="shower-thoughts">
<!-- shower thoughts go here -->
</ul>
<script type="module">
import { request, gql } from 'graphql-request';
const list = document.querySelector('#shower-thoughts');
// Create a shower thought element
function createSt(st) {
const li = document.createElement('li');
li.innerHTML = `${st.text} (<a href="${st.url}" target="_blank">${st.upvotes}</a>)`;
return li;
}
function search(event) {
event.preventDefault();
list.innerHTML = ''; // clear the list
const topic = this['topic'].value;
const query = gql`
{
Get {
ShowerThought(
nearText: { concepts: ["${topic}"] }
limit: 10
) {
text
url
upvotes
}
}
}
`;
request(process.env.GRAPHQL_URL, query).then(data => {
for (const st of data.Get.ShowerThought)
list.appendChild(createSt(st));
});
}
document.querySelector('#search').onsubmit = search;
</script>
</body>
</html>