A modern web application that predicts life expectancy based on lifestyle and health factors using machine learning.
Prerequisites: Docker and Docker Compose
# Build and start the application
docker-compose up -d
Visit:
- Frontend: http://localhost
- Backend API: http://localhost:5000
Prerequisites: Python 3.8+, Node.js 18+, npm
- Navigate to the backend directory:
cd backend- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Start the Flask server:
python app.pyThe API will run on http://localhost:5000
- Navigate to the frontend directory:
cd frontend- Install dependencies:
npm install- Start the development server:
npm run devThe app will run on http://localhost:5173
healthy-life-webapp/
├── backend/ # Flask API
│ ├── app.py # Main Flask application
│ ├── requirements.txt # Python dependencies
│ ├── model/ # Trained ML model files
│ │ ├── model.pkl
│ │ ├── scaler.pkl
│ │ ├── feature_info.json
│ │ └── top_features.json
│ └── utils/ # Utility modules
│ ├── converter.py # Feature conversion
│ └── predictor.py # Prediction logic
│
└── frontend/ # React + TypeScript
├── src/
│ ├── components/ # React components
│ │ ├── Welcome.tsx
│ │ ├── QuestionForm.tsx
│ │ └── ResultDisplay.tsx
│ ├── services/ # API service
│ │ └── api.ts
│ ├── types/ # TypeScript types
│ │ └── index.ts
│ ├── App.tsx # Main app component
│ └── main.tsx # Entry point
├── package.json
└── tailwind.config.js
- Interactive Questionnaire: 10 simple questions about lifestyle and health
- Real-time Prediction: Instant life expectancy calculation using XGBoost ML model
- Visual Results: Beautiful charts and cards showing predicted life expectancy
- Top 10 Factors: Identifies which factors positively or negatively impact your life expectancy
- Personalized Recommendations: Actionable advice to improve health outcomes
- Responsive Design: Works perfectly on desktop, tablet, and mobile devices
- Flask: Lightweight Python web framework
- XGBoost: Machine learning model for predictions
- scikit-learn: Data preprocessing and scaling
- Flask-CORS: Cross-origin resource sharing
- React 18: UI library
- TypeScript: Type-safe JavaScript
- Vite: Fast build tool and dev server
- Tailwind CSS: Utility-first CSS framework
- Axios: HTTP client for API calls
- Recharts: Data visualization library
- User Input: User answers 10 questions about their lifestyle, health, and demographics
- Feature Conversion: Responses are converted to 34 model features using population statistics
- ML Prediction: XGBoost model predicts life expectancy based on features
- Factor Analysis: Top 10 influential factors are identified and explained
- Results Display: User sees their predicted life expectancy, comparison to average, and personalized recommendations
- All data is processed in real-time
- No personal information is stored on servers
- Calculations happen locally or in temporary API calls
- No tracking or analytics
GET /- API informationGET /api/health- Health checkGET /api/questions- Get questionnaire questionsPOST /api/predict- Submit data and get prediction
cd backend
export FLASK_ENV=development
python app.pycd frontend
npm run devcd frontend
npm run build