fast-api / app.py
samanthakarungi's picture
Upload main app file
bc07c80 verified
raw
history blame contribute delete
No virus
833 Bytes
from fastapi import FastAPI, HTTPException
from typing import List
app = FastAPI()
@app.get("/")
async def read_root():
return {"message": "Welcome to the FastAPI application!"}
@app.post("/classify")
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))