rbiswasfc commited on
Commit
c041aaa
·
1 Parent(s): ab53d63
Files changed (1) hide show
  1. app.py +20 -24
app.py CHANGED
@@ -1,9 +1,6 @@
1
- import base64
2
- import io
3
  import json
4
  import os
5
  from datetime import datetime
6
- from io import BytesIO
7
 
8
  import dotenv
9
  import lancedb
@@ -11,7 +8,6 @@ import requests
11
  from datasets import load_dataset
12
  from fasthtml.common import * # noqa
13
  from huggingface_hub import login, whoami
14
- from PIL import Image
15
  from rerankers import Reranker
16
 
17
 
@@ -257,33 +253,33 @@ def SearchResult(result):
257
  )
258
 
259
 
260
- def base64_to_pil(base64_string):
261
- # Remove the "data:image/png;base64," part if it exists
262
- if "base64," in base64_string:
263
- base64_string = base64_string.split("base64,")[1]
264
 
265
- # Decode the base64 string
266
- img_data = base64.b64decode(base64_string)
267
 
268
- # Open the image using PIL
269
- img = Image.open(BytesIO(img_data))
270
 
271
- return img
272
 
273
 
274
- def process_image(image, max_size=(500, 500), quality=85):
275
- pil_image = base64_to_pil(image)
276
- img_byte_arr = io.BytesIO()
277
- pil_image.thumbnail(max_size)
278
- pil_image.save(img_byte_arr, format="JPEG", quality=quality, optimize=True)
279
- return f"data:image/jpeg;base64,{base64.b64encode(img_byte_arr.getvalue()).decode('utf-8')}"
280
 
281
 
282
- # def ImageResult(image):
283
- # return Div(
284
- # Img(src=f"data:image/jpeg;base64,{image}", alt="arxiv image"),
285
- # cls="image-result",
286
- # )
287
 
288
 
289
  def ImageResult(image):
 
 
 
1
  import json
2
  import os
3
  from datetime import datetime
 
4
 
5
  import dotenv
6
  import lancedb
 
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
 
 
253
  )
254
 
255
 
256
+ # def base64_to_pil(base64_string):
257
+ # # Remove the "data:image/png;base64," part if it exists
258
+ # if "base64," in base64_string:
259
+ # base64_string = base64_string.split("base64,")[1]
260
 
261
+ # # Decode the base64 string
262
+ # img_data = base64.b64decode(base64_string)
263
 
264
+ # # Open the image using PIL
265
+ # img = Image.open(BytesIO(img_data))
266
 
267
+ # return img
268
 
269
 
270
+ # def process_image(image, max_size=(500, 500), quality=85):
271
+ # pil_image = base64_to_pil(image)
272
+ # img_byte_arr = io.BytesIO()
273
+ # pil_image.thumbnail(max_size)
274
+ # pil_image.save(img_byte_arr, format="JPEG", quality=quality, optimize=True)
275
+ # return f"data:image/jpeg;base64,{base64.b64encode(img_byte_arr.getvalue()).decode('utf-8')}"
276
 
277
 
278
+ def ImageResult(image):
279
+ return Div(
280
+ Img(src=f"data:image/jpeg;base64,{image}", alt="arxiv image"),
281
+ cls="image-result",
282
+ )
283
 
284
 
285
  def ImageResult(image):