File size: 5,331 Bytes
a144435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---

title: AI Diet Planner & Nutrition Assistant
emoji: 🍽️
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
short_description: AI-powered diet planning with nutrition analysis
---


# 🍽️ AI Diet Planner & Nutrition Assistant

An intelligent diet planning application that uses RAG (Retrieval-Augmented Generation) technology to provide personalized nutrition advice, meal planning, and dietary recommendations.

## ✨ Features

### 🎯 **Personalized Diet Planning**
- **Weekly Meal Plans**: Complete 7-day diet plans with detailed meal breakdowns
- **Daily Nutrition**: Individual day meal planning with macro and micronutrient analysis
- **Customizable Parameters**: Age, weight, height, activity level, and dietary preferences

### πŸ“Š **Nutrition Analysis**
- **Comprehensive Nutrition Facts**: Detailed breakdown of calories, macronutrients, vitamins, and minerals
- **USDA Food Database**: Access to extensive food nutrition information
- **BMR & TDEE Calculations**: Accurate metabolic rate calculations using Mifflin-St Jeor formula

### πŸ€– **AI-Powered Recommendations**
- **Smart Suggestions**: Personalized dietary recommendations based on your profile
- **Goal-Oriented Planning**: Weight loss, muscle gain, or maintenance-focused plans
- **Interactive Chat**: Natural language interface for easy interaction

### πŸ“‹ **Advanced Features**
- **JSON Export**: All plans and analyses saved as structured JSON files
- **Table Formatting**: Beautiful markdown tables for easy reading
- **Multi-language Support**: English interface with comprehensive food database

## πŸš€ How to Use

### 1. **Create a Diet Plan**
```

"Create a weekly diet plan for a 25-year-old male, 70kg, 175cm, moderate activity"

```

### 2. **Calculate Nutrition**
```

"Calculate nutrition for 200g chicken breast and 150g rice"

```

### 3. **Get Recommendations**
```

"Get diet recommendations for weight loss"

```

### 4. **Vegetarian Options**
```

"Create a vegetarian meal plan for 7 days"

```

## πŸ”§ Technical Details

### **Architecture**
- **RAG System**: Retrieval-Augmented Generation for intelligent responses
- **Groq API**: Fast LLM inference for real-time responses
- **Sentence Transformers**: Semantic search for relevant nutrition data
- **Gradio**: Modern web interface for easy interaction

### **Data Sources**
- **USDA FoodData Central**: Comprehensive nutrition database
- **Custom Food Database**: Curated collection of common foods
- **Nutritional Algorithms**: BMR, TDEE, and macro distribution calculations

### **Output Formats**
- **JSON Files**: Structured data for all plans and analyses
- **Markdown Tables**: Human-readable formatted output
- **Interactive Chat**: Real-time conversation interface

## πŸ“ File Structure

```

β”œβ”€β”€ app.py                 # Main Gradio application

β”œβ”€β”€ main3.py              # RAG system and tool router

β”œβ”€β”€ diet_tool.py          # Diet planning algorithms

β”œβ”€β”€ usda_provider.py      # USDA API integration

β”œβ”€β”€ requirements.txt      # Python dependencies

β”œβ”€β”€ README.md            # This file

└── outputs/             # Generated JSON files

    β”œβ”€β”€ diet_plan_weekly_*.json

    β”œβ”€β”€ diet_plan_daily_*.json

    └── diet_recommendations_*.json

```

## πŸ› οΈ Setup Instructions

### **For Hugging Face Spaces**

1. **Create a new Space** on Hugging Face
2. **Upload all files** to your Space repository
3. **Set Environment Variables**:
   - Go to Settings β†’ Secrets
   - Add `GROQ_API_KEY` with your Groq API key
4. **Deploy** - The Space will automatically build and deploy

### **For Local Development**

1. **Install Dependencies**:
   ```bash

   pip install -r requirements.txt

   ```

2. **Set Environment Variable**:
   ```bash

   export GROQ_API_KEY="your_groq_api_key_here"

   ```

3. **Run the Application**:
   ```bash

   python app.py

   ```

## πŸ”‘ API Keys Required

- **Groq API Key**: Get your free API key from [console.groq.com](https://console.groq.com)

## πŸ“Š Example Outputs

### **Weekly Diet Plan**
- 7-day meal breakdown
- Daily calorie and macro targets
- Detailed food lists with portions
- Nutritional analysis per meal

### **Nutrition Analysis**
- Complete macronutrient breakdown
- Vitamin and mineral content
- Calorie calculations
- Serving size recommendations

### **Dietary Recommendations**
- Personalized advice based on profile
- Goal-specific suggestions
- Macro distribution guidance
- Lifestyle integration tips

## 🀝 Contributing

Feel free to contribute to this project by:
- Adding new food items to the database
- Improving nutrition calculation algorithms
- Enhancing the user interface
- Adding new dietary patterns (keto, paleo, etc.)

## πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

## πŸ™ Acknowledgments

- **USDA FoodData Central** for comprehensive nutrition data
- **Groq** for fast LLM inference
- **Gradio** for the beautiful web interface
- **Sentence Transformers** for semantic search capabilities

---

**Made with ❀️ for better nutrition and healthier living!**