Spaces:
Sleeping
Sleeping
add model
Browse files- app.py +15 -4
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -1,7 +1,18 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("NlpHUST/vi-word-segmentation")
|
| 8 |
+
model = AutoModelForTokenClassification.from_pretrained("NlpHUST/vi-word-segmentation")
|
| 9 |
+
nlp = pipeline("token-classification", model=model, tokenizer=tokenizer)
|
| 10 |
+
|
| 11 |
+
class InputText(BaseModel):
|
| 12 |
+
text: str
|
| 13 |
+
|
| 14 |
+
@app.post("/segment")
|
| 15 |
+
async def segment_text(payload: InputText):
|
| 16 |
+
text = payload.text
|
| 17 |
+
result = nlp(text)
|
| 18 |
+
return result
|
requirements.txt
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
fastapi
|
| 2 |
-
uvicorn[standard]
|
|
|
|
|
|
|
|
|
| 1 |
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
transformers
|
| 4 |
+
torch
|