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']))