Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
colpali fix
Browse files- RAG/colpali.py +18 -0
RAG/colpali.py
CHANGED
|
@@ -4,6 +4,7 @@ import random
|
|
| 4 |
import pprint
|
| 5 |
import os
|
| 6 |
from io import BytesIO
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Optional, cast
|
| 9 |
import numpy as np
|
|
@@ -154,6 +155,23 @@ def generate_ans(top_result,query):
|
|
| 154 |
return content_text
|
| 155 |
|
| 156 |
def img_highlight(img,batch_queries,query_tokens):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
# Reference from : https://github.com/tonywu71/colpali-cookbooks/blob/main/examples/gen_colpali_similarity_maps.ipynb
|
| 158 |
with open(img, "rb") as f:
|
| 159 |
img_b64 = base64.b64encode(f.read()).decode("utf-8")
|
|
|
|
| 4 |
import pprint
|
| 5 |
import os
|
| 6 |
from io import BytesIO
|
| 7 |
+
import glob
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Optional, cast
|
| 10 |
import numpy as np
|
|
|
|
| 155 |
return content_text
|
| 156 |
|
| 157 |
def img_highlight(img,batch_queries,query_tokens):
|
| 158 |
+
|
| 159 |
+
img_name = os.path.basename(img) # e.g., "my_image.png"
|
| 160 |
+
|
| 161 |
+
# Construct the search pattern
|
| 162 |
+
search_pattern = f"/home/user/app/similarity_maps/similarity_map_{img_name}_token_*"
|
| 163 |
+
|
| 164 |
+
# Search for matching files
|
| 165 |
+
matching_files = glob.glob(search_pattern)
|
| 166 |
+
|
| 167 |
+
# Check if any match exists
|
| 168 |
+
map_images = []
|
| 169 |
+
if matching_files:
|
| 170 |
+
print("✅ Matching similarity map exists:")
|
| 171 |
+
for file_path in matching_files:
|
| 172 |
+
print(f" - {file_path}")
|
| 173 |
+
map_images.append({'file':file_path})
|
| 174 |
+
return map_images
|
| 175 |
# Reference from : https://github.com/tonywu71/colpali-cookbooks/blob/main/examples/gen_colpali_similarity_maps.ipynb
|
| 176 |
with open(img, "rb") as f:
|
| 177 |
img_b64 = base64.b64encode(f.read()).decode("utf-8")
|