Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,18 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
2 |
|
3 |
app = FastAPI()
|
|
|
|
|
4 |
|
5 |
@app.get("/")
|
6 |
def greet_json():
|
7 |
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from sentence_transformers import SentenceTransformer
|
3 |
+
import faiss
|
4 |
+
import numpy as np
|
5 |
|
6 |
app = FastAPI()
|
7 |
+
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
8 |
+
index = faiss.IndexFlatL2(384) # 384 is the dimensionality of the MiniLM model
|
9 |
|
10 |
@app.get("/")
|
11 |
def greet_json():
|
12 |
return {"Hello": "World!"}
|
13 |
+
|
14 |
+
@app.post("/embed")
|
15 |
+
def embed_string(text: str):
|
16 |
+
embedding = model.encode([text])
|
17 |
+
index.add(np.array(embedding))
|
18 |
+
return {"message": "String embedded and added to FAISS database"}
|