Skip to content

code #2

@tech-by-nasa

Description

@tech-by-nasa

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions