This project serves as the backend for the MomCare application, providing machine learning-powered predictions and recommendations related to maternal health. It is built with FastAPI.
ML/
|-- app/
| `-- main.py # FastAPI application logic and API endpoints
|-- random_forest_model.pkl # Trained model for risk prediction
|-- xgb_model.pkl # Trained model for anxiety prediction
|-- unique_indian_foods_dataset.csv # Dataset for dietary recommendations
|-- requirements.txt # Python dependencies
`-- README.md # This file
-
Clone the repository:
git clone https://github.com/jayan110105/MomCareBackend cd ML
-
Create a virtual environment: It is highly recommended to use a virtual environment to manage project dependencies.
# For Windows python -m venv venv venv\Scripts\activate # For macOS/Linux python3 -m venv venv source venv/bin/activate
-
Install dependencies: Install all the required Python packages using pip.
pip install -r requirements.txt
To run the FastAPI application locally, use uvicorn
. It will start a local server, and the API will be accessible.
uvicorn app.main:app --reload
The application will be available at http://127.0.0.1:8000
.
The following endpoints are available:
- Endpoint:
/predict_risk
- Method:
POST
- Description: Predicts a general risk level based on input features.
- Request Body:
{ "feature1": 0.0, "feature2": 0.0, "feature3": 0.0, "feature4": 0.0, "feature5": 0.0 }
- Response:
{ "prediction": "some_risk_level" }
- Endpoint:
/predict_anxiety
- Method:
POST
- Description: Predicts the level of anxiety based on a series of questions.
- Request Body:
{ "Age": "25-30", "FeelingSadOrTearful": "Yes", "IrritableTowardsBabyAndPartner": "Yes", "TroubleSleepingAtNight": "Yes", "ProblemsConcentratingOrMakingDecision": "Yes", "OvereatingOrLossOfAppetite": "Yes", "FeelingOfGuilt": "Yes", "ProblemsOfBondingWithBaby": "Yes", "SuicideAttempt": "No" }
- Response:
{ "prediction": "Feeling anxious" }
- Endpoint:
/recommendations/
- Method:
POST
- Description: Provides food recommendations based on nutritional requirements.
- Request Body:
{ "calories": 1800, "fats": 80, "proteins": 150, "iron": 20, "carbohydrates": 300, "fibre": 30, "veg_only": true }
- Response: A JSON object containing a list of recommended food items.
{ "recommendations": [ { "Food_items": "...", "Calories": "...", "Fats": "...", "Proteins": "...", "Iron": "...", "Carbohydrates": "...", "Fibre": "...", "VegNovVeg": "..." } ] }