from fastapi import FastAPI from pydantic import BaseModel import joblib app = FastAPI() try: model = joblib.load("model.pkl") print("Model loaded successfully.") except Exception as e: print(f"Error loading model: {e}") model = None class InputData(BaseModel): sepal_length: float sepal_width: float petal_length: float petal_width: float @app.get('/') def home(): return {"Message: This is live API for tesing prediction"} @app.post("/masala") def prediction(data: InputData): features = [[ data.sepal_length, data.sepal_width, data.petal_length, data.petal_width ]] result = model.predict(features) print(result) return {"Prediction": int(result[0])}