Spaces:
Sleeping
Sleeping
File size: 624 Bytes
6a13fbc 6aa465d 6a13fbc 6aa465d 6a13fbc 6aa465d 6a13fbc 6aa465d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from fastapi import FastAPI
from sentence_transformers import SentenceTransformer
from pydantic import BaseModel
from typing import List
class Query(BaseModel):
sentence: str
class Response(BaseModel):
embedding: List[float]
model = SentenceTransformer('Alibaba-NLP/gte-large-en-v1.5', trust_remote_code=True)
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World!"}
@app.post("/embeddings", response_model=Response)
def get_embedding(query: Query) -> Response:
sentence = query.sentence
embedding = model.encode(sentence).tolist()
return Response(embedding=embedding)
|