mi-api-temas / app.py
alexanderander30's picture
Create app.py
fdef2ed verified
raw
history blame contribute delete
657 Bytes
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline
from typing import List
app = FastAPI()
theme_classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli")
class ThemeRequest(BaseModel):
texts: List[str]
labels: List[str]
@app.post("/classify/")
def classify_themes(request: ThemeRequest):
results = theme_classifier(request.texts, candidate_labels=request.labels, multi_label=False)
main_themes = [res['labels'][0] for res in results]
return {"themes": main_themes}
@app.get("/")
def read_root():
return {"status": "API de Temas está en línea"}