Skip to content

CogniConnect is an AI-powered memory support app for individuals with dementia/Alzheimer's. It uses GPT-4 Vision, face recognition, and video analysis to help maintain connections with memories through interactive quizzes, semantic search, and performance tracking. Built with Next.js, Flask, and OpenAI.

Notifications You must be signed in to change notification settings

InfiKnight-TGP/Cogni-Connect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

CogniConnect ๐Ÿง 

A full-stack AI-powered memory support application designed to help individuals with dementia and Alzheimer's maintain connections with their memories through intelligent video analysis, face recognition, and interactive cognitive exercises. Built with Next.js, Flask, and OpenAI's GPT-4 Vision API.

โœจ Features

๐ŸŽฅ Video Memory Processing

  • Automatic Video Upload: Upload video journals with metadata (title, date, description, emotions, people)
  • Smart Chunking: Splits videos into 10-second chunks for efficient processing
  • Audio Transcription: Extracts and transcribes audio using speech recognition
  • Face Detection: Automatic face recognition in video frames using face_recognition library
  • Frame Extraction: ORB keypoint detection for extracting unique frames
  • AI Analysis: GPT-4 Vision API analyzes video content and generates contextual Q&A

๐Ÿ” Memory Explorer

  • Semantic Search: Natural language queries to find specific memories
  • Video Playback: Sequential playback of video chunks with auto-advance
  • Random Folder Selection: Randomized video folder selection while maintaining chunk order
  • Transcript Display: Real-time synchronized transcripts during playback
  • Face Recognition Tags: Visual indicators of recognized people in videos

๐Ÿงฉ Cognitive Quiz System

Activity 1: Face Recognition

  • Present faces from videos and known contacts
  • Track correct/incorrect selections
  • Scoring: (correct - incorrect) / total ร— 100
  • Mix of real faces and distractor images

Activity 2: Name-Face Matching

  • Interactive bubble-clicking game
  • Match names to correct faces
  • Dynamic name generation for similar distractors
  • Binary scoring: 100 points for correct match

Activity 3: Context Questions

  • AI-generated questions about video memories
  • GPT-4 powered answer verification
  • Sequential question flow with manual navigation
  • Score averaging: (sum of all question scores / 5) ร— 10

Comprehensive Scoring

  • Combines all 3 activities into unified performance metric
  • Detailed breakdown per activity
  • Historical tracking with timestamps
  • Visual feedback and progress indicators

๐Ÿ“Š Performance Dashboard

  • Memory Trends Graph: Weekly performance visualization
  • Activity Breakdown: Individual scores for each quiz activity
  • Statistics Cards:
    • Average score tracking
    • Recent performance metrics
    • Improvement indicators
    • Completion counts
  • Monthly Analysis: Week-by-week performance within current month
  • Real-time Updates: Dynamic data refresh after each quiz

๐Ÿ‘ฅ Faces Management

  • Known Faces Directory: Upload and manage familiar faces
  • Dynamic Loading: Automatic detection of uploaded face images
  • Name Normalization: Converts filenames to display names (e.g., jawed_karim.jpg โ†’ "Jawed Karim")
  • Static Distractors: Pre-loaded faces for quiz variety
  • Grid Display: Visual grid of all known faces with names

๐Ÿ“ Emergency Contacts

  • Quick Access: Important contact information display
  • Contact Cards: Name, relationship, phone, email, address
  • Important Notes: Critical information and emergency instructions
  • Theme Support: Light/dark mode compatibility

๐ŸŒ“ Theme System

  • Dark/Light Mode Toggle: Seamless theme switching
  • System Preference Detection: Automatic theme based on OS settings
  • Persistent Preferences: Theme choice saved in localStorage
  • Comprehensive Coverage: All pages and components theme-aware
  • Smooth Transitions: Animated icon changes and color transitions

๐Ÿ› ๏ธ Tech Stack

Backend

  • Runtime: Python 3.13+
  • Framework: Flask 3.x with CORS support
  • AI/ML:
    • OpenAI GPT-4 Vision API
    • face_recognition library (dlib-based)
    • SpeechRecognition for audio transcription
  • Video Processing:
    • MoviePy 2.x for video manipulation
    • OpenCV (cv2) for frame extraction
    • ORB keypoint detection for unique frame filtering
  • Data Storage: JSON-based file storage
    • qas.json: Quiz questions and answers
    • video_journals.json: Video metadata
    • performance_data.json: Quiz performance history
  • Utilities:
    • python-dotenv for environment variables
    • NumPy for numerical operations

Frontend

  • Framework: Next.js 14.0.3 (App Router)
  • UI Library: React 18.2.0
  • Styling:
    • Tailwind CSS 3.3.0
    • Tailwind Animate for transitions
    • Custom CSS variables for theming
  • Component Libraries:
    • Radix UI (Dialog, Popover, Select, Tabs, etc.)
    • Lucide React for icons
    • shadcn/ui component patterns
  • Charting: Chart.js 4.4.0 with react-chartjs-2
  • Theme Management: next-themes 0.2.1
  • Date Handling: date-fns 2.30.0
  • Image Optimization: Sharp 0.32.6 (Next.js Image)
  • TypeScript: Full type safety with TS 5

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.13+ installed
  • Node.js 20+ installed
  • Redis Server (optional, for future pub/sub features)
  • OpenAI API Key (for GPT-4 Vision)

Installation

  1. Clone the repository
git clone https://github.com/InfiKnight-TGP/Cogni-Connect.git
cd Cogni-Connect
  1. Backend Setup
cd backend

# Create virtual environment
python -m venv .venv

# Activate virtual environment
.venv\Scripts\Activate.ps1

# Install dependencies
pip install -r requirements.txt

# Create .env file
# Add your OpenAI API key:
# OPENAI_API_KEY=your_api_key_here
  1. Frontend Setup
cd frontend

# Install dependencies
npm install

Running the Application

Option 1: Quick Start (Two Terminals)

Terminal 1 - Backend:

cd "D:\Cogni Connect\backend"
python app.py

Terminal 2 - Frontend:

cd "D:\Cogni Connect\frontend"
npm run dev

Option 2: Development Mode

Backend (Terminal 1):

cd backend
.venv\Scripts\Activate.ps1
python app.py

Expected output:

* Serving Flask app 'app'
* Debug mode: on
* Running on http://127.0.0.1:5000

Frontend (Terminal 2):

cd frontend
npm run dev

Expected output:

โ–ฒ Next.js 14.0.3
- Local: http://localhost:3000
โœ“ Ready in 5s

Access the Application

๐Ÿ“ Project Structure

