This repository contains the backend server and the machine learning model for NutriGenius, a smart recipe recommendation system. The backend is built with Python and FastAPI, and it serves personalized meal recommendations based on user-provided health data and preferences.
- FastAPI Framework: A modern, high-performance web framework for building APIs with Python.
- Content-Based Filtering Model: A custom-trained machine learning model that recommends recipes based on ingredient similarity, diet, course, and user goals.
- Dynamic Image Fetching: Uses DuckDuckGo Search to dynamically find relevant images for each recommended recipe, without needing API keys.
- CORS Enabled: Properly configured to accept requests from any frontend origin.
- Ready for Deployment: Includes a
Procfile
andrequirements.txt
for easy deployment on platforms like Render.
- Language: Python
- Web Framework: FastAPI
- ML & Data Processing: Pandas, Scikit-learn
- Image Search: duckduckgo-search
- Server: Uvicorn
Follow these instructions to get the backend server running on your local machine.
- Python (v3.9 or later)
pip
andvenv
-
Clone the repository:
git clone [https://github.com/your-username/nutrigenius-backend.git](https://github.com/your-username/nutrigenius-backend.git) cd nutrigenius-backend
-
Create and activate a virtual environment:
# For Windows python -m venv venv .\venv\Scripts\activate # For macOS/Linux python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
With your virtual environment activated, run the following command to start the local development server:
uvicorn main:app --reload
The API will be available at http://127.0.0.1:8000
. You can access the interactive API documentation (powered by Swagger UI) at http://127.0.0.1:8000/docs
.
- Endpoint:
POST /recommend
- Description: Takes user data and returns a list of personalized recipe recommendations.
- Request Body:
{ "height_cm": 175, "weight_kg": 70, "desired_ingredients": "paneer, onion", "user_allergies": "nuts", "meal_type": "Dinner", "weight_goal": "Lose", "max_cooking_time": 60, "diet_preference": "Vegetarian" }
- Success Response (200 OK): An array of recipe objects.
- Endpoint:
GET /procedure/{recipe_id}
- Description: Retrieves the step-by-step cooking instructions for a specific recipe ID.
- Success Response (200 OK):
{ "steps": ["Step 1...", "Step 2...", "Step 3..."] }
This project is configured for easy deployment on Render.
-
Create
requirements.txt
: If you've added new packages, update the file:pip freeze > requirements.txt
-
Create
Procfile
: Ensure aProcfile
exists in the root directory with the following content:web: uvicorn main:app --host 0.0.0.0 --port $PORT
-
Push to GitHub: Commit and push your latest changes to a GitHub repository.
-
Deploy on Render:
- Create a new Web Service on Render and connect your GitHub repository.
- Set the Runtime to
Python 3
. - Set the Build Command to
pip install -r requirements.txt
. - Set the Start Command to
uvicorn main:app --host 0.0.0.0 --port $PORT
. - Add an environment variable with
PYTHON_VERSION
as the key and3.11.9
as the value. - Click Create Web Service. Render will build and deploy your API.