HUANG-Stephanie commited on
Commit
191bfa7
·
verified ·
1 Parent(s): 30a1a24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -89,19 +89,21 @@ async def search(query: str, k: int):
89
 
90
  results = []
91
  for idx in top_k_indices:
92
- results.append({"image": images[idx], "page": f"Page {idx}"})
 
 
 
93
 
94
  # Generate PDF
95
  pdf_buffer = BytesIO()
96
  c = canvas.Canvas(pdf_buffer, pagesize=letter)
97
  width, height = letter
 
98
  for result in results:
99
- img = result["image"]
100
- img_byte_arr = BytesIO()
101
- img.save(img_byte_arr, format='PNG')
102
- img_byte_arr = img_byte_arr.getvalue()
103
- img_base64 = base64.b64encode(img_byte_arr).decode('utf-8')
104
- c.drawImage(BytesIO(base64.b64decode(img_base64)), 0, 0, width, height)
105
  c.showPage()
106
 
107
  c.save()
 
89
 
90
  results = []
91
  for idx in top_k_indices:
92
+ img_byte_arr = BytesIO()
93
+ images[idx].save(img_byte_arr, format='PNG')
94
+ img_base64 = base64.b64encode(img_byte_arr.getvalue()).decode('utf-8')
95
+ results.append({"image": img_base64, "page": f"Page {idx}"})
96
 
97
  # Generate PDF
98
  pdf_buffer = BytesIO()
99
  c = canvas.Canvas(pdf_buffer, pagesize=letter)
100
  width, height = letter
101
+
102
  for result in results:
103
+ img_base64 = result["image"]
104
+ img_data = base64.b64decode(img_base64)
105
+ img_byte_arr = BytesIO(img_data)
106
+ c.drawImage(img_byte_arr, 0, 0, width, height)
 
 
107
  c.showPage()
108
 
109
  c.save()