Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,16 @@ def create_chunks(text, chunk_size):
|
|
33 |
|
34 |
# Function to create FAISS vector store
|
35 |
def create_faiss_index(chunks, vector_dim):
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
embeddings = np.random.rand(len(chunks), vector_dim).astype('float32') # Replace with real embeddings
|
38 |
index.add(embeddings)
|
39 |
return index, embeddings
|
|
|
33 |
|
34 |
# Function to create FAISS vector store
|
35 |
def create_faiss_index(chunks, vector_dim):
|
36 |
+
# Check if GPU is available and use it
|
37 |
+
if faiss.get_num_gpus() > 0:
|
38 |
+
st.write("Using GPU for FAISS indexing.")
|
39 |
+
resource = faiss.StandardGpuResources() # Initialize GPU resources
|
40 |
+
index_flat = faiss.IndexFlatL2(vector_dim)
|
41 |
+
index = faiss.index_cpu_to_gpu(resource, 0, index_flat)
|
42 |
+
else:
|
43 |
+
st.write("Using CPU for FAISS indexing.")
|
44 |
+
index = faiss.IndexFlatL2(vector_dim)
|
45 |
+
|
46 |
embeddings = np.random.rand(len(chunks), vector_dim).astype('float32') # Replace with real embeddings
|
47 |
index.add(embeddings)
|
48 |
return index, embeddings
|