Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from sentence_transformers import SentenceTransformer
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
model = SentenceTransformer("thenlper/gte-small")
|
| 9 |
+
|
| 10 |
+
class EmbedInput(BaseModel):
|
| 11 |
+
text: str
|
| 12 |
+
|
| 13 |
+
@app.post("/embed")
|
| 14 |
+
async def embed_text(payload: EmbedInput):
|
| 15 |
+
embedding = model.encode(payload.text, normalize_embeddings=True)
|
| 16 |
+
return {"embedding": embedding.tolist()}
|