-
Install Dependencies:
pip install -r requirements.txt
-
Get Google API Key:
- Visit https://ai.google.dev/
- Sign in with your Google account
- Create a new API key for Gemini
- Keep your API key secure
-
Run the Application:
streamlit run mood_food_recommender.py
-
Access the Web Interface:
- Open your browser to
http://localhost:8501 - Enter your Google API key in the sidebar
- Start getting personalized food recommendations!
- Open your browser to
your-project/
├── mood_food_recommender.py # Main Streamlit application
├── user_profile.txt # User preferences and history
├── contextual_data.txt # Current context (time, weather, etc.)
├── requirements.txt # Python dependencies
└── README.md # This file
The system uses a sophisticated 4-phase scoring algorithm:
- Mood Analysis (40% weight) - Analyzes your text input for emotional state
- Historical Behavior (30% weight) - Considers your past food preferences
- Contextual Integration (20% weight) - Factors in time, weather, location
- Demographic Personalization (10% weight) - Adjusts for age, income, preferences
- User Input (GUI): Your current mood/feelings as text
- User Profile (File): Your preferences, history, demographics
- Contextual Data (File): Current time, weather, location info
- Frontend: Streamlit (Web Interface)
- LLM: Google Gemini 2.0 Flash
- Framework: LangChain for LLM orchestration
- Data Validation: Pydantic for structured outputs
- Language: Python 3.8+
Edit user_profile.txt to include:
- Your actual food preferences
- Order history
- Dietary restrictions
- Budget preferences
- Demographics
Edit contextual_data.txt to reflect:
- Current time and date
- Local weather conditions
- Your location
- Current situation/stress levels
The algorithm weights can be adjusted in the prompt template within mood_food_recommender.py:
- Mood Analysis: Currently 40%
- Historical Behavior: Currently 30%
- Contextual Integration: Currently 20%
- Demographics: Currently 10%
-
API Key Error:
- Ensure your Google API key is correct
- Check if you have Gemini API access enabled
- Verify billing is set up if required
-
File Not Found:
- Ensure
user_profile.txtandcontextual_data.txtexist - Check file permissions and encoding (UTF-8)
- Ensure
-
Import Errors:
- Run
pip install -r requirements.txt - Check Python version (3.8+ required)
- Consider using a virtual environment
- Run
-
Rate Limiting:
- Google API has usage limits
- Wait a few minutes between requests if hitting limits
- Check your API quota in Google Cloud Console
The system uses Pydantic models to ensure consistent response formatting:
RecommendationResponse- Main output structureFoodRecommendation- Individual recommendation format
- Uses
ChatGoogleGenerativeAIfor Gemini access - Implements
PromptTemplatefor consistent prompting - Leverages
with_structured_output()for JSON mode
- API keys are handled securely through Streamlit's sidebar
- No data is stored permanently
- All processing happens in real-time
Feel free to enhance the algorithm by:
- Adding more sophisticated mood detection
- Implementing user feedback loops
- Adding more contextual factors
- Improving the UI/UX
This project is open source and available under the MIT License.