rbiswasfc commited on
Commit
c3d6a88
1 Parent(s): 031ae25
Files changed (1) hide show
  1. app.py +43 -2
app.py CHANGED
@@ -4,11 +4,20 @@ from datetime import datetime
4
 
5
  import dotenv
6
  import lancedb
 
7
  from datasets import load_dataset
8
  from fasthtml.common import * # noqa
9
  from huggingface_hub import login, whoami
10
  from rerankers import Reranker
11
 
 
 
 
 
 
 
 
 
12
  dotenv.load_dotenv()
13
  login(token=os.environ.get("HF_TOKEN"))
14
 
@@ -77,7 +86,7 @@ def _format_results(results):
77
  return ret
78
 
79
 
80
- def retrieve_and_rerank(query, k=5):
81
  # retrieve ---
82
  n_fetch = 25
83
 
@@ -163,6 +172,21 @@ style = Style("""
163
  margin-right: 10px;
164
  vertical-align: middle;
165
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  """)
167
 
168
  # get the fast app and route
@@ -229,6 +253,13 @@ def SearchResult(result):
229
  )
230
 
231
 
 
 
 
 
 
 
 
232
  def log_query_and_results(query, results):
233
  log_entry = {
234
  "timestamp": datetime.now(),
@@ -241,9 +272,19 @@ def log_query_and_results(query, results):
241
  @rt("/search")
242
  async def post(query: str):
243
  results = retrieve_and_rerank(query)
 
 
244
  log_query_and_results(query, results)
245
 
246
- return Div(*[SearchResult(r) for r in results], id="search-results")
 
 
 
 
 
 
 
 
247
 
248
 
249
  def LogEntry(entry):
 
4
 
5
  import dotenv
6
  import lancedb
7
+ import requests
8
  from datasets import load_dataset
9
  from fasthtml.common import * # noqa
10
  from huggingface_hub import login, whoami
11
  from rerankers import Reranker
12
 
13
+
14
+ def get_images(query: str):
15
+ url = "http://147.189.194.113:80/get_pages"
16
+
17
+ response = requests.get(url, params={"query": query})
18
+ return response.json()
19
+
20
+
21
  dotenv.load_dotenv()
22
  login(token=os.environ.get("HF_TOKEN"))
23
 
 
86
  return ret
87
 
88
 
89
+ def retrieve_and_rerank(query, k=3):
90
  # retrieve ---
91
  n_fetch = 25
92
 
 
172
  margin-right: 10px;
173
  vertical-align: middle;
174
  }
175
+ .image-results {
176
+ display: flex;
177
+ flex-wrap: wrap;
178
+ gap: 10px;
179
+ margin-top: 20px;
180
+ }
181
+ .image-result {
182
+ width: calc(20% - 10px);
183
+ text-align: center;
184
+ }
185
+ .image-result img {
186
+ max-width: 100%;
187
+ height: auto;
188
+ border-radius: 5px;
189
+ }
190
  """)
191
 
192
  # get the fast app and route
 
253
  )
254
 
255
 
256
+ def ImageResult(image):
257
+ return Div(
258
+ Img(src=f"data:image/jpeg;base64,{image}", alt="arxiv image"),
259
+ cls="image-result",
260
+ )
261
+
262
+
263
  def log_query_and_results(query, results):
264
  log_entry = {
265
  "timestamp": datetime.now(),
 
272
  @rt("/search")
273
  async def post(query: str):
274
  results = retrieve_and_rerank(query)
275
+ image_results = get_images(query)
276
+
277
  log_query_and_results(query, results)
278
 
279
+ return Div(
280
+ H3("Byaldi Results"),
281
+ Div(*[ImageResult(img) for img in image_results], cls="image-results"),
282
+ H3("Text Results"),
283
+ Div(*[SearchResult(r) for r in results], id="text-results"),
284
+ id="search-results",
285
+ )
286
+
287
+ # return Div(*[SearchResult(r) for r in results], id="search-results")
288
 
289
 
290
  def LogEntry(entry):