Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, HTTPException | |
from typing import List | |
app = FastAPI() | |
async def read_root(): | |
return {"message": "Welcome to the FastAPI application!"} | |
async def classify(labels: List[dict]): | |
try: | |
# if labels is empty return 400 error | |
if not labels: | |
raise HTTPException(status_code=400, detail="No labels provided") | |
# Check if the highest score is lower than 0.6 | |
if labels[0]["score"] < 0.6: | |
predicted_label = "OTHER" | |
else: | |
# Find the label with the highest score | |
predicted_label = labels[0]["label"] | |
# Return the predicted label | |
return {"predicted_label": predicted_label} | |
except Exception as e: | |
raise HTTPException(status_code=500, detail=str(e)) | |