Spaces:
Sleeping
Sleeping
File size: 541 Bytes
9f2c4c2 8b56784 9f2c4c2 8b56784 9f2c4c2 8b56784 a95c82c 9f2c4c2 a95c82c 9f2c4c2 8b56784 a132d67 9f2c4c2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from transformers import pipeline
app = FastAPI(debug=True, title="Text classifier")
class Payload(BaseModel):
text: str
async def classify_text(text):
pipe = pipeline("text-classification",
model="SamLowe/roberta-base-go_emotions")
return pipe(text)
@app.post("/classify")
async def classify(payload: Payload):
result = await classify_text(payload.text)
return JSONResponse({"data": result}) |