Spaces:
Sleeping
Sleeping
Update app_main.py
Browse files- app_main.py +5 -0
app_main.py
CHANGED
@@ -238,6 +238,9 @@ def extract_images_from_pdf(pdf_path, output_json_path):
|
|
238 |
except Exception as e:
|
239 |
raise RuntimeError(f"❌ Error in extract_images_from_pdf: {str(e)}")
|
240 |
|
|
|
|
|
|
|
241 |
def similarity_matching(input_json_path: str) -> str:
|
242 |
import uuid, shutil, tempfile
|
243 |
from langchain_experimental.open_clip.open_clip import OpenCLIPEmbeddings
|
@@ -318,6 +321,8 @@ def similarity_matching(input_json_path: str) -> str:
|
|
318 |
# ============================== #
|
319 |
# COMPUTE SIMILARITIES #
|
320 |
# ============================== #
|
|
|
|
|
321 |
similarity = np.matmul(np.array(sprite_features), np.array(img_features).T)
|
322 |
most_similar_indices = np.argmax(similarity, axis=1)
|
323 |
|
|
|
238 |
except Exception as e:
|
239 |
raise RuntimeError(f"❌ Error in extract_images_from_pdf: {str(e)}")
|
240 |
|
241 |
+
os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
|
242 |
+
os.environ["HF_HOME"] = "/app/cache"
|
243 |
+
|
244 |
def similarity_matching(input_json_path: str) -> str:
|
245 |
import uuid, shutil, tempfile
|
246 |
from langchain_experimental.open_clip.open_clip import OpenCLIPEmbeddings
|
|
|
321 |
# ============================== #
|
322 |
# COMPUTE SIMILARITIES #
|
323 |
# ============================== #
|
324 |
+
if not sprite_features or not img_features:
|
325 |
+
raise ValueError("❌ Embedding generation failed: One of the image feature lists is empty.")
|
326 |
similarity = np.matmul(np.array(sprite_features), np.array(img_features).T)
|
327 |
most_similar_indices = np.argmax(similarity, axis=1)
|
328 |
|