Skip to content

NamaiBest/SDG-Chat-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

32 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒฑ SDG Teacher & Multi-Persona AI Assistant

A powerful dual-mode intelligent chatbot powered by Google's Gemini AI. Switch between Sustainability Teacher mode for ethics and UN SDG education, or Multi-Persona Assistant mode featuring six specialized AI personalities (Chef, Teacher, Tech, Motivation, Finance, Knowledge) that automatically switch based on your needs. Features personalized video analysis, advanced conversation memory, multimodal capabilities, and AI Locket (ESP32-CAM wearable) integration for hands-free AI assistance anywhere.

โœจ Features

๐Ÿ“ฑ AI Locket - ESP32-CAM Wearable Integration

  • ๐ŸŽค Voice-Activated: Say "start capture" for hands-free recording - no buttons needed
  • ๐Ÿ“น Smart Video Capture: 12-second automatic video recording with simultaneous audio
  • ๐ŸŽง Bluetooth Audio: Wireless communication via Bluetooth A2DP earbuds (input & output)
  • ๐Ÿ”— One-Time Device Linking: Register your ESP32 device once - no repeated logins required
  • ๐ŸŒ WiFi Sync: Automatic synchronization with server over WiFi
  • ๐Ÿ’พ Unified Memory: Shared conversation history across web interface and wearable device
  • ๐Ÿ”‹ Portable Power: LiPo battery with TP4056 charging for all-day wearability
  • ๐Ÿ“Š Visual AI: Analyzes what you see and provides context-aware responses
  • ๐ŸŽฏ Intelligent Routing: Automatically uses Personal Assistant mode for quick, practical help
  • โœจ Markdown Formatting: Bold, italic, and formatted text in AI responses
  • ๐Ÿ“ฑ Mobile-Optimized: Responsive interface works great on phones and tablets

See ESP32_SETUP_GUIDE.md for hardware setup and ESP32_INTEGRATION_SUMMARY.md for deployment details.

๐Ÿ‘ค User Authentication System

  • ๐Ÿ‘ค User Accounts: Secure registration and login system
  • ๐Ÿ”’ Password Security: SHA-256 password hashing (never stored in plain text)
  • ๐Ÿ’พ Persistent Memory: Your conversations are saved to your account and persist across sessions
  • ๐ŸŒ Cross-Device: Access your chat history from any device after logging in
  • ๐Ÿข Dual Storage: Automatically uses PostgreSQL (Railway) or JSON files (local development)

๏ฟฝ๐Ÿ”„ Dual Mode System

  • ๐ŸŒฑ Sustainability Teacher Mode: Educational focus on ethics, sustainability, and UN SDGs with personalized, caring responses
  • ๐ŸŽญ Multi-Persona Assistant Mode: Six specialized AI personalities that automatically switch based on your needs

๐ŸŽญ Multi-Persona AI Personalities

Your Personal AI Team:

  • ๐Ÿ‘จโ€๐Ÿณ Chef Rile: Cooking, recipes, meal planning, nutrition, food safety, kitchen organization
  • ๐Ÿ‘จโ€๐Ÿซ Teacher Rile: Learning, education, study tips, explaining concepts, homework help, skill development
  • ๐Ÿ‘จโ€๐Ÿ’ป Tech Rile: Technology, gadgets, software, troubleshooting, digital organization, apps, devices
  • ๐Ÿ’ช Motivation Rile: Encouragement, goal setting, productivity, wellness, mental health, personal growth
  • ๐Ÿ’ฐ Finance Rile: Money management, budgeting, savings, investment basics, financial planning
  • ๐Ÿง  Knowledge Rile: General knowledge, facts, research, curiosity-driven questions, trivia

Each persona automatically activates based on your question and responds with their specialized expertise!

๐Ÿง  Advanced Memory & Analysis

  • ๐Ÿ’ฌ Cross-mode conversation memory: Seamlessly remembers discussions across both modes
  • ๐ŸŽฏ Context-aware responses: AI adapts to your mood and needs (offers support if you look sad/stressed in videos)
  • ๐Ÿ“Š Ultra-detailed media analysis: Comprehensive breakdown of your environment, belongings, and activities
  • โฐ Time-tracking: Monitors changes in your space and habits over time
  • ๐Ÿ“Š Enhanced context window: Up to 20 recent exchanges for better conversation continuity

