A mental health companion web app for students โ journaling, AI chat, risk assessment, and mood tracking, all in one place.
VoiceWithin is a Flask-based web application designed to support student mental health. It combines a mood journal, an AI-powered chatbot, a mental health risk assessment survey, and push notifications into a single, empathetic platform.
- Powered by Groq's LLaMA 3.3 70B model
- Responds in short, warm, Gen-Z-friendly tones โ like a supportive friend at 2AM
- Crisis detection: instantly surfaces the AASRA helpline (๐ฎ๐ณ 9820466627) if distress signals are detected
- Short-term memory: retains the last 10 messages per chat for context
- Auto-names chats based on detected emotions (e.g. "Stressed Talk", "Happy Chat")
- NLTK VADER sentiment analysis runs on every user message
- Write daily entries with a title, content, and mood tag
- Attach images (stored in MongoDB GridFS)
- View, edit, and delete past entries
- Mood statistics with daily and monthly trend summaries
- Multi-question survey covering depression, anxiety, panic attacks, suicidal ideation, self-harm, bullying, substance use, and more
- ML model (scikit-learn) predicts risk level: Low / Medium / High
- Tailored suggestions based on prediction
- History tracked per user for the improvement dashboard
- Combines QA risk history and mood journal data
- Shows progress over time with visual charts
- Web Push via VAPID keys
- Motivational messages sent at 10 AM and 7 PM daily using APScheduler
VoiceWithin/
โโโ hie.py # Main Flask app (routes, chatbot, ML, notifications)
โโโ fixed_chat_route.py # Isolated chat route (dev iteration artifact)
โโโ requirements.txt # Python dependencies
โโโ Procfile # Render deployment config
โโโ suicide_model(3).pkl # Trained ML model (scikit-learn)
โโโ label_encoders.pkl(3) # Label encoders for ML features
โโโ .gitignore
โโโ templates/
โโโ intro.html # Landing page
โโโ index.html # Signup page
โโโ login.html # Login page
โโโ main_menu.html # Dashboard
โโโ survey.html # Mental health QA form
โโโ QA.html # QA interface
โโโ result.html # Prediction result
โโโ journal.html # New journal entry
โโโ hist.html # Journal history
โโโ chatbot.html # AI chat interface
โโโ improve.html # Progress dashboard
| Layer | Technology |
|---|---|
| Backend | Python, Flask |
| Database | MongoDB Atlas (PyMongo, GridFS) |
| AI / LLM | Groq API โ LLaMA 3.3 70B |
| ML Model | scikit-learn (pickle) |
| Sentiment | NLTK VADER |
| Push Notifications | pywebpush + APScheduler |
| Auth | Flask sessions |
| Deployment | Render (free tier) |
| Frontend | HTML, CSS, JavaScript |
- Python 3.9+
- MongoDB Atlas account
- Groq API key (get one here)
- VAPID keys for Web Push (generate with
py-vapidorweb-push-codelab)
git clone https://github.com/Sayedani-29/VoiceWithin.git
cd VoiceWithinpip install -r requirements.txtYou may also need to download the NLTK lexicon:
import nltk
nltk.download("vader_lexicon")Create a .env file in the root directory:
GROQ_API_KEY=your_groq_api_key_here
MONGO_URI=your_mongodb_connection_string_here
SECRET_KEY=your_flask_secret_key_here
โ ๏ธ Never commit your.envfile. It's already included in.gitignore.
python hie.pyVisit http://localhost:5000 in your browser.
This project is configured for deployment on Render.
The Procfile tells Render how to start the app:
web: python hie.py
Steps:
- Push your code to GitHub.
- Create a new Web Service on Render and connect your repository.
- Add the following environment variables in Render's dashboard:
GROQ_API_KEYMONGO_URISECRET_KEY
- Deploy.
๐ก The app includes a keep-alive thread that pings itself every 14 minutes to prevent Render's free tier from sleeping.
| Variable | Description |
|---|---|
GROQ_API_KEY |
API key for Groq LLM access |
MONGO_URI |
MongoDB Atlas connection string |
SECRET_KEY |
Flask session secret key |
| Method | Route | Description |
|---|---|---|
| GET | / |
Intro / landing page |
| GET/POST | /index |
Signup |
| GET/POST | /login |
Login |
| GET | /logout |
Logout |
| GET | /main_menu |
Dashboard (auth required) |
| GET | /survey |
Mental health survey |
| POST | /predict |
Run ML prediction |
| GET | /result |
Show prediction result |
| GET | /journal |
New journal entry form |
| POST | /add |
Save journal entry |
| GET | /hist |
Journal history |
| POST | /edit/<id> |
Edit a journal entry |
| POST | /delete/<id> |
Delete a journal entry |
| GET | /mood_stats |
Mood statistics (JSON) |
| GET | /improve |
Improvement dashboard |
| GET | /chatbot |
Chatbot UI |
| POST | /chat |
Send a message to the bot |
| POST | /save_subscription |
Register push notification subscription |
| GET | /health |
Health check endpoint |
Contributions are welcome! Here's how to get involved:
- Fork this repository
- Create a branch for your feature or fix:
git checkout -b feature/your-feature-name
- Make your changes and commit with a clear message:
git commit -m "feat: add your feature description" - Push to your fork:
git push origin feature/your-feature-name
- Open a Pull Request against the
masterbranch
- Add password hashing (bcrypt)
- Add email verification on signup
- Build a more detailed progress dashboard
- Add multilingual support
- Improve mobile responsiveness
These are known limitations to be aware of before deploying to production:
- Passwords are stored in plaintext โ use
bcryptorwerkzeug.securityto hash passwords before storing. - VAPID keys are hardcoded in
hie.pyโ move them to environment variables. - Sessions are not encrypted beyond Flask's default โ set a strong, random
SECRET_KEY. fixed_chat_route.pyis a development artifact and is not used in production.
- Groq โ blazing fast LLM inference
- NLTK โ sentiment analysis
- MongoDB Atlas โ cloud database
- AASRA โ crisis helpline integrated for Indian users (24/7: 9820466627)
- Everyone who contributed to making mental health tools more accessible ๐
ยฉ 2024 Sayedani-29. All rights reserved. This project and its contents may not be reproduced, distributed, or used without explicit permission from the author.
"Your story matters. You matter." ๐ป