paulbricman commited on
Commit
2651a3e
1 Parent(s): c1aed78

feat: beautify html response, add dummy content

Browse files
.gitignore CHANGED
@@ -1,2 +1 @@
1
- conceptarium/*
2
  __pycache__/*
 
1
  __pycache__/*
__pycache__/responses.cpython-38.pyc CHANGED
Binary files a/__pycache__/responses.cpython-38.pyc and b/__pycache__/responses.cpython-38.pyc differ
__pycache__/util.cpython-38.pyc CHANGED
Binary files a/__pycache__/util.cpython-38.pyc and b/__pycache__/util.cpython-38.pyc differ
conceptarium/8-Nui4nKCBU.jpeg ADDED
Binary file (380 kB). View file
conceptarium/9iLya2FSZKo.txt ADDED
@@ -0,0 +1 @@
 
1
+ A folded paper is like a 2D manifold embedded in 3D space. If you're *on* the paper, it seems flat, but for an outside observer it's clearly 3D.
conceptarium/LO_f_WBVokI.jpeg ADDED
Binary file (209 kB). View file
conceptarium/_ac9aiG6L0g.txt ADDED
@@ -0,0 +1 @@
 
1
+ In Origami, creating creases is like priming the paper to behave in certain ways, nudging its geometry to work in certain ways.
conceptarium/ibY8uSacriA.jpeg ADDED
Binary file (133 kB). View file
conceptarium/metadata.pickle ADDED
Binary file (12.2 kB). View file
conceptarium/style.css ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :root {
2
+ --custom-color: rgb(255, 108, 0);
3
+ }
4
+
5
+ * {
6
+ box-sizing: border-box;
7
+ font-family: monospace;
8
+ }
9
+
10
+ .board {
11
+ font-size: 16;
12
+ width: 100%;
13
+ text-align: center;
14
+ margin-bottom: 10px;
15
+ }
16
+
17
+ .header {
18
+ color: var(--custom-color);
19
+ text-align: center;
20
+ }
21
+
22
+ .header h2 {
23
+ font-weight: bold;
24
+ margin: 20px;
25
+ font-size: 30;
26
+ }
27
+
28
+ body {
29
+ background-color: azure;
30
+ }
31
+
32
+ .card-image {
33
+ width: 100%;
34
+ }
35
+
36
+ .card {
37
+ box-sizing: border-box;
38
+ border: 4px solid;
39
+ border-color: var(--custom-color);
40
+ background-color: var(--custom-color);
41
+ display: inline-block;
42
+ margin: 10px;
43
+ margin-bottom: 0px;
44
+ width: 40rem;
45
+ color: white;
46
+ font-weight: bold;
47
+ text-align: left;
48
+ }
49
+
50
+ @media only screen and (max-width: 768px) {
51
+ .card {
52
+ width: calc(100% - 20px);
53
+ margin-bottom: 0px;
54
+ }
55
+ }
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- sentence_transformers==2.0.0
2
  numpy
3
  fastapi
4
  Pillow
1
+ sentence_transformers
2
  numpy
3
  fastapi
4
  Pillow
responses.py CHANGED
@@ -1,6 +1,7 @@
1
  def html_response(thoughts):
2
  html = '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">'
3
  html += '<link rel="stylesheet" type="text/css" href="/conceptarium/style.css" media="screen" />'
 
4
  html += '<div class="board">'
5
 
6
  for thought in thoughts:
@@ -11,7 +12,7 @@ def html_response(thoughts):
11
  else:
12
  html += '<img class="card-img" src=\"/' + \
13
  thought.filename + '\">'
14
- html += '</div>'
15
 
16
  html += '</div>'
17
  return html
1
  def html_response(thoughts):
2
  html = '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">'
3
  html += '<link rel="stylesheet" type="text/css" href="/conceptarium/style.css" media="screen" />'
4
+ html += '<div class="header"><h2>conceptarium.</h2></div>'
5
  html += '<div class="board">'
6
 
7
  for thought in thoughts:
12
  else:
13
  html += '<img class="card-img" src=\"/' + \
14
  thought.filename + '\">'
15
+ html += '</div><br/>'
16
 
17
  html += '</div>'
18
  return html
util.py CHANGED
@@ -30,7 +30,7 @@ def remember(query, model, behavior='balanced', top_k=50):
30
  corpus_embeddings = [e.embedding for e in conceptarium]
31
 
32
  results = util.semantic_search(
33
- [query_embedding], corpus_embeddings, top_k=len(corpus_embeddings))[0]
34
  results = [e if modality_match[e['corpus_id']]
35
  else compensate_modality_mismatch(e) for e in results]
36
 
@@ -76,9 +76,9 @@ def load_model():
76
 
77
  def embed(content, model):
78
  if get_modality(content) == 'language':
79
- return model.encode(content, convert_to_tensor=True)
80
  else:
81
- return model.encode(Image.open(io.BytesIO(content)), convert_to_tensor=True)
82
 
83
 
84
  def get_modality(content):
@@ -89,7 +89,7 @@ def get_modality(content):
89
 
90
 
91
  def compensate_modality_mismatch(result):
92
- result['score'] *= 3.5
93
  return result
94
 
95
 
30
  corpus_embeddings = [e.embedding for e in conceptarium]
31
 
32
  results = util.semantic_search(
33
+ [query_embedding], corpus_embeddings, top_k=len(corpus_embeddings), score_function=util.dot_score)[0]
34
  results = [e if modality_match[e['corpus_id']]
35
  else compensate_modality_mismatch(e) for e in results]
36
 
76
 
77
  def embed(content, model):
78
  if get_modality(content) == 'language':
79
+ return model.encode(content, convert_to_tensor=True, normalize_embeddings=True)
80
  else:
81
+ return model.encode(Image.open(io.BytesIO(content)), convert_to_tensor=True, normalize_embeddings=True)
82
 
83
 
84
  def get_modality(content):
89
 
90
 
91
  def compensate_modality_mismatch(result):
92
+ result['score'] *= 2.5
93
  return result
94
 
95