A sophisticated Streamlit web application that generates personalized healthy recipes from available ingredients and provides detailed nutritional analysis. Built with advanced AI, modern UI design, and comprehensive recipe management features.
- Advanced AI Model: Uses Groq's Llama-3.1-8B-Instant for intelligent recipe creation
- Structured Output: Pydantic validation ensures consistent, high-quality recipe data
- Ingredient-Only Recipes: Creates recipes using ONLY the ingredients you provide
- Smart Prompting: Optimized prompts for culinary realism and nutritional balance
- USDA Integration: Fetches accurate macro data from 200,000+ verified food items
- Detailed Breakdown: Protein, carbs, fat, fiber, and calories per ingredient
- Per-Serving & Total Macros: Complete nutritional analysis for meal planning
- Real-time Calculations: Instant macro scaling based on ingredient quantities
- Glassmorphism Design: Beautiful, modern UI with advanced CSS animations
- Responsive Layout: Optimized for desktop, tablet, and mobile devices
- Interactive Elements: Hover effects, smooth transitions, and visual feedback
- Intuitive Navigation: Clean, organized interface with helpful tooltips
- SQLite Database: Persistent storage with comprehensive recipe metadata
- Smart Filtering: Filter by dietary restrictions, cuisine, meal type, cooking time, and difficulty
- Search Functionality: Find recipes by title or ingredients
- Rating System: 5-star rating system with real-time statistics
- Favorites Management: Save and organize your preferred recipes
- Recipe Quality Scoring: Automatic validation with helpful feedback
- Ingredient Usage Verification: Ensures all provided ingredients are used
- Spelling Suggestions: Intelligent error detection with correction tips
- Success Rate Tracking: Monitor recipe generation performance
- User Statistics: Track total recipes, favorites, and average ratings
- Fast AI Inference: Leverages Groq's ultra-fast hardware for quick responses
- Error Handling: Graceful fallbacks and user-friendly error messages
- Caching System: Optimized database connections for better performance
- Free APIs: Cost-effective operation using generous free tiers
- Python 3.7 or higher
- Free API keys from Groq and USDA
-
Clone the repository
git clone https://github.com/shaunn17/NutrifyAI.git cd NutrifyAI -
Install dependencies
pip install -r requirements.txt
-
Get your free API keys
Groq API Key (for AI recipe generation):
- Visit console.groq.com
- Sign up/login and create an API key
USDA API Key (for nutritional data):
- Visit fdc.nal.usda.gov/api-guide.html
- Sign up for a free API key
-
Configure your API keys
Create
.streamlit/secrets.toml:groq_api_key = "your_groq_api_key_here" usda_api_key = "your_usda_api_key_here"
-
Run the application
streamlit run app.py
The app will open in your browser at http://localhost:8501
-
Enter Ingredients: Type your available ingredients separated by commas
chicken breast, quinoa, spinach, olive oil, garlic -
Generate Recipe: Click "๐ Create My Recipe" to get your AI-created recipe
-
Review Results:
- Complete recipe with cooking instructions
- Ingredient quantities in grams
- Detailed macro breakdown per ingredient
- Per-serving and total nutrition information
- Generates random ingredient combinations for inspiration
- Perfect for discovering new recipe ideas
Filter your saved recipes by:
- ๐ฅ Dietary Restrictions: None, Vegetarian, Vegan, Keto, Paleo
- ๐ Cuisine Types: Italian, Asian, Mexican, Mediterranean, American, Indian, French, Thai
- ๐ฝ๏ธ Meal Types: Breakfast, Lunch, Dinner, Snacks, Desserts
- โฑ๏ธ Cooking Time: Quick (15min), Medium (30min), Long (60min+)
- ๐ Difficulty Level: Beginner, Intermediate, Advanced
- Recipe History: Browse all your generated recipes
- Favorites: Save and organize your preferred recipes
- Search: Find recipes by title or ingredients
- Rating System: Rate recipes 1-5 stars
- Statistics: Track your recipe generation success
- Individual Deletion: Remove specific recipes
- Bulk Operations: Clear all recipes with confirmation
- Data Export: All data stored in local SQLite database
Input:
salmon, sweet potato, broccoli, olive oil, lemon
Output:
- Recipe: "Roasted Salmon with Sweet Potato and Broccoli" (4 servings)
- Macros per serving: ~35g protein, 25g carbs, 12g fat, 6g fiber
- Cooking steps: Detailed preparation and cooking instructions
- Quality Score: 95/100 with validation feedback
NutrifyAI/
โโโ app.py # Main Streamlit application (1,700+ lines)
โโโ database.py # SQLite database management (535 lines)
โโโ utils.py # USDA API integration (122 lines)
โโโ requirements.txt # Python dependencies
โโโ recipes.db # SQLite database file
โโโ .streamlit/
โโโ secrets.toml # API keys configuration
app.py: Main application with Streamlit UI, AI integration, and comprehensive recipe managementdatabase.py: SQLite database with advanced filtering, search, and analytics capabilitiesutils.py: USDA FoodData Central API wrapper with macro calculation algorithms- Pydantic Models: Structured data validation ensuring recipe quality and consistency
- Advanced CSS: Custom glassmorphism design with animations and responsive layout
- Model: Llama-3.1-8B-Instant
- Purpose: AI-powered recipe generation
- Performance: 500+ tokens/second generation speed
- Rate Limit: Generous free tier
- Documentation: console.groq.com
- Purpose: Nutritional data lookup and macro calculations
- Coverage: 200,000+ verified food items
- Rate Limit: 1,000 requests/hour (free)
- Accuracy: Government-verified nutritional data
- Documentation: fdc.nal.usda.gov
- Input Validation: Parses and validates ingredient list
- AI Prompt Engineering: Constructs optimized prompts for Groq AI
- JSON Parsing: Extracts and validates recipe JSON with Pydantic
- Quality Validation: Checks ingredient usage and recipe quality
- Macro Calculation: Queries USDA API for each ingredient
- Data Scaling: Calculates per-serving and total macros
- Database Storage: Saves recipe with metadata and analytics
graph LR
A[User Input] --> B[Input Validation]
B --> C[Groq AI]
C --> D[JSON Validation]
D --> E[Quality Check]
E --> F[USDA API]
F --> G[Macro Calculation]
G --> H[Database Storage]
H --> I[UI Display]
- Ingredient Usage Verification: Ensures all provided ingredients are used
- Spelling Detection: Identifies common spelling errors with suggestions
- Serving Size Validation: Checks for realistic portion sizes
- Recipe Completeness: Validates cooking instructions and steps
- Quality Scoring: Provides 0-100 quality score with detailed feedback
- Database Caching: Optimized SQLite connections with intelligent caching
- API Rate Limiting: Efficient API usage with error handling
- UI Responsiveness: Smooth animations and fast page loads
- Memory Management: Efficient data structures and cleanup
- Error Recovery: Graceful handling of API failures and edge cases
export GROQ_API_KEY="your_groq_api_key_here"
export USDA_API_KEY="your_usda_api_key_here"For deployment on Streamlit Cloud or other platforms:
groq_api_key: Your Groq API keyusda_api_key: Your USDA API key
"Please add your API keys in Secrets"
- Ensure your
secrets.tomlfile is in the.streamlit/directory - Verify API keys are correctly formatted (no extra spaces/quotes)
"No USDA match found"
- Try simpler ingredient names (e.g., "chicken breast" instead of "organic free-range chicken")
- Use generic terms rather than brand names
- Check spelling of ingredient names
"Recipe generation failed"
- Check your Groq API key is valid and has remaining quota
- Ensure internet connection is stable
- Try with fewer ingredients (4-8 ingredients work best)
"Ingredients not used in recipe"
- Check spelling (e.g., "broccoli" not "brocoli")
- Use simpler ingredient names
- Try regenerating the recipe
- Recipe rating and favorites system โ
- Advanced filtering and search โ
- Quality validation and feedback โ
- Modern glassmorphism UI โ
- Recipe management and analytics โ
- Shopping list generation
- Recipe image generation
- Meal planning calendar
- Export to PDF/email
- Ingredient substitution suggestions
- Calorie target optimization
- Multi-language support
- Recipe sharing and collaboration
This project is licensed under the MIT License - see the LICENSE file for details.
Transform any combination of ingredients into a delicious, healthy meal with AI precision!