Shyamati turns a Jupyter-style experiment into a reproducible pipeline, an API that streams plots and PDFs, and a modern dark-themed web app. It includes a “Getting Started” learning page, awareness PDFs (multi-language), and optional deep learning — all wired end-to-end.
Highlights
- Reproducible training (scikit-learn) with stacked models and metadata export
- FastAPI backend that streams on-demand PDFs (prediction report + awareness guide)
- Next.js frontend with a dark purple theme, accessible content, and embedded videos
- Optional TensorFlow deep-learning path with lazy runtime detection
- Smooth UX: auto-open prediction report, reliable downloads, and print styles
Repository layout (top level)
train_model.py— Train & export sklearn pipeline and metadatatrain_dl.py— Optional Keras MLP training for tabular dataapp/main.py— FastAPI app (predict, report, awareness, models, sample)frontend/— Next.js site (Home, Learn, Demo) with Tailwind stylinggenerate_pdf.py— Builds a sample/report PDF for homepage downloadartifacts/— Saved plots (ROC/PR/Confusion/SHAP), classification reportmodel_pipeline.joblib,model_pipeline_stacking.joblib,model_metadata.json— artifactsdl_model.h5— optional deep learning modelrequirements.txt— Python deps (ReportLab pinned for reliable PDFs)
Backend (FastAPI) on Render:
- Commit
render.yaml(included) or create a new Web Service manually. - Settings:
- Runtime: Python
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn app.main:APP --host 0.0.0.0 --port $PORT - Health Check Path:
/health - Optional env:
FRONTEND_ORIGIN=https://your-frontend-url.vercel.app
- Ensure model artifacts (
model_pipeline.joblib, etc.) are in the repository (Render pulls them at build time). - If enabling deep learning, add
tensorflow-cputorequirements.txt(Render Free plan has limited resources; prefer CPU variant).
Frontend (Next.js) on Vercel:
- Add a project pointing at
frontend/. - Set an Environment Variable:
NEXT_PUBLIC_API_BASE=https://shyamati-backend.onrender.com(replace with your Render URL). - Remove dev rewrites (or keep them—they are ignored on Vercel). All fetch calls now prepend
NEXT_PUBLIC_API_BASE. - For PDF links (awareness, report), the app uses this base to request backend endpoints.
Cross-Origin / CORS:
app/main.pynow readsFRONTEND_ORIGINand also permitshttps://*.vercel.appdomains via regex.- If you use a custom domain, set
FRONTEND_ORIGIN=https://yourdomain.comin Render.
File persistence notes:
- Render’s disk is ephemeral between deploys; uploaded/generated runtime files (like per-request reports) remain during instance life but are lost after redeploy.
- Long-term storage (if needed) can be added later (S3, etc.)—current design is stateless aside from bundled artifacts.
Troubleshooting deployment:
- 404 on PDFs: verify
NEXT_PUBLIC_API_BASEis set and points to a live backend. - CORS error: set
FRONTEND_ORIGINexactly to your Vercel deployed URL. - Large dependency build timeout: remove unused heavy libs or pin versions; ensure ReportLab version remains pinned.
Local env parity check:
uvicorn app.main:APP --port 8000
# In another terminal (frontend directory):
npm run devSet NEXT_PUBLIC_API_BASE=http://127.0.0.1:8000 for local Vercel preview parity.
Backend API
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
python -m uvicorn app.main:APP --reload --port 8000Frontend (Next.js)
cd frontend
npm install
npm run devOpen http://localhost:3000 and try:
- Launch Demo → enter or load sample values → prediction → report auto-opens
- Getting Started → visual guide with i18n and awareness PDF download
- Data & Training
- Load
data.csv; clean columns (drop id/unnamed); stratified split - Preprocess: imputer → scaler → SelectKBest (k tuned)
- Train candidate models; GridSearchCV; export best pipeline and
model_metadata.json - Optional: train a DL MLP; persist
dl_model.h5and a consistent scaler
- API (FastAPI)
- Lazy-load artifacts; detect DL runtime (no heavy TF import at startup)
/predictvalidates input and returns prediction and probability/reportstreams a per-prediction PDF with plots and metrics/awarenessserves a daily-cached multilingual awareness PDF/modelsreports available models and whether DL is runnable/samplereturns a canonical feature vector for quick demos
- Frontend (Next.js)
- Home: feature highlights and an awareness spotlight video
- Learn: “Getting Started” guide with visuals, FAQs, and PDF download
- Demo: inputs, model selector (sklearn/stacking/DL), SHAP toggle; opens PDF
- Smooth scrolling and fade-in animations; downloads via robust proxying
- Reports & PDFs
┌───────────────┐ ┌──────────────┐ ┌────────┐ ┌──────────┐
│ Data & Train │ ───▶ │ Artifacts │ ───▶ │ API │ ───▶ │ Frontend │
│ (train_model) │ │ (models, │ │ (predict│ │ (Home / │
│ │ │ metadata, │ │ report │ │ Demo / │
│ train_dl opt)│ │ plots) │ │ aware) │ │ Learn) │
└──────┬────────┘ └──────┬───────┘ └────┬───┘ └─────┬────┘
│ │ │ │
│ │ │ │
▼ ▼ ▼ ▼
Reports (PDF) <────────────┘ Awareness PDF (cached per lang/day)
The same diagram is exported as artifacts/workflow.png and embedded into the generated PDF.
- Prediction report: generated on-demand via
/report(streamed PDF) - Awareness guide: multi-language PDF with inline vector illustrations; cached per day
- Sample static PDF: built by
generate_pdf.pyfor homepage download
- GET
http://127.0.0.1:8000/health - POST
http://127.0.0.1:8000/predictBody:{ "features": [x1..x30], "model_type": "sklearn|stacking|dl", "explain": bool } - POST
http://127.0.0.1:8000/report - GET
http://127.0.0.1:8000/awareness?lang=en|hi|mr - GET
http://127.0.0.1:8000/models - GET
http://127.0.0.1:8000/sample
TensorFlow isn’t imported at startup: the backend checks runtime availability and model file presence before enabling the DL option. To enable DL locally:
pip install tensorflow-cpu
python train_dl.pypython generate_pdf.pyThis creates report.pdf (the homepage “Download Example Report”). It summarizes metrics, configuration, model comparison, plots, key findings, technical details, and clinical implications. It now also includes a “Project Workflow” section.
python test_report.py
python -m pytest -q # if you add more tests- Awareness PDF returns 404 in dev: ensure Next.js dev rewrite maps
/api/awareness→ backend/awarenessand that the API is running on port 8000. - Deep learning disabled: check
/models— DL requires bothdl_model.h5and a TF runtime. - Blank plots in reports: make sure
artifacts/*.pngexist; rebuild by re-running training.
This repository is for educational purposes. It does not provide medical advice.
