File size: 671 Bytes
a9561be 49df4b6 d9355ac 49df4b6 d9355ac 49df4b6 a9561be a58942c c11b2c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from transformers import pipeline
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Adjust this if you know the specific origin
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
classifier = pipeline("zero-shot-classification", model="valhalla/distilbart-mnli-12-1")
@app.get("/")
def greet_json():
return "Hello"
@app.post('/zero-shot-classification')
def classify(source: str, labels: list[str]) -> dict[str, str]:
c = classifier(source, candidate_labels = labels)
return dict(zip(c['labels'], c['scores']))
|