Skip to content

Sayedani-29/VoiceWithin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  VoiceWithin

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.


โœจ Features

๐Ÿค– AI Chatbot

  • 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

๐Ÿ““ Mood Journal

  • 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

๐Ÿ“Š Mental Health Risk Assessment

  • 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

๐Ÿ“ˆ Improvement Dashboard

  • Combines QA risk history and mood journal data
  • Shows progress over time with visual charts

๐Ÿ”” Push Notifications

  • Web Push via VAPID keys
  • Motivational messages sent at 10 AM and 7 PM daily using APScheduler

๐Ÿ—‚๏ธ Project Structure

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

๐Ÿ› ๏ธ Tech Stack

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

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.9+
  • MongoDB Atlas account
  • Groq API key (get one here)
  • VAPID keys for Web Push (generate with py-vapid or web-push-codelab)

1. Clone the repo

git clone https://github.com/Sayedani-29/VoiceWithin.git
cd VoiceWithin

2. Install dependencies

pip install -r requirements.txt

You may also need to download the NLTK lexicon:

import nltk
nltk.download("vader_lexicon")

3. Set up environment variables

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 .env file. It's already included in .gitignore.

4. Run the app

python hie.py

Visit http://localhost:5000 in your browser.


โ˜๏ธ Deployment (Render)

This project is configured for deployment on Render.

The Procfile tells Render how to start the app:

web: python hie.py

Steps:

  1. Push your code to GitHub.
  2. Create a new Web Service on Render and connect your repository.
  3. Add the following environment variables in Render's dashboard:
    • GROQ_API_KEY
    • MONGO_URI
    • SECRET_KEY
  4. Deploy.

๐Ÿ’ก The app includes a keep-alive thread that pings itself every 14 minutes to prevent Render's free tier from sleeping.


๐Ÿ”‘ Environment Variables

Variable Description
GROQ_API_KEY API key for Groq LLM access
MONGO_URI MongoDB Atlas connection string
SECRET_KEY Flask session secret key

๐Ÿงฉ API Routes

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

๐Ÿค Contributing

Contributions are welcome! Here's how to get involved:

  1. Fork this repository
  2. Create a branch for your feature or fix:
    git checkout -b feature/your-feature-name
  3. Make your changes and commit with a clear message:
    git commit -m "feat: add your feature description"
  4. Push to your fork:
    git push origin feature/your-feature-name
  5. Open a Pull Request against the master branch

Ideas for contribution

  • Add password hashing (bcrypt)
  • Add email verification on signup
  • Build a more detailed progress dashboard
  • Add multilingual support
  • Improve mobile responsiveness

๐Ÿ› Known Issues & Security Notes

These are known limitations to be aware of before deploying to production:

  • Passwords are stored in plaintext โ€” use bcrypt or werkzeug.security to 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.py is a development artifact and is not used in production.

๐Ÿ’› Acknowledgements

  • 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 ๐Ÿ’›

๐Ÿ“„ License

ยฉ 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." ๐ŸŒป

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors