Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,10 +67,9 @@ class FastPDFSearch:
|
|
| 67 |
img = img.convert('RGB')
|
| 68 |
img_byte_arr = io.BytesIO()
|
| 69 |
img.save(img_byte_arr, format='PNG')
|
| 70 |
-
img_byte_arr
|
| 71 |
-
img_base64 = base64.b64encode(img_byte_arr).decode()
|
| 72 |
doc.close()
|
| 73 |
-
return
|
| 74 |
doc.close()
|
| 75 |
return None
|
| 76 |
except Exception as e:
|
|
@@ -86,16 +85,19 @@ class FastPDFSearch:
|
|
| 86 |
filename = result.metadata["filename"]
|
| 87 |
page_number = result.metadata["page_number"]
|
| 88 |
text = result.page_content
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
# --- Gradio UI ---
|
| 93 |
searcher = FastPDFSearch()
|
| 94 |
|
| 95 |
def gradio_search(query):
|
| 96 |
-
text,
|
| 97 |
-
if
|
| 98 |
-
return text, [(
|
| 99 |
else:
|
| 100 |
return text, []
|
| 101 |
|
|
|
|
| 67 |
img = img.convert('RGB')
|
| 68 |
img_byte_arr = io.BytesIO()
|
| 69 |
img.save(img_byte_arr, format='PNG')
|
| 70 |
+
img_byte_arr.seek(0)
|
|
|
|
| 71 |
doc.close()
|
| 72 |
+
return img_byte_arr
|
| 73 |
doc.close()
|
| 74 |
return None
|
| 75 |
except Exception as e:
|
|
|
|
| 85 |
filename = result.metadata["filename"]
|
| 86 |
page_number = result.metadata["page_number"]
|
| 87 |
text = result.page_content
|
| 88 |
+
img_bytes = self.get_pdf_page_image(self.pdf_files[filename], page_number)
|
| 89 |
+
if img_bytes:
|
| 90 |
+
return text, img_bytes, f"{filename} - Page {page_number}"
|
| 91 |
+
else:
|
| 92 |
+
return text, None, f"{filename} - Page {page_number}"
|
| 93 |
|
| 94 |
# --- Gradio UI ---
|
| 95 |
searcher = FastPDFSearch()
|
| 96 |
|
| 97 |
def gradio_search(query):
|
| 98 |
+
text, img_bytes, label = searcher.search(query)
|
| 99 |
+
if img_bytes:
|
| 100 |
+
return text, [(img_bytes, label)]
|
| 101 |
else:
|
| 102 |
return text, []
|
| 103 |
|