Cogni-Connect/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ app.py                          # Flask API server
โ”‚   โ”œโ”€โ”€ process_video.py                # Video processing pipeline
โ”‚   โ”œโ”€โ”€ requirements.txt                # Python dependencies
โ”‚   โ”œโ”€โ”€ .env                            # Environment variables (API keys)
โ”‚   โ”œโ”€โ”€ content/                        # Uploaded video files
โ”‚   โ”œโ”€โ”€ known_faces/                    # Known face images
โ”‚   โ”‚   โ”œโ”€โ”€ jawed_karim.jpg
โ”‚   โ”‚   โ”œโ”€โ”€ bharath.jpg
โ”‚   โ”‚   โ”œโ”€โ”€ dinesh.jpg
โ”‚   โ”‚   โ””โ”€โ”€ ... (more faces)
โ”‚   โ”œโ”€โ”€ frames/                         # Extracted video frames
โ”‚   โ”‚   โ””โ”€โ”€ [video_name]_chunks/
โ”‚   โ”œโ”€โ”€ video_chunks/                   # Processed video chunks
โ”‚   โ”‚   โ””โ”€โ”€ [video_name]_chunks/
โ”‚   โ”‚       โ”œโ”€โ”€ chunk_0000_0010.mp4
โ”‚   โ”‚       โ”œโ”€โ”€ chunk_0000_0010_faces.json
โ”‚   โ”‚       โ””โ”€โ”€ full_transcript.json
โ”‚   โ”œโ”€โ”€ qas.json                        # Generated Q&A data
โ”‚   โ”œโ”€โ”€ video_journals.json             # Video metadata
โ”‚   โ””โ”€โ”€ performance_data.json           # Quiz scores
โ”‚
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx                  # Root layout with theme provider
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx                    # Home/Dashboard
โ”‚   โ”‚   โ”œโ”€โ”€ globals.css                 # Global styles + Tailwind
โ”‚   โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ accuracy/route.tsx      # AI answer scoring
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ questions/route.tsx     # Quiz questions API
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ semSearch/route.tsx     # Semantic search
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ videos/route.tsx        # Video list API
โ”‚   โ”‚   โ”œโ”€โ”€ contacts/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx                # Emergency contacts
โ”‚   โ”‚   โ”œโ”€โ”€ dashboard/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx                # Performance dashboard
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ graph.tsx               # Memory trends chart
โ”‚   โ”‚   โ”œโ”€โ”€ explore/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx                # Memory explorer (video player)
โ”‚   โ”‚   โ”œโ”€โ”€ faces/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx                # Known faces grid
โ”‚   โ”‚   โ”œโ”€โ”€ quiz/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx                # Quiz orchestrator
โ”‚   โ”‚   โ””โ”€โ”€ upload/
โ”‚   โ”‚       โ””โ”€โ”€ page.tsx                # Video upload interface
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ nav.tsx                     # Navigation bar
โ”‚   โ”‚   โ”œโ”€โ”€ theme-toggle.tsx            # Dark/light mode toggle
โ”‚   โ”‚   โ”œโ”€โ”€ videoModal.tsx              # Video playback modal
โ”‚   โ”‚   โ”œโ”€โ”€ quiz/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ start.tsx               # Quiz landing page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ personSelect.tsx        # Activity 1: Face recognition
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ namePeople.tsx          # Activity 2: Name matching
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ contextQuestions.tsx    # Activity 3: Context Q&A
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ datePicker.tsx          # Date selection component
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ bubbles/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ index.tsx           # Bubble clicking game
โ”‚   โ”‚   โ””โ”€โ”€ ui/
โ”‚   โ”‚       โ”œโ”€โ”€ button.tsx              # shadcn button
โ”‚   โ”‚       โ”œโ”€โ”€ card.tsx                # shadcn card
โ”‚   โ”‚       โ”œโ”€โ”€ dialog.tsx              # shadcn dialog
โ”‚   โ”‚       โ”œโ”€โ”€ input.tsx               # shadcn input
โ”‚   โ”‚       โ””โ”€โ”€ ... (more UI components)
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”œโ”€โ”€ types.ts                    # TypeScript type definitions
โ”‚   โ”‚   โ””โ”€โ”€ utils.ts                    # Utility functions
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”‚   โ”œโ”€โ”€ known-faces/                # Publicly accessible face images
โ”‚   โ”‚   โ””โ”€โ”€ video_chunks/               # Public video chunks
โ”‚   โ”œโ”€โ”€ next.config.js                  # Next.js configuration
โ”‚   โ”œโ”€โ”€ tailwind.config.ts              # Tailwind CSS config
โ”‚   โ”œโ”€โ”€ tsconfig.json                   # TypeScript config
โ”‚   โ””โ”€โ”€ package.json                    # Node dependencies
โ”‚
โ”œโ”€โ”€ HOW_TO_RUN.md                       # Setup instructions
โ””โ”€โ”€ README.md                           # This file

๐ŸŽฏ Configuration

Backend Configuration (app.py)

UPLOAD_FOLDER = 'content'              # Video uploads directory
KNOWN_FACES_FOLDER = 'known_faces'     # Known faces directory
MAX_CONTENT_LENGTH = 500 * 1024 * 1024 # 500MB max upload size
ALLOWED_EXTENSIONS = {'mp4', 'avi', 'mov', 'mkv', 'webm'}
ALLOWED_IMAGE_EXTENSIONS = {'jpg', 'jpeg', 'png'}

Frontend Configuration (next.config.js)

images: {
  remotePatterns: [
    {
      protocol: 'http',
      hostname: 'localhost',
      port: '5000',
      pathname: '/known-faces/**',
    },
  ],
}

Environment Variables

Create .env in backend/ folder:

OPENAI_API_KEY=your_openai_api_key_here

๐Ÿ“ก API Endpoints

Video Management

POST /upload                           # Upload video with metadata
GET  /video_chunks                     # Get all video chunks
GET  /api/videos                       # Get video list (frontend API)

Face Recognition

GET  /known-faces                      # Get all known faces
POST /known-faces                      # Upload new face image
GET  /known-faces/<filename>           # Serve face image

Quiz System

GET  /api/questions                    # Get quiz questions
POST /api/accuracy                     # Verify answer with AI
POST /performance                      # Save quiz performance
GET  /performance                      # Get performance history

Memory Search

POST /api/semSearch                    # Semantic video search

๐Ÿ’ป Usage Examples

Upload a Video Memory

  1. Navigate to "Upload Video" page
  2. Fill in video details:
    • Title, date, description
    • Emotions experienced
    • People present
  3. Select video file
  4. Click "Upload"
  5. Video processes automatically in background

Use Memory Explorer

  1. Go to "Memory Explorer" page
  2. Enter search query (e.g., "family dinner", "birthday party")
  3. Click "Query" button
  4. Watch relevant video chunks play sequentially
  5. View synchronized transcripts

