Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,11 @@
|
|
1 |
-
|
2 |
-
from pydantic import BaseModel
|
3 |
-
from sentence_transformers import SentenceTransformer
|
4 |
|
5 |
-
# Initialize FastAPI app
|
6 |
-
app = FastAPI()
|
7 |
-
|
8 |
-
# Load the BGE Chinese model
|
9 |
model = SentenceTransformer("BAAI/bge-small-zh")
|
10 |
|
11 |
-
|
12 |
-
class Texts(BaseModel):
|
13 |
texts: list[str]
|
14 |
|
15 |
-
# Embed endpoint
|
16 |
@app.post("/embed")
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
normalize_embeddings=True
|
21 |
-
).tolist()
|
22 |
-
return {"embeddings": embeddings}
|
|
|
1 |
+
app = FastAPI() # ✅ This line is critical
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
3 |
model = SentenceTransformer("BAAI/bge-small-zh")
|
4 |
|
5 |
+
class InputText(BaseModel):
|
|
|
6 |
texts: list[str]
|
7 |
|
|
|
8 |
@app.post("/embed")
|
9 |
+
def embed(texts: InputText):
|
10 |
+
vectors = model.encode(texts.texts, normalize_embeddings=True).tolist()
|
11 |
+
return {"embeddings": vectors}
|
|
|
|
|
|