from fastapi import FastAPI, HTTPException from app.model import IrisModel, IrisInput, IrisPrediction app = FastAPI(title="Iris Classification API", version="1.0.0") # Initialize model model = IrisModel() from fastapi.responses import HTMLResponse @app.get("/", response_class=HTMLResponse) def read_root(): return """ Iris Classification

Iris Classification Model

Enter the measurements of the iris flower to predict its species.

API Usage

You can also access this model via the API.

cURL

curl -X POST "https://nipun-ml-deploy-app.hf.space/predict" \
     -H "Content-Type: application/json" \
     -d '{"sepal_length": 5.1, "sepal_width": 3.5, "petal_length": 1.4, "petal_width": 0.2}'

Python

import requests

url = "https://nipun-ml-deploy-app.hf.space/predict"
data = {
    "sepal_length": 5.1,
    "sepal_width": 3.5,
    "petal_length": 1.4,
    "petal_width": 0.2
}

response = requests.post(url, json=data)
print(response.json())

JavaScript

fetch("https://nipun-ml-deploy-app.hf.space/predict", {
    method: "POST",
    headers: {
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        sepal_length: 5.1,
        sepal_width: 3.5,
        petal_length: 1.4,
        petal_width: 0.2
    })
})
.then(response => response.json())
.then(data => console.log(data));
""" @app.get("/health") def health_check(): return {"status": "healthy"} @app.post("/predict", response_model=IrisPrediction) def predict_iris(input_data: IrisInput): try: prediction = model.predict(input_data) return prediction except Exception as e: raise HTTPException(status_code=500, detail=str(e))