Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAM AI — Clinical Diagnostic Suite

Early disease detection powered by machine learning and AI-assisted chat

Next.js React TypeScript Flask Python scikit-learn License: MIT


Demo

SAM AI demo — landing page, login, heart disease result, breast cancer radar chart, AI chat, dashboard

Landing · Login · Heart Disease · Breast Cancer radar chart · AI Chat · Dashboard  |  Full demo MP4


What It Does

SAM AI lets users fill in clinical biomarkers and receive an instant ML-powered risk assessment — complete with a confidence score, risk badge, clinical recommendations, and a downloadable PDF report. A built-in AI chat widget (powered by Groq / Llama 3.3-70B) answers general health questions.


Diagnostic Modules

Specialty Assessment Key Inputs
Cardiology Heart Disease Risk 13 vitals — resting ECG, cholesterol, max heart rate, ST depression
Oncology Breast Cancer Screening 30 FNA cell-nucleus measurements — radius, texture, area, concavity
Endocrinology Female Diabetes Risk 8 PIMA endpoints — glucose, BMI, insulin, pregnancies
Endocrinology Male Diabetes Risk 16 symptom indicators — polyuria, polydipsia, weight loss
Hepatology Liver Health 10 hepatic enzyme values — ALT, AST, bilirubin, albumin

Each result includes:

  • Probability score and risk level (Low / Moderate / High)
  • Confidence bar with model version
  • Clinical recommendations panel
  • PDF report download (generated client-side with jsPDF)
  • Radar / bar chart for breast cancer oncology results

Tech Stack

Frontend

Framework Next.js 15 (App Router) + React 19
Language TypeScript 5.x
Styling Tailwind CSS v4 + Framer Motion

Backend

Framework Flask 3.x + Flask-Session + Flask-Limiter
Language Python 3.9+
Database SQLite (dev) — swap DATABASE_URL for PostgreSQL in production
Auth Flask-Login + bcrypt + server-side sessions (filesystem)
ML scikit-learn, joblib, pandas, NumPy

AI Chat

Powered by Groq inference (Llama 3.3-70B). Set GROQ_API_KEY in sam-next/.env.local to enable it. Free tier available at console.groq.com.


Getting Started

Prerequisites: Node.js 18+ and Python 3.9+

git clone https://github.com/ARSHIYASHAFIZADE/SAM_Ai.git
cd SAM_Ai

1. Backend

cd server
python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt

Create server/.env:

SECRET_KEY=change-me-in-production
DATABASE_URL=sqlite:///./db.sqlite
SESSION_TYPE=filesystem
SESSION_COOKIE_SECURE=false
GROQ_API_KEY=                   # optional — only needed for the chat route

Start the backend:

python app.py                   # http://localhost:5000

2. Frontend

cd sam-next
npm install

Create sam-next/.env.local:

NEXT_PUBLIC_API_BASE_URL=http://localhost:3000/api-backend
BACKEND_URL=http://localhost:5000
GROQ_API_KEY=your_groq_key_here

The frontend proxies all /api-backend/* requests to the Flask backend via a Next.js rewrite. This keeps auth cookies on the same origin and avoids CORS issues.

Start the frontend:

npm run dev                     # http://localhost:3000

Project Structure

SAM_Ai/
├── sam-next/                    # Next.js 15 frontend
│   ├── src/
│   │   ├── app/
│   │   │   ├── page.tsx         # Landing page
│   │   │   ├── register/        # Registration
│   │   │   ├── login/           # Login
│   │   │   ├── dashboard/       # Assessment history
│   │   │   ├── predict/
│   │   │   │   ├── heart/       # Heart disease form + result
│   │   │   │   ├── diabetes-female/
│   │   │   │   ├── diabetes-male/
│   │   │   │   ├── liver/
│   │   │   │   └── breast-cancer/
│   │   │   └── api/chat/        # Groq / Llama chat route
│   │   └── components/
│   │       ├── Navbar.tsx
│   │       ├── AuthProvider.tsx  # Session context + RequireAuth HOC
│   │       ├── ResultCard.tsx    # Shared result display
│   │       ├── RecommendationsPanel.tsx
│   │       ├── ChatWidget.tsx    # Floating AI chat button + panel
│   │       └── MedicalIcons.tsx
│   └── next.config.js           # Rewrites /api-backend/* → Flask
│
├── server/                      # Flask backend
│   ├── app.py                   # App factory, routes, CORS
│   ├── config.py                # ApplicationConfig (reads .env)
│   ├── models.py                # SQLAlchemy User model
│   ├── schemas.py               # Pydantic request schemas
│   └── services/
│       ├── heart_service.py
│       ├── female_diabetes_service.py
│       ├── male_diabetes_service.py
│       ├── liver_service.py
│       └── cancer_service.py    # Breast cancer + chart generation
│
└── docs/
    └── demo.mp4

API Reference

All routes are prefixed with / on the Flask backend (port 5000), accessed from the frontend via /api-backend/.

Auth

Method Path Description
POST /register Create account — { name, email, password }
POST /login Sign in — { email, password }
POST /logout Clear session
GET /@me Return current user or 401

Predictions

Method Path Description
POST /detect_heart Heart disease — 13 numeric + categorical fields
POST /predict Female diabetes — 8 numeric fields
POST /predict_male Male diabetes — Age (float) + 15 Yes/No/Male/Female fields
POST /detect_liver Liver health — { input_data: [10 floats] }
POST /detect_breast_cancer Breast cancer — 30 numeric measurements

Each prediction returns { prediction, probability, risk_level, model_version }. Breast cancer also returns bar_chart and radar_chart as base64-encoded PNG strings.

AI Chat

The chat widget calls the Next.js API route at /api/chat (not the Flask backend), which proxies to Groq.


Environment Variables

Backend (server/.env)

Variable Default Description
SECRET_KEY Required. Flask session signing key
DATABASE_URL sqlite:///./db.sqlite SQLAlchemy database URL
SESSION_TYPE filesystem Flask-Session backend
SESSION_COOKIE_SECURE true Set false for HTTP localhost
GROQ_API_KEY Optional — only needed if calling Groq from the backend

Frontend (sam-next/.env.local)

Variable Description
NEXT_PUBLIC_API_BASE_URL Must be http://localhost:3000/api-backend (same-origin proxy)
BACKEND_URL Where Next.js rewrites proxy to — http://localhost:5000
GROQ_API_KEY Groq API key for the /api/chat Next.js route

Disclaimer

SAM AI is built for educational and demonstration purposes. Predictions are produced by ML models trained on public datasets and are not a substitute for professional medical advice. Always consult a qualified healthcare provider for real health concerns.


License

MIT

About

Full-stack clinical AI suite — 5 ML disease-risk models (heart disease, diabetes, liver health, breast cancer) + Groq-powered medical chat. Next.js 15 · Flask · scikit-learn · TypeScript

Topics

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages