Skip to content

Atul-SyntexError/MindfulAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 MindfulAI

Your Personal Mental Wellbeing Companion

An AI-powered mental health assistant using evidence-based CBT techniques, built with Streamlit & Groq LLM

πŸš€ Live Demo

πŸ”— Try the App Here

Streamlit Groq Python License


✨ Features

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

πŸ“Έ Preview

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.


πŸ—οΈ Architecture

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

πŸš€ Quick Start

Prerequisites

1. Clone the repository

git clone https://github.com/yourusername/mindfulai.git
cd mindfulai

2. Create a virtual environment (recommended)

python -m venv venv

# Windows
venv\Scripts\activate

# macOS / Linux
source venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

4. Set up your API key

# 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 key

Or β€” paste your key directly in the app's sidebar (πŸ”‘ API Key section).

5. Run the app

streamlit run app.py

The app opens at http://localhost:8501 πŸŽ‰


βš™οΈ Configuration

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

🧘 How the CBT Framework Works

The system prompt uses a 4-step cognitive-behavioral approach β€” invisible to the user but guiding every response:

  1. Validate β€” acknowledge the user's feelings without judgment
  2. Explore β€” ask one focused question to understand context
  3. Reframe β€” gently offer a new perspective (cognitive restructuring)
  4. Empower β€” suggest one small, actionable step

The prompt adapts dynamically based on:

  • Current mood selection
  • Stress level trends
  • Sleep quality
  • Journal entries
  • Conversation history

πŸ”’ Safety

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

🚒 Deployment

Streamlit Cloud (Easiest)

  1. Push your code to GitHub
  2. Go to share.streamlit.io
  3. Connect your repository
  4. Set Main file path: app.py
  5. Add your GROQ_API_KEY in Secrets (Settings β†’ Secrets):
    GROQ_API_KEY = "gsk_your_actual_key"
  6. Click Deploy βœ…

Render

  1. Create a new Web Service on render.com
  2. Connect your GitHub repo
  3. Set:
    • Build command: pip install -r requirements.txt
    • Start command: streamlit run app.py --server.port $PORT --server.headless true
  4. Add GROQ_API_KEY as an environment variable
  5. Deploy βœ…

Railway

  1. Create a new project on railway.app
  2. Connect your GitHub repo
  3. Add a Procfile:
    web: streamlit run app.py --server.port $PORT --server.headless true
    
  4. Add GROQ_API_KEY in Variables
  5. Deploy βœ…

πŸ› οΈ Development

# Run with auto-reload (default)
streamlit run app.py

# Enable debug logging
LOG_LEVEL=DEBUG streamlit run app.py

Project modules

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)

⚠️ Disclaimer

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.


πŸ“„ License

MIT License β€” see LICENSE for details.


Built with πŸ’œ using Streamlit + Groq

Releases

No releases published

Packages

 
 
 

Contributors