arjunanand13 commited on
Commit
7b1bacb
·
verified ·
1 Parent(s): 09e2eff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -41,9 +41,12 @@ class Chatbot:
41
  self.embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2", model_kwargs={"device": "cuda"})
42
 
43
  try:
 
44
  cpu_index = faiss.read_index('faiss_index_new_model3.index')
45
- gpu_resource = faiss.StandardGpuResources()
46
- self.vectorstore = faiss.index_cpu_to_gpu(gpu_resource, 0, cpu_index)
 
 
47
  print("Loaded embedding successfully")
48
  except Exception as e:
49
  print("FAISS could not be imported or index could not be loaded.")
@@ -60,10 +63,10 @@ class Chatbot:
60
  return False
61
 
62
  def format_prompt(self, query):
63
- prompt=f"""
64
  You are a knowledgeable assistant with access to a comprehensive database.
65
  I need you to answer my question and provide related information in a specific format.
66
- I have provided four relatable json files , choose the most suitable chunks for answering the query
67
  Here's what I need:
68
  Include a final answer without additional comments, sign-offs, or extra phrases. Be direct and to the point.
69
 
 
41
  self.embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2", model_kwargs={"device": "cuda"})
42
 
43
  try:
44
+ # Initialize FAISS with GPU support
45
  cpu_index = faiss.read_index('faiss_index_new_model3.index')
46
+ res = faiss.StandardGpuResources() # Use this to allocate the GPU resources
47
+ co = faiss.GpuClonerOptions()
48
+ co.useFloat16 = True # Enable float16 for better performance
49
+ self.vectorstore = faiss.index_cpu_to_gpu(res, 0, cpu_index, co)
50
  print("Loaded embedding successfully")
51
  except Exception as e:
52
  print("FAISS could not be imported or index could not be loaded.")
 
63
  return False
64
 
65
  def format_prompt(self, query):
66
+ prompt = f"""
67
  You are a knowledgeable assistant with access to a comprehensive database.
68
  I need you to answer my question and provide related information in a specific format.
69
+ I have provided four relatable json files, choose the most suitable chunks for answering the query.
70
  Here's what I need:
71
  Include a final answer without additional comments, sign-offs, or extra phrases. Be direct and to the point.
72