Take Cognitive Quiz

  1. Navigate to "Quiz" page
  2. Choose an activity:
    • Activity 1: Identify faces from your memories
    • Activity 2: Match names to the correct faces
    • Activity 3: Answer context questions about videos
  3. Complete all activities for comprehensive score
  4. View results on Performance Dashboard

View Performance Dashboard

  1. Go to "Dashboard" page
  2. View stats cards:
    • Average score
    • Recent performance
    • Activity breakdowns
  3. Analyze Memory Trends graph
    • Weekly performance visualization
    • Current month focus
  4. Track improvement over time

Manage Known Faces

  1. Navigate to "Faces" page
  2. View all known faces in grid layout
  3. Upload new faces:
    • Use "Upload Face" button
    • Name format: firstname_lastname.jpg
  4. System automatically normalizes names for display

๐Ÿ—๏ธ Architecture Highlights

Video Processing Pipeline

  1. Upload: User submits video with metadata
  2. Chunking: Video split into 10-second segments
  3. Transcription: Audio extracted and converted to text
  4. Frame Extraction: ORB keypoint detection identifies unique frames
  5. Face Recognition: Detects and identifies people in frames
  6. AI Analysis: GPT-4 Vision generates contextual Q&A
  7. Storage: Chunks, transcripts, and faces saved to JSON

Face Recognition System

  • Training: Loads all images from known_faces/ directory
  • Encoding: Uses dlib's face encoding (128-dimensional vectors)
  • Detection: Scans video frames for faces
  • Matching: Compares detected faces to known encodings
  • Threshold: Configurable tolerance for face matching accuracy

Quiz Scoring Algorithm

Activity 1 (Face Recognition):

score = ((correct_count - incorrect_count) / total_faces) ร— 100

Activity 2 (Name Matching):

score = 100 if correct else 0

Activity 3 (Context Questions):

question_score = AI_verification_score (0-10)
activity_score = (sum(all_question_scores) / total_questions) ร— 10

Combined Score:

final_score = (activity1 + activity2 + activity3) / 3

Theme System

  • CSS Variables: Light/dark color schemes defined in globals.css
  • next-themes: Manages theme state and persistence
  • System Detection: Auto-detects OS preference on first visit
  • LocalStorage: Persists user theme choice
  • No Flash: Prevents theme flicker on page load

Video Randomization Strategy

  • Folder-Level: Randomizes which video folder plays first
  • Chunk-Level: Maintains sequential order within each video
  • Algorithm: Shuffles folders array before concatenating chunks
  • Result: Different video order each page load, but coherent playback

๐ŸŽจ Recent Enhancements

Quiz System Overhaul

โœ… Comprehensive scoring combining all 3 activities
โœ… Sequential question flow with manual navigation
โœ… AI-powered answer verification using GPT-4
โœ… Fixed bubble click handler with proper dependencies
โœ… Activity score breakdown in performance data
โœ… Finish button only appears after all questions answered

Dashboard Improvements

โœ… Stats cards repositioned above Memory Trends graph
โœ… Weekly calculation based on actual calendar weeks
โœ… Filters performance data by current month only
โœ… Dynamic week generation (Week 1-5)
โœ… Real-time updates after quiz completion

Theme System Implementation

โœ… Dark/light mode toggle in navigation
โœ… System preference detection
โœ… Persistent theme storage
โœ… Complete dark mode styling across all pages
โœ… Smooth animated transitions
โœ… Fixed search inputs, cards, and all UI elements

Memory Explorer Updates

โœ… Random video folder selection
โœ… Sequential chunk playback within videos
โœ… Fixed dark mode styling for search interface
โœ… Improved video loading performance

๐Ÿ“ˆ Performance Metrics

Typical performance on modern hardware:

  • Video Upload: ~2-5 seconds (depends on file size)
  • Video Processing: ~30-60 seconds per minute of video
  • Face Recognition: ~100-200ms per frame
  • Transcript Generation: ~5-10 seconds per chunk
  • AI Analysis: ~3-5 seconds per Q&A generation
  • Semantic Search: ~1-2 seconds
  • Quiz Loading: <500ms
  • Dashboard Rendering: <300ms

๐Ÿงช Testing

Currently testing is done manually. Future enhancements will include:

  • Jest/React Testing Library for frontend components
  • pytest for backend API endpoints
  • Integration tests for video processing pipeline
  • E2E tests with Playwright/Cypress
  • Performance benchmarking scripts

