A deployable FastAPI + vanilla HTML/CSS/JavaScript website built around the schema and suggestion engine in the uploaded PCOS_Detection_and_Suggestion_System.ipynb.
The UI is designed as a medical-style dashboard: dark by default, light-blue accent system, responsive layout, multi-step screening, batch CSV analysis, model transparency, browser-only result saving, print report, and no patient-record database.
The active notebook configuration uses a synthetic pcos_prediction_dataset.csv. The notebook's own signal audit reports that the target has no meaningful learnable signal. The website therefore treats the model as a research/demo screening component and clearly warns that the probability is not a clinical risk estimate.
For real clinical use, replace the training data with a validated clinical dataset and complete external validation, privacy/security review, clinical governance, and any required regulatory review.
pcos_webapp/
βββ backend/
β βββ app.py
β βββ ml_service.py
β βββ schemas.py
βββ frontend/
β βββ index.html
β βββ static/
β βββ app.js
β βββ styles.css
βββ scripts/
β βββ train_model.py
βββ data/
β βββ pcos_prediction_dataset.csv # put your source CSV here
βββ artifacts/
β βββ model.joblib # generated after training
βββ .env.example
βββ Dockerfile
βββ requirements.txt
βββ README.md
- Create a virtual environment:
python -m venv .venv
.\.venv\Scripts\Activate.ps1- Install dependencies:
pip install -r requirements.txt- Put your dataset at:
data\pcos_prediction_dataset.csv
The CSV needs the same active columns as the notebook, especially:
Age
BMI
Menstrual Regularity
Hirsutism
Acne Severity
Family History of PCOS
Insulin Resistance
Lifestyle Score
Stress Levels
Urban/Rural
Socioeconomic Status
Awareness of PCOS
Fertility Concerns
Undiagnosed PCOS Likelihood
Ethnicity
Diagnosis
Country may be present; the training pipeline drops it just like the notebook.
- Train the saved deployment artifact:
python scripts\train_model.py- Launch the website:
uvicorn backend.app:app --host 0.0.0.0 --port 8000Open http://127.0.0.1:8000.
FastAPI docs are available at http://127.0.0.1:8000/api/docs.
Put the dataset in data/pcos_prediction_dataset.csv, then:
docker build -t pcosense .
docker run --rm -p 8000:8000 pcosenseThe image will train automatically at startup only when artifacts/model.joblib is missing and the dataset exists. For a production deployment, pre-train the artifact and bake it into the deployment image where appropriate.
The main screening flow is a 3-step form that mirrors the active notebook's pcos schema. It returns:
- model probability and binary prediction
- LOW / MODERATE / HIGH distribution-derived band
- triggered notebook-style rule findings
- grouped suggestions by domain
- recommended next step
- supportive non-diagnostic summary
- model metrics and signal-gate status
- printable report
- browser-side JSON export
Upload a CSV of up to 500 rows / 5 MB. The API validates the schema, runs the same prediction path per row, and returns a downloadable result CSV. The server does not persist the uploaded file.
Shows the saved classifier, augmentation method, rows used, evaluation metrics, signal-gate result, and NiWo diagnostics so the website can double as a project-demo dashboard.
Returns server and model readiness.
Returns the form schema, options, and descriptions.
Returns model metadata from the saved artifact.
Accepts the same feature names shown in the UI and returns a screening report.
Accepts a multipart CSV upload and returns row-level results.
Retrains and replaces the saved artifact. Set TRAIN_TOKEN and send X-TRAIN-TOKEN in any remotely exposed deployment if this endpoint is enabled.
The backend preserves the active synthetic-dataset schema, fixed ordinal/binary mappings, train/test split, StandardScaler, the notebook's NiWo weighting logic, class-balance budget allocation, ROS-style augmentation, Random Forest deployment classifier, risk stratification concept, and the active synthetic rule-based suggestion categories.
The optional heavy Hugging Face NLP/LLM stack from the notebook is intentionally not a default runtime dependency because it makes a public web deployment much slower and more memory-intensive. The website's supportive-summary layer works without an LLM and can be replaced later with an approved local or hosted model behind a controlled provider interface.
Before exposing a public domain to real users, add HTTPS at the hosting layer, authentication for any administrative training operation, centralized monitoring without storing patient inputs, rate limiting, a proper privacy notice, an audited clinical dataset, external validation, and a documented threat model. Do not store identifiable health information in browser localStorage for real patient deployments.