Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
from huggingface_hub import InferenceClient
|
|
|
|
| 6 |
|
| 7 |
from fastapi import Request
|
| 8 |
import requests
|
|
@@ -30,6 +31,16 @@ app.add_middleware(
|
|
| 30 |
)
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
@app.get("/invert")
|
| 34 |
async def invert(text: str):
|
| 35 |
return {
|
|
|
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
+
from sentence_transformers import SentenceTransformer
|
| 7 |
|
| 8 |
from fastapi import Request
|
| 9 |
import requests
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
|
| 34 |
+
app = FastAPI()
|
| 35 |
+
embedder = SentenceTransformer('sentence-transformers/distiluse-base-multilingual-cased-v1')
|
| 36 |
+
|
| 37 |
+
@app.post("/api/embed")
|
| 38 |
+
async def embed(request: Request):
|
| 39 |
+
data = await request.json()
|
| 40 |
+
texts = data.get("texts", [])
|
| 41 |
+
embeddings = embedder.encode(texts)
|
| 42 |
+
return {"embeddings": embeddings.tolist()}
|
| 43 |
+
|
| 44 |
@app.get("/invert")
|
| 45 |
async def invert(text: str):
|
| 46 |
return {
|