Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,10 +93,32 @@ def recursive_chunking(text, source, chunk_size=500, overlap=100):
|
|
| 93 |
|
| 94 |
# --- CORE SEARCH ENGINE ---
|
| 95 |
class DocSearchEngine:
|
| 96 |
-
def __init__(self):
|
| 97 |
-
# Force CPU
|
| 98 |
-
self.bi_encoder = SentenceTransformer(
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
self.index = None
|
| 102 |
self.metadata = []
|
|
|
|
| 93 |
|
| 94 |
# --- CORE SEARCH ENGINE ---
|
| 95 |
class DocSearchEngine:
|
| 96 |
+
def __init__(self):def __init__(self):
|
| 97 |
+
# Force CPU and DISABLE "Meta Device" loading for both models
|
| 98 |
+
self.bi_encoder = SentenceTransformer(
|
| 99 |
+
'all-MiniLM-L6-v2',
|
| 100 |
+
device="cpu",
|
| 101 |
+
model_kwargs={"low_cpu_mem_usage": False}
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
self.cross_encoder = CrossEncoder(
|
| 105 |
+
'cross-encoder/ms-marco-MiniLM-L-6-v2',
|
| 106 |
+
device="cpu",
|
| 107 |
+
automodel_args={"low_cpu_mem_usage": False}
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
self.index = None
|
| 111 |
+
self.metadata = []
|
| 112 |
+
|
| 113 |
+
if os.path.exists(INDEX_FILE) and os.path.exists(META_FILE):
|
| 114 |
+
try:
|
| 115 |
+
self.index = faiss.read_index(INDEX_FILE)
|
| 116 |
+
with open(META_FILE, "rb") as f: self.metadata = pickle.load(f)
|
| 117 |
+
except Exception as e:
|
| 118 |
+
st.error(f"Index load failed, starting fresh: {e}")
|
| 119 |
+
self.reset_index()
|
| 120 |
+
else:
|
| 121 |
+
self.reset_index()
|
| 122 |
|
| 123 |
self.index = None
|
| 124 |
self.metadata = []
|