Spaces:
Sleeping
Sleeping
File size: 510 Bytes
0d60a24 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import asyncio
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from transformers import AutoModel
embedding_model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-en', trust_remote_code=True)
app = FastAPI()
class Req(BaseModel):
input: list[str]
@app.post("/embeddings")
async def embeddings(req: Req):
def do():
embedding_model.encode(req.input).tolist()
return JSONResponse(
await asyncio.to_thread(do)
)
|