Update app.py
Browse files
app.py
CHANGED
|
@@ -87,11 +87,25 @@ def download_documents():
|
|
| 87 |
|
| 88 |
##### TESTING ######
|
| 89 |
@app.post("/admin/documents/upload")
|
| 90 |
-
def upload_documents(
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
@app.get("/admin/database/download")
|
| 97 |
def download_database():
|
|
|
|
| 87 |
|
| 88 |
##### TESTING ######
|
| 89 |
@app.post("/admin/documents/upload")
|
| 90 |
+
def upload_documents(file: UploadFile = File(...)):
|
| 91 |
+
# Read the contents of the uploaded file
|
| 92 |
+
contents = file.file.read()
|
| 93 |
+
|
| 94 |
+
# Load the JSON data from the file contents
|
| 95 |
+
data = json.loads(contents)
|
| 96 |
+
|
| 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))
|
| 103 |
+
|
| 104 |
+
# Add the new documents to the documents list
|
| 105 |
+
documents.extend(new_documents)
|
| 106 |
+
|
| 107 |
+
return {"message": f"{len(new_documents)} new documents uploaded and embedded"}
|
| 108 |
+
|
| 109 |
|
| 110 |
@app.get("/admin/database/download")
|
| 111 |
def download_database():
|