Update app.py
Browse files
app.py
CHANGED
|
@@ -138,6 +138,18 @@ def download_database():
|
|
| 138 |
|
| 139 |
@app.post("/admin/database/upload")
|
| 140 |
def upload_database(file: UploadFile = File(...)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# Open the uploaded file as a binary file object
|
| 142 |
with open(file.filename, "wb") as f:
|
| 143 |
f.write(file.file.read())
|
|
|
|
| 138 |
|
| 139 |
@app.post("/admin/database/upload")
|
| 140 |
def upload_database(file: UploadFile = File(...)):
|
| 141 |
+
# Read the contents of the uploaded file
|
| 142 |
+
contents = file.file.read()
|
| 143 |
+
|
| 144 |
+
# Load the FAISS index from the file contents
|
| 145 |
+
global index
|
| 146 |
+
index = faiss.read_index_binary(io.BytesIO(contents))
|
| 147 |
+
|
| 148 |
+
return {"message": f"Database uploaded with {index.ntotal} embeddings"}
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def upload_database_1(file: UploadFile = File(...)):
|
| 153 |
# Open the uploaded file as a binary file object
|
| 154 |
with open(file.filename, "wb") as f:
|
| 155 |
f.write(file.file.read())
|