Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 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
|
| 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 |
|