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.
- 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
- 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
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
- 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
- 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
- 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
- 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
- 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 answersvideo_journals.json: Video metadataperformance_data.json: Quiz performance history
- Utilities:
- python-dotenv for environment variables
- NumPy for numerical operations
- 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
- Python 3.13+ installed
- Node.js 20+ installed
- Redis Server (optional, for future pub/sub features)
- OpenAI API Key (for GPT-4 Vision)
- Clone the repository
git clone https://github.com/InfiKnight-TGP/Cogni-Connect.git
cd Cogni-Connect- 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- Frontend Setup
cd frontend
# Install dependencies
npm installOption 1: Quick Start (Two Terminals)
Terminal 1 - Backend:
cd "D:\Cogni Connect\backend"
python app.pyTerminal 2 - Frontend:
cd "D:\Cogni Connect\frontend"
npm run devOption 2: Development Mode
Backend (Terminal 1):
cd backend
.venv\Scripts\Activate.ps1
python app.pyExpected output:
* Serving Flask app 'app'
* Debug mode: on
* Running on http://127.0.0.1:5000
Frontend (Terminal 2):
cd frontend
npm run devExpected output:
โฒ Next.js 14.0.3
- Local: http://localhost:3000
โ Ready in 5s
- Main App: http://localhost:3000
- API Server: http://localhost:5000
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
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'}images: {
remotePatterns: [
{
protocol: 'http',
hostname: 'localhost',
port: '5000',
pathname: '/known-faces/**',
},
],
}Create .env in backend/ folder:
OPENAI_API_KEY=your_openai_api_key_herePOST /upload # Upload video with metadata
GET /video_chunks # Get all video chunks
GET /api/videos # Get video list (frontend API)
GET /known-faces # Get all known faces
POST /known-faces # Upload new face image
GET /known-faces/<filename> # Serve face image
GET /api/questions # Get quiz questions
POST /api/accuracy # Verify answer with AI
POST /performance # Save quiz performance
GET /performance # Get performance history
POST /api/semSearch # Semantic video search
- Navigate to "Upload Video" page
- Fill in video details:
- Title, date, description
- Emotions experienced
- People present
- Select video file
- Click "Upload"
- Video processes automatically in background
- Go to "Memory Explorer" page
- Enter search query (e.g., "family dinner", "birthday party")
- Click "Query" button
- Watch relevant video chunks play sequentially
- View synchronized transcripts
- Navigate to "Quiz" page
- 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
- Complete all activities for comprehensive score
- View results on Performance Dashboard
- Go to "Dashboard" page
- View stats cards:
- Average score
- Recent performance
- Activity breakdowns
- Analyze Memory Trends graph
- Weekly performance visualization
- Current month focus
- Track improvement over time
- Navigate to "Faces" page
- View all known faces in grid layout
- Upload new faces:
- Use "Upload Face" button
- Name format:
firstname_lastname.jpg
- System automatically normalizes names for display
- Upload: User submits video with metadata
- Chunking: Video split into 10-second segments
- Transcription: Audio extracted and converted to text
- Frame Extraction: ORB keypoint detection identifies unique frames
- Face Recognition: Detects and identifies people in frames
- AI Analysis: GPT-4 Vision generates contextual Q&A
- Storage: Chunks, transcripts, and faces saved to JSON
- 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
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
- 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
- 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
โ
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
โ
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
โ
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
โ
Random video folder selection
โ
Sequential chunk playback within videos
โ
Fixed dark mode styling for search interface
โ
Improved video loading performance
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
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
Frontend:
cd frontend
npm run build
npm startBackend:
cd backend
# Set production environment variables
# Use production WSGI server (gunicorn, waitress)
pip install gunicorn
gunicorn app:apiOPENAI_API_KEY=your_production_api_key
FLASK_ENV=production
PORT=5000
NODE_ENV=production- 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
- 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
- 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
- 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
- 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
Contributions are welcome! This project is designed to help individuals with cognitive challenges and their families.
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Test thoroughly
- Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- 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
- Next.js Documentation
- React Documentation
- Flask Documentation
- OpenAI API Reference
- face_recognition Library
- Tailwind CSS
- Chart.js
- 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
- 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)
This project is licensed under the MIT License - see the LICENSE file for details.
- 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
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