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