-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Backend: FastAPI
File: main.py
from fastapi import FastAPI, Depends
from pydantic import BaseModel
import uvicorn
from typing import List
import random
app = FastAPI()
Sample database (Simulating a real database)
nutrition_db = {
"weight_loss": ["Grilled Chicken Salad", "Steamed Broccoli with Quinoa", "Oatmeal with Berries"],
"muscle_gain": ["Steak with Sweet Potato", "Chicken Breast with Brown Rice", "Protein Smoothie"],
"balanced": ["Salmon with Veggies", "Whole Wheat Pasta with Pesto", "Tofu Stir Fry"]
}
class UserPreferences(BaseModel):
goal: str
dietary_restrictions: List[str] = []
@app.post("/recommend")
def recommend_meals(preferences: UserPreferences):
goal = preferences.goal.lower()
if goal in nutrition_db:
recommendations = random.sample(nutrition_db[goal], 2)
return {"meal_recommendations": recommendations}
return {"error": "Invalid goal"}
if name == "main":
uvicorn.run(app, host="0.0.0.0", port=8000)