Update app.py
Browse files
app.py
CHANGED
|
@@ -14,13 +14,13 @@ templates = Jinja2Templates(directory=".")
|
|
| 14 |
def read_root(request: Request):
|
| 15 |
return templates.TemplateResponse("index.html", {"request": request})
|
| 16 |
|
| 17 |
-
@app.
|
| 18 |
def embed_string(text: str):
|
| 19 |
embedding = model.encode([text])
|
| 20 |
index.add(np.array(embedding))
|
| 21 |
return {"message": "String embedded and added to FAISS database"}
|
| 22 |
|
| 23 |
-
@app.
|
| 24 |
def search_string(text: str, n: int = 5):
|
| 25 |
embedding = model.encode([text])
|
| 26 |
distances, indices = index.search(np.array(embedding), n)
|
|
|
|
| 14 |
def read_root(request: Request):
|
| 15 |
return templates.TemplateResponse("index.html", {"request": request})
|
| 16 |
|
| 17 |
+
@app.post("/embed")
|
| 18 |
def embed_string(text: str):
|
| 19 |
embedding = model.encode([text])
|
| 20 |
index.add(np.array(embedding))
|
| 21 |
return {"message": "String embedded and added to FAISS database"}
|
| 22 |
|
| 23 |
+
@app.post("/search")
|
| 24 |
def search_string(text: str, n: int = 5):
|
| 25 |
embedding = model.encode([text])
|
| 26 |
distances, indices = index.search(np.array(embedding), n)
|