๐Ÿ–ผ๏ธ Multimodal Capabilities with Optional Context

  • ๐Ÿ“ท Webcam integration: Capture photos directly in-browser for instant analysis
  • ๐ŸŽฅ Video recording with optional context: Record videos and optionally add text descriptions for targeted analysis
  • ๐Ÿ“ File uploads: Upload images and videos for detailed analysis
  • ๐ŸŽค Voice input: Record voice messages with automatic transcription and environmental audio analysis
  • ๏ฟฝ Video context feature: After recording, add optional text context like "Review my presentation skills" or "Check my cooking technique"
  • ๐Ÿท๏ธ Smart tagging: Visual confirmation when video is saved with optional description field

๐ŸŽจ Professional Interface

  • ๐ŸŽฏ Modern UI: Clean, responsive design with smooth animations
  • ๐Ÿ“ฑ Mobile optimized: Full responsive design for phones and tablets
  • ๐ŸŒˆ Mode-based theming: Blue gradient for Personal Assistant, green for Sustainability Teacher
  • ๐Ÿ–ผ๏ธ Media preview: Corner preview system for captured media with clear/remove controls
  • ๐Ÿ“ Markdown support: Rich text formatting in responses (bold, italic, code)
  • โ†ฉ๏ธ Intuitive navigation: Fixed header with back button and mode toggle
  • ๐ŸŽญ Modal system: Elegant profile creation with background collection
  • ๐Ÿ“ Optimized spacing: Compact, efficient use of screen space
  • ๐Ÿ”˜ Aligned controls: Perfectly aligned media buttons (camera, video, file upload)
  • ๐Ÿ’ฌ Smart input bar: Fixed to bottom with no gaps, always accessible

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.7 or higher
  • A free Google Gemini API key

Installation & Setup

  1. Clone or download this project to your local machine

  2. Navigate to the project directory:

    cd "Chat bot"
  3. Create and activate a virtual environment (recommended):

    python -m venv .venv

On macOS/Linux

or

.venv\Scripts\activate # On Windows


