Spaces:
Sleeping
Sleeping
Create app/main.py
Browse files- app/main.py +14 -0
app/main.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from sentence_transformers import SentenceTransformer
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
| 7 |
+
|
| 8 |
+
class EmbedRequest(BaseModel):
|
| 9 |
+
text: str
|
| 10 |
+
|
| 11 |
+
@app.post("/embed")
|
| 12 |
+
def embed_text(req: EmbedRequest):
|
| 13 |
+
emb = model.encode(req.text).tolist()
|
| 14 |
+
return {"embedding": emb}
|