zero-shot-classification-zh/main.py

28 lines
559 B
Python
Raw Permalink Normal View History

2024-10-24 03:12:23 +00:00
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
2024-11-05 18:01:25 +00:00
from classification import ClassifyResult, classify as classifier
from config import HTTP_ARGS
2024-10-24 03:12:23 +00:00
app = FastAPI()
2024-10-24 05:07:11 +00:00
2024-10-24 03:12:23 +00:00
class TextClassificationRequest(BaseModel):
text: str
labels: list[str]
2024-10-24 05:07:11 +00:00
2024-11-05 18:01:25 +00:00
# class TextClassificationResponse(BaseModel):
# prediction: str
# ranks: list[str]
2024-10-24 03:12:23 +00:00
@app.post("/classify")
2024-11-05 18:01:25 +00:00
def classify(req: TextClassificationRequest) -> ClassifyResult:
2024-10-24 03:12:23 +00:00
2024-11-05 18:01:25 +00:00
return classifier(req.text, req.labels)
2024-10-24 03:12:23 +00:00
if __name__ == "__main__":
uvicorn.run(app, **HTTP_ARGS)