๐Ÿšข Deployment

Production Build

Frontend:

cd frontend
npm run build
npm start

Backend:

cd backend
# Set production environment variables
# Use production WSGI server (gunicorn, waitress)
pip install gunicorn
gunicorn app:api

Environment Variables (Production)

OPENAI_API_KEY=your_production_api_key
FLASK_ENV=production
PORT=5000
NODE_ENV=production

Deployment Checklist

  • Set strong API keys
  • Configure CORS for production domain
  • Use production WSGI server (not Flask dev server)
  • Enable HTTPS
  • Set up database (replace JSON storage)
  • Configure file storage (S3, Azure Blob, etc.)
  • Set up monitoring and logging
  • Configure rate limiting
  • Enable caching
  • Set up CI/CD pipeline

๐Ÿ”ฎ Future Enhancements

Phase 1: Core Improvements

  • Database Integration: PostgreSQL for persistent storage
  • User Authentication: Multi-user support with login system
  • Cloud Storage: S3/Azure for video and image storage
  • WebSocket Support: Real-time updates and notifications
  • Mobile App: React Native application
  • Offline Mode: Progressive Web App (PWA) capabilities

Phase 2: Advanced Features

  • Voice Commands: Voice-activated memory search
  • Calendar Integration: Link memories to calendar events
  • Medication Reminders: Smart notification system
  • Caregiver Dashboard: Separate interface for caregivers
  • Social Sharing: Share memories with family members
  • Memory Games: Additional cognitive exercises
  • AR/VR Support: Immersive memory experiences
  • Multi-language Support: Internationalization

Phase 3: AI Enhancements

  • Emotion Detection: Analyze emotions in videos
  • Object Recognition: Tag objects in video scenes
  • Scene Classification: Categorize video content
  • Predictive Analytics: Identify cognitive patterns
  • Personalized Recommendations: Suggest relevant memories
  • Natural Conversations: ChatGPT-style memory chat
  • Auto-captioning: Generate video captions
  • Smart Highlights: Auto-create memory compilations

Phase 4: Clinical Features

  • Progress Tracking: Long-term cognitive assessment
  • Medical Integration: Connect with healthcare systems
  • Clinical Reports: Generate reports for doctors
  • Medication Tracking: Monitor medication adherence
  • Appointment Reminders: Healthcare appointment system
  • Emergency Alerts: Automatic caregiver notifications
  • Research Tools: Anonymized data for dementia research

๐Ÿค Contributing

Contributions are welcome! This project is designed to help individuals with cognitive challenges and their families.

How to Contribute

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Make your changes
  4. Test thoroughly
  5. Commit your changes
    git commit -m 'Add amazing feature'
  6. Push to the branch
    git push origin feature/amazing-feature
  7. Open a Pull Request

Contribution Guidelines

  • Follow existing code style and conventions
  • Add comments for complex logic
  • Update documentation for new features
  • Test all changes before submitting
  • Be respectful and constructive in discussions

๐Ÿ“– Learning Resources

๐Ÿ› Known Issues

  • Video processing can be slow for long videos (>5 minutes)
  • Face recognition accuracy depends on image quality
  • Large video files may cause memory issues
  • AI-generated Q&A quality varies with video content
  • Theme flash may occur on slow connections

๐Ÿ”’ Privacy & Security

  • All data stored locally (no cloud sync by default)
  • OpenAI API calls are encrypted via HTTPS
  • No user data collected or shared
  • Videos and faces remain on local server
  • API key stored in environment variables (never committed)

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • OpenAI - GPT-4 Vision API for intelligent analysis
  • dlib Team - Face recognition algorithms
  • Next.js Team - Modern React framework
  • Tailwind CSS - Utility-first styling
  • shadcn/ui - Beautiful UI components
  • Radix UI - Accessible component primitives
  • Face Recognition Library - Simple face recognition for Python

๐Ÿ“ž Support

For issues, questions, or feature requests:

  • GitHub Issues: Open an issue
  • Email: Contact the maintainers for urgent issues

Built with โค๏ธ to help individuals with dementia and Alzheimer's stay connected to their memories

CogniConnect - Connecting Minds, Preserving Memories

About

CogniConnect is an AI-powered memory support app for individuals with dementia/Alzheimer's. It uses GPT-4 Vision, face recognition, and video analysis to help maintain connections with memories through interactive quizzes, semantic search, and performance tracking. Built with Next.js, Flask, and OpenAI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published