An AI-powered mental health assistant using evidence-based CBT techniques, built with Streamlit & Groq LLM
π Try the App Here
| Feature | Description |
|---|---|
| π Mood Tracking | Select your current mood with emoji-based picker; visualized over time |
| π Stress & Sleep Logs | Quick slider/dropdown check-ins; personalized tips based on trends |
| π Guided Journaling | Free-form journal entries that feed context to the AI |
| π§ CBT-Based Prompting | Validate β Explore β Reframe β Empower framework, hidden in natural tone |
| π Safety Layer | Real-time crisis keyword detection with immediate hotline resources |
| π Mood Trend Chart | Interactive Plotly sparkline in the sidebar |
| π‘ Wellness Tips | Dynamic tips based on your stress and sleep averages |
| π¬ Streaming Responses | Token-by-token streaming for a natural chat experience |
| π§ Context Memory | Conversation summarization keeps context within LLM window limits |
| π Premium Dark Theme | Glassmorphic cards, fade-up animations, Inter font |
The app features a polished dark UI with gradient branding, glassmorphic chat bubbles, animated welcome card, and a rich sidebar with mood tracking, journaling, and wellness insights.
MindfulAI/
βββ app.py # Main Streamlit entry point
βββ config.py # Configuration & environment loading
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variable template
βββ .gitignore
β
βββ .streamlit/
β βββ config.toml # Streamlit theme configuration
β
βββ assets/
β βββ style.css # Premium dark-theme CSS
β
βββ components/ # UI layer
β βββ __init__.py
β βββ chat.py # Header, welcome card, message renderer
β βββ sidebar.py # Mood picker, sliders, journal, tips, chart
β
βββ prompts/ # Prompt engineering
β βββ __init__.py
β βββ templates.py # System prompt, context builder, summary prompt
β
βββ services/ # Business logic
β βββ __init__.py
β βββ llm.py # Groq API wrapper (streaming + sync)
β βββ memory.py # Session state, context window, mood/stress logs
β
βββ utils/ # Shared utilities
βββ __init__.py
βββ safety.py # Crisis keyword detection + resource card
βββ helpers.py # Timestamps, formatters, validators
- Python 3.10+
- Groq API Key β get one free at console.groq.com
git clone https://github.com/yourusername/mindfulai.git
cd mindfulaipython -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activatepip install -r requirements.txt# Copy the example env file
cp .env.example .env # macOS/Linux
copy .env.example .env # Windows
# Edit .env and replace gsk_YOUR_KEY_HERE with your actual Groq API keyOr β paste your key directly in the app's sidebar (π API Key section).
streamlit run app.pyThe app opens at http://localhost:8501 π
All settings are controlled via environment variables (.env file):
| Variable | Default | Description |
|---|---|---|
GROQ_API_KEY |
(required) | Your Groq API key |
GROQ_MODEL |
llama-3.3-70b-versatile |
Groq model to use |
GROQ_MAX_TOKENS |
1024 |
Max tokens per response |
GROQ_TEMPERATURE |
0.7 |
Response creativity (0.0 β 1.0) |
LOG_LEVEL |
INFO |
Python logging level |
The system prompt uses a 4-step cognitive-behavioral approach β invisible to the user but guiding every response:
- Validate β acknowledge the user's feelings without judgment
- Explore β ask one focused question to understand context
- Reframe β gently offer a new perspective (cognitive restructuring)
- Empower β suggest one small, actionable step
The prompt adapts dynamically based on:
- Current mood selection
- Stress level trends
- Sleep quality
- Journal entries
- Conversation history
MindfulAI includes a real-time safety layer:
- 15+ crisis keywords are matched against user input with regex
- If triggered, the AI immediately shows crisis hotline numbers for USA, India, UK, and international
- The AI does not attempt to counsel through acute crisis β it directs to professionals
- A permanent disclaimer footer reinforces that this is not a substitute for professional care
- Push your code to GitHub
- Go to share.streamlit.io
- Connect your repository
- Set Main file path:
app.py - Add your
GROQ_API_KEYin Secrets (Settings β Secrets):GROQ_API_KEY = "gsk_your_actual_key"
- Click Deploy β
- Create a new Web Service on render.com
- Connect your GitHub repo
- Set:
- Build command:
pip install -r requirements.txt - Start command:
streamlit run app.py --server.port $PORT --server.headless true
- Build command:
- Add
GROQ_API_KEYas an environment variable - Deploy β
- Create a new project on railway.app
- Connect your GitHub repo
- Add a
Procfile:web: streamlit run app.py --server.port $PORT --server.headless true - Add
GROQ_API_KEYin Variables - Deploy β
# Run with auto-reload (default)
streamlit run app.py
# Enable debug logging
LOG_LEVEL=DEBUG streamlit run app.py| Module | Responsibility |
|---|---|
config.py |
Loads .env, defines all constants and settings |
services/llm.py |
Groq API calls with streaming and error handling |
services/memory.py |
Session state, context window, summarization |
prompts/templates.py |
System prompt, context builder, summary prompt |
utils/safety.py |
Crisis detection and resource card |
utils/helpers.py |
Shared utility functions |
components/chat.py |
Header, welcome card, message renderer |
components/sidebar.py |
Sidebar UI (mood, stress, sleep, journal, tips) |
MindfulAI is an AI companion, not a licensed therapist or medical professional. It does not provide diagnoses, treatment plans, or medication advice. If you are experiencing a mental health crisis, please contact your local emergency services or a crisis hotline immediately.
MIT License β see LICENSE for details.