File size: 527 Bytes
9f2c4c2
757cf92
8b56784
9f2c4c2
8cc6110
8b56784
42ca00e
8b56784
a95c82c
9f2c4c2
 
a95c82c
 
9f2c4c2
 
 
 
8b56784
a132d67
627e0b2
9f2c4c2
757cf92
 
c4ed287
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from transformers import pipeline
import uvicorn

app = FastAPI()


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})