Spaces:
Sleeping
Sleeping
File size: 657 Bytes
fdef2ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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"} |