Talha812 commited on
Commit
4d5c46d
·
verified ·
1 Parent(s): cd5f458

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
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
- index = faiss.IndexFlatL2(vector_dim)
 
 
 
 
 
 
 
 
 
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