BLY0608 commited on
Commit
c3c8e89
·
verified ·
1 Parent(s): 73ad7b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -1,22 +1,11 @@
1
- from fastapi import FastAPI
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
- # Define request format
12
- class Texts(BaseModel):
13
  texts: list[str]
14
 
15
- # Embed endpoint
16
  @app.post("/embed")
17
- async def embed(texts: Texts):
18
- embeddings = model.encode(
19
- texts.texts,
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}