4. **Install required packages**:
```bash
pip install fastapi uvicorn requests
  1. Run the chatbot:

    uvicorn app:app --reload

    Or if you're using the virtual environment:

    .venv/bin/python -m uvicorn app:app --reload
  2. Open your browser and go to:

    http://localhost:8000
    

๐ŸŽฎ How to Use

Getting Started

  1. Login or Register:

    • New users: Click "Create New Account" and choose a username and password (minimum 6 characters)
    • Returning users: Enter your username and password to access your saved conversations
  2. Choose your mode using the toggle switch:

    • ๐ŸŒฑ Sustainability Teacher: For education about ethics, sustainability, and SDGs
    • ๐Ÿค– Personal Assistant: For environment analysis and personalized help (default mode)
  3. Start chatting - your conversations are automatically saved to your account and persist across all sessions

๐ŸŒฑ Sustainability Teacher Mode

Perfect for learning and education. Ask questions like:

  • "What is SDG 2?"
  • "How can I live more sustainably?"
  • "What are the ethics of fast fashion?"
  • "Tell me about circular economy"
  • "Analyze the environmental impact in this image/video"

๐Ÿค– Personal Assistant Mode

Ideal for practical help and environment analysis. Try:

  • Environment scanning: "What do you see in my room?" (with photos/videos)
  • Meal planning: "What can I cook with these ingredients?" (show your fridge/pantry)
  • Organization help: "How should I organize this space?"
  • Resource optimization: "What can I do with these items?"
  • Safety assessment: "Is there anything unsafe here?"

๐ŸŽค Voice & Media Features

  • Voice messages: Record speech for automatic transcription and environmental audio analysis
  • Camera capture: Take photos directly in the app for instant analysis
  • Video recording: Record your environment for comprehensive assessment
  • File uploads: Upload existing images and videos

๐Ÿ“ Project Structure

Chat bot/
โ”œโ”€โ”€ app.py                 # Main FastAPI application with authentication & dual-mode support
โ”œโ”€โ”€ database.py            # Database layer (PostgreSQL + JSON fallback) with user auth
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ gemini_key.py     # Holds GEMINI_API_KEY (keep private)
โ”œโ”€โ”€ personas/             # AI persona configurations
โ”‚   โ”œโ”€โ”€ chef_rile.json
โ”‚   โ”œโ”€โ”€ teacher_rile.json
โ”‚   โ”œโ”€โ”€ tech_rile.json
โ”‚   โ”œโ”€โ”€ motivation_rile.json
โ”‚   โ”œโ”€โ”€ finance_rile.json
โ”‚   โ”œโ”€โ”€ knowledge_rile.json
โ”‚   โ””โ”€โ”€ sustainability_rile.json
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ index.html        # HTML with login/register screens and dual-mode interface
โ”œโ”€โ”€ static/
โ”‚   โ”œโ”€โ”€ style.css         # CSS with auth screens, mode-specific themes
โ”‚   โ””โ”€โ”€ script.js         # Frontend with authentication, media handling
โ”œโ”€โ”€ memory/               # Local storage (auto-created for development)
โ”‚   โ”œโ”€โ”€ users.json        # User accounts (local only)
โ”‚   โ”œโ”€โ”€ sustainability/   # Sustainability mode conversations by username
โ”‚   โ”‚   โ””โ”€โ”€ {username}.json
โ”‚   โ””โ”€โ”€ personal_assistant/ # Personal Assistant mode conversations by username
โ”‚       โ””โ”€โ”€ {username}.json
โ””โ”€โ”€ README.md            # This file

๐Ÿ”ง Configuration

API Key

The chatbot uses Google's Gemini-2.5-Flash model, which is free tier compatible. The API key is configured in config/gemini_key.py.

Authentication System

  • Local Development: Uses JSON files in memory/users.json
  • Production (Railway): Automatically uses PostgreSQL database
  • Password Security: SHA-256 hashing (never stores plain text passwords)
  • User-Based Memory: All conversations are tied to username and persist across sessions

Database Tables (PostgreSQL - Auto-created on Railway)

  • users: id, username (unique), password_hash, created_at, last_login
  • conversations: id, session_id, username, mode, user_message, bot_response, timestamp
  • detailed_memories: id, session_id, media_type, detailed_analysis, extracted_memory

๐ŸŒŸ Features in Detail

๐Ÿง  Advanced Memory System

  • Cross-mode continuity: Conversations are remembered across both Sustainability Teacher and Personal Assistant modes
  • Profile-based memory: Each profile maintains its own conversation history and environment observations
  • Enhanced context window: AI receives up to 20 recent exchanges for better conversation flow
  • Time-aware memory: Environment observations are timestamped for tracking changes over time
  • Background-aware responses: AI tailors advice based on your profile background (student, professional, etc.)

๐Ÿ‘ค Profile Management

  • Background collection: Profiles store your living situation and background for personalized responses
  • Multiple profiles: Create different profiles for different contexts or users
  • Modal interface: Clean, professional profile creation with detailed background collection
  • Persistent sessions: Each profile maintains its own conversation continuity

๐ŸŽฏ Mode-Specific Features

๐ŸŒฑ Sustainability Teacher Mode

  • Educational responses focused on ethics, sustainability, and UN SDGs
  • Gentle redirection of off-topic questions to relevant themes
  • Teacher-like explanations that inspire and educate
  • Analysis of media through sustainability lens

๐Ÿค– Personal Assistant Mode

  • Detailed environment analysis: Comprehensive inventory of visible objects, conditions, safety assessment
  • Meal planning: Recipe suggestions based on visible ingredients
  • Organization advice: Space optimization and resource management
  • Adaptive responses: Advice tailored to your background (student budget-friendly, professional efficiency-focused, etc.)
  • Environmental memory: Detailed tracking of your belongings and space changes over time

๐ŸŽจ User Interface

  • Dual-mode toggle: Smooth switching between modes with visual feedback
  • Modern design: Glass-morphism effects, smooth animations, professional appearance
  • Responsive layout: Optimized for mobile and desktop with touch-friendly controls
  • Media integration: Corner preview system, camera overlay, real-time recording feedback
  • Navigation: Easy return to main page, clear visual hierarchy

Chat not working?

  • Check your internet connection (required for Gemini API)
  • Look at the browser console for error messages (F12 โ†’ Console)

Want to reset conversations?

  • Delete the memory/ folder to clear all saved conversations and user accounts (local only). The folder will be recreated automatically when you start a new chat.

Authentication issues?

  • Ensure you're using correct username/password (case-sensitive)
  • Password must be at least 6 characters
  • Check console (F12) for specific error messages
  • For Railway: Ensure PostgreSQL service is connected and DATABASE_URL is set

๐ŸŽฏ About

Created by Namai, an interdisciplinary dual major student passionate about sustainability and ethical technology. This chatbot serves as an educational tool to promote awareness about the UN Sustainable Development Goals and encourage ethical thinking.

๐Ÿ“„ License

This project is open source and available for educational purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors