Spaces:
Sleeping
Sleeping
Commit ·
9e7ded3
1
Parent(s): 538d976
fix: graceful fallback when colpali_engine not installed
Browse filescolpali_retriever imports are now conditional so /compare endpoint
works on HF Spaces without colpali_engine; also fix local Qdrant path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- src/colpali_retriever.py +12 -9
src/colpali_retriever.py
CHANGED
|
@@ -4,17 +4,22 @@ Model: vidore/colpali-v1.2 (multi-vector, MaxSim scoring)
|
|
| 4 |
So sánh với pipeline text hiện tại để thấy sự khác biệt trên tài liệu có bảng biểu.
|
| 5 |
"""
|
| 6 |
import os
|
| 7 |
-
import torch
|
| 8 |
from pathlib import Path
|
| 9 |
-
from PIL import Image
|
| 10 |
-
from colpali_engine.models import ColPali, ColPaliProcessor
|
| 11 |
from qdrant_client import QdrantClient
|
| 12 |
from qdrant_client.models import (
|
| 13 |
Distance, VectorParams, MultiVectorConfig,
|
| 14 |
-
MultiVectorComparator, PointStruct,
|
| 15 |
)
|
| 16 |
from dotenv import load_dotenv
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
load_dotenv()
|
| 19 |
|
| 20 |
COLPALI_MODEL = "vidore/colpali-v1.2"
|
|
@@ -26,6 +31,8 @@ _processor = None
|
|
| 26 |
|
| 27 |
|
| 28 |
def _get_model():
|
|
|
|
|
|
|
| 29 |
global _model, _processor
|
| 30 |
if _model is None:
|
| 31 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -41,11 +48,7 @@ def _get_model():
|
|
| 41 |
|
| 42 |
|
| 43 |
def _get_client() -> QdrantClient:
|
| 44 |
-
|
| 45 |
-
api_key = os.getenv("QDRANT_API_KEY")
|
| 46 |
-
if url and api_key:
|
| 47 |
-
return QdrantClient(url=url, api_key=api_key, timeout=60)
|
| 48 |
-
return QdrantClient(path="qdrant_storage")
|
| 49 |
|
| 50 |
|
| 51 |
def _get_or_create_collection(client: QdrantClient):
|
|
|
|
| 4 |
So sánh với pipeline text hiện tại để thấy sự khác biệt trên tài liệu có bảng biểu.
|
| 5 |
"""
|
| 6 |
import os
|
|
|
|
| 7 |
from pathlib import Path
|
|
|
|
|
|
|
| 8 |
from qdrant_client import QdrantClient
|
| 9 |
from qdrant_client.models import (
|
| 10 |
Distance, VectorParams, MultiVectorConfig,
|
| 11 |
+
MultiVectorComparator, PointStruct,
|
| 12 |
)
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
|
| 15 |
+
try:
|
| 16 |
+
import torch
|
| 17 |
+
from PIL import Image
|
| 18 |
+
from colpali_engine.models import ColPali, ColPaliProcessor
|
| 19 |
+
COLPALI_AVAILABLE = True
|
| 20 |
+
except ImportError:
|
| 21 |
+
COLPALI_AVAILABLE = False
|
| 22 |
+
|
| 23 |
load_dotenv()
|
| 24 |
|
| 25 |
COLPALI_MODEL = "vidore/colpali-v1.2"
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
def _get_model():
|
| 34 |
+
if not COLPALI_AVAILABLE:
|
| 35 |
+
raise RuntimeError("colpali_engine not installed")
|
| 36 |
global _model, _processor
|
| 37 |
if _model is None:
|
| 38 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
def _get_client() -> QdrantClient:
|
| 51 |
+
return QdrantClient(path="qdrant_colpali")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
def _get_or_create_collection(client: QdrantClient):
|