Update app.py
Browse files
app.py
CHANGED
|
@@ -97,6 +97,22 @@ def upload_documents(file: UploadFile = File(...)):
|
|
| 97 |
# Get the list of documents from the JSON data
|
| 98 |
new_documents = data["texts"]
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# Encode the new documents and add them to the FAISS database
|
| 101 |
new_embeddings = model.encode(new_documents)
|
| 102 |
index.add(np.array(new_embeddings))
|
|
@@ -141,13 +157,14 @@ def download_database_0():
|
|
| 141 |
@app.post("/admin/database/upload")
|
| 142 |
def upload_database(file: UploadFile = File(...)):
|
| 143 |
# Read the contents of the uploaded file
|
| 144 |
-
contents =
|
| 145 |
|
| 146 |
# Load the FAISS index from the file contents
|
| 147 |
-
|
|
|
|
| 148 |
|
| 149 |
-
#
|
| 150 |
-
documents
|
| 151 |
-
documents.
|
| 152 |
|
| 153 |
-
return {"message": "Database uploaded
|
|
|
|
| 97 |
# Get the list of documents from the JSON data
|
| 98 |
new_documents = data["texts"]
|
| 99 |
|
| 100 |
+
# Add the new documents to the documents list
|
| 101 |
+
documents.extend(new_documents)
|
| 102 |
+
|
| 103 |
+
return {"message": f"{len(new_documents)} new documents uploaded"}
|
| 104 |
+
|
| 105 |
+
@app.post("/admin/documents/embed")
|
| 106 |
+
def embed_documents(file: UploadFile = File(...)):
|
| 107 |
+
# Read the contents of the uploaded file
|
| 108 |
+
contents = file.file.read()
|
| 109 |
+
|
| 110 |
+
# Load the JSON data from the file contents
|
| 111 |
+
data = json.loads(contents)
|
| 112 |
+
|
| 113 |
+
# Get the list of documents from the JSON data
|
| 114 |
+
new_documents = data["texts"]
|
| 115 |
+
|
| 116 |
# Encode the new documents and add them to the FAISS database
|
| 117 |
new_embeddings = model.encode(new_documents)
|
| 118 |
index.add(np.array(new_embeddings))
|
|
|
|
| 157 |
@app.post("/admin/database/upload")
|
| 158 |
def upload_database(file: UploadFile = File(...)):
|
| 159 |
# Read the contents of the uploaded file
|
| 160 |
+
contents = file.file.read()
|
| 161 |
|
| 162 |
# Load the FAISS index from the file contents
|
| 163 |
+
global index
|
| 164 |
+
index = faiss.read_index_binary(contents)
|
| 165 |
|
| 166 |
+
# Clear the existing documents list and add the new documents
|
| 167 |
+
#global documents
|
| 168 |
+
#documents = index.reconstruct_n(0, index.ntotal).tolist()
|
| 169 |
|
| 170 |
+
return {"message": f"Database uploaded with {len(documents)} documents"}
|