Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,15 @@
|
|
1 |
import faiss
|
2 |
-
import
|
3 |
-
from sentence_transformers import SentenceTransformer
|
4 |
|
5 |
-
# ๐น
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
# ๐น Load Embedding Model
|
10 |
-
embedder = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
11 |
-
|
12 |
-
# ๐น Test Query
|
13 |
-
test_query = "Where is ASA Microfinance located?"
|
14 |
-
query_embedding = embedder.encode([test_query], convert_to_tensor=True).cpu().numpy()
|
15 |
|
16 |
-
# ๐น
|
17 |
-
|
|
|
18 |
|
19 |
-
# ๐น
|
20 |
-
print("
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
print("๐น FAISS Distances:")
|
25 |
-
print(distances)
|
|
|
1 |
import faiss
|
2 |
+
import os
|
|
|
3 |
|
4 |
+
# ๐น Define FAISS File Path
|
5 |
+
FAISS_FILE = "asa_faiss.index" # This should be inside your space files
|
6 |
+
LOCAL_FAISS_PATH = os.path.join(os.getcwd(), FAISS_FILE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
# ๐น Check if FAISS File Exists
|
9 |
+
if not os.path.exists(LOCAL_FAISS_PATH):
|
10 |
+
raise FileNotFoundError(f"โ FAISS index file '{FAISS_FILE}' not found! Make sure it's uploaded to your Space.")
|
11 |
|
12 |
+
# ๐น Load FAISS Index
|
13 |
+
print(f"Loading FAISS index from {LOCAL_FAISS_PATH}...")
|
14 |
+
faiss_index = faiss.read_index(LOCAL_FAISS_PATH)
|
15 |
+
print("โ
FAISS index loaded successfully!")
|
|
|
|
|
|