Futuresony commited on
Commit
5b8d85d
ยท
verified ยท
1 Parent(s): 40845a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -1,25 +1,15 @@
1
  import faiss
2
- import numpy as np
3
- from sentence_transformers import SentenceTransformer
4
 
5
- # ๐Ÿ”น Load FAISS Index
6
- FAISS_PATH = "asa_faiss.index"
7
- faiss_index = faiss.read_index(FAISS_PATH)
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
- # ๐Ÿ”น Search FAISS
17
- distances, indices = faiss_index.search(query_embedding, 3) # Retrieve top 3 matches
 
18
 
19
- # ๐Ÿ”น Print Results
20
- print("๐Ÿ”น FAISS Search Results:")
21
- for idx in indices[0]:
22
- print(f"Index: {idx}")
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!")