Bagi4's picture
fix: requirements.txt
dce67e9
raw
history blame
963 Bytes
import logging
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline
logging.basicConfig(
format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
level=logging.DEBUG,
datefmt='%Y-%m-%d %H:%M:%S'
)
classifier = pipeline("zero-shot-classification", model="models/classificator", use_fast=False)
app = FastAPI()
class RequestData(BaseModel):
multiLabel: bool
sequence: str
labels: list[str]
class ResponseData(BaseModel):
sequence: str
labels: list[str]
scores: list[float]
@app.post("/classify", response_model=ResponseData, tags=["Classificator"])
async def classify_text(data: RequestData):
result = classifier(data.sequence, data.labels, multi_label=data.multiLabel)
logging.info(result)
return result
@app.get("/ping", tags=["TEST"])
def ping():
return "pong"
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8000)