Commit
·
6b4360c
1
Parent(s):
e648cf1
Sentence trasformer for english-filipino
Browse files- app.py +16 -4
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,8 +1,20 @@
|
|
1 |
-
from
|
|
|
|
|
|
|
2 |
|
3 |
app = FastAPI()
|
|
|
4 |
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sentence_transformers import SentenceTransformer
|
2 |
+
from fastapi import FastAPI, HTTPException, Request
|
3 |
+
from pydantic import BaseModel
|
4 |
+
import torch
|
5 |
|
6 |
app = FastAPI()
|
7 |
+
model = SentenceTransformer("meedan/paraphrase-filipino-mpnet-base-v2")
|
8 |
|
9 |
|
10 |
+
class TextInput(BaseModel):
|
11 |
+
text: str
|
12 |
+
|
13 |
+
|
14 |
+
@app.post("/embed")
|
15 |
+
def embed_text(input: TextInput):
|
16 |
+
if len(input.text) > 5000:
|
17 |
+
raise HTTPException(status_code=400, detail="Text too long")
|
18 |
+
with torch.no_grad():
|
19 |
+
embedding = model.encode([input.text])[0].tolist()
|
20 |
+
return {"embedding": embedding}
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
fastapi
|
2 |
-
uvicorn
|
|
|
|
|
|
1 |
fastapi
|
2 |
+
uvicorn
|
3 |
+
sentence-transformers
|
4 |
+
torch
|