Spaces:
Runtime error
Runtime error
from fastapi import FastAPI | |
from .routes import router | |
import os | |
app = FastAPI( | |
title="Mila-Wellnest API", | |
description="Pregnancy Risk Prediction backend powered by fine-tuned DistilBERT.", | |
version="1.0.0" | |
) | |
# Root health check | |
def root(): | |
return {"message": "👶 Hello from Mila-Wellnest Backend API"} | |
# Mount the /predict endpoint from routes.py | |
app.include_router(router) | |
# On startup: Train the model if no saved checkpoint exists | |
async def startup_event(): | |
checkpoint_path = "./data/best_model" | |
if not os.path.exists(checkpoint_path): | |
os.makedirs(checkpoint_path, exist_ok=True) | |
print("⚙️ No checkpoint found. Starting training...") | |
from backend.app.train import train | |
train() | |