import joblib from fastapi import FastAPI import pickle import pandas as pd import os # main.py # relative import # optional if using as module app = FastAPI() MODEL_PATH = "models/best_model.pkl" # Train model if it doesn't exist if os.path.exists(MODEL_PATH): model = joblib.load(MODEL_PATH) # Load model @app.get("/") def read_root(): return {"message": "Hello World"} @app.get("/predict") def predict(preg: int, glu: int, bp: int): df = pd.DataFrame([[preg, glu, bp]], columns=["Pregnancies","Glucose","BloodPressure"]) pred = model.predict(df)[0] return {"prediction": int(pred)}