A production-ready Flask web application that analyzes the sentiment of YouTube video and channel comments using advanced machine learning models. Features real-time analysis, comprehensive dashboards, and social media theme detection.
GitHub Repository: https://github.com/theresaanna/sentiment_analyzer
Note: The sentiment analysis is powered by a separate microservice running on Modal cloud GPUs using state-of-the-art transformer models. See the sentiment_ml_service repository for ML implementation details.
- πΉ YouTube Integration: Extract and analyze videos/channels from various URL formats
- π¬ Comment Analysis: Fetch and analyze comments (2.5K free / 5K logged-in / 50K pro)
- π€ Advanced ML Models: Transformer-based sentiment analysis with confidence scoring
- π Rich Visualizations: Interactive charts, word clouds, and sentiment distributions
- π― Social Media Themes: Detect trends like mental health, relationships, career discussions
- β‘ Real-time Processing: Asynchronous analysis with Redis queue management
- π User Authentication: Google OAuth integration with secure sessions
- π³ Subscription System: Stripe integration for premium features
- π User Dashboard: Track analysis history and manage saved results
- π¨ Modern UI: Responsive design with Bootstrap 5 and custom animations
- Framework: Flask with blueprints architecture
- Database: PostgreSQL with SQLAlchemy ORM
- Caching: Redis for session management and queue processing
- Task Queue: Redis Queue (RQ) for asynchronous processing
- ML Service: Modal cloud deployment with GPU acceleration
- Authentication: Flask-Login with Google OAuth 2.0
- Payments: Stripe API for subscription management
- UI Framework: Bootstrap 5 with custom CSS
- React Components: Vite-bundled React for interactive UI elements
- JavaScript: Modern ES6+ with React for dynamic components
- Visualizations: Chart.js for interactive charts
- Word Clouds: Custom canvas-based implementation
- Deployment: Railway with automated CI/CD
- Testing: Pytest with 85%+ coverage
- Monitoring: Health checks and error tracking
- Security: CSRF protection, secure sessions, rate limiting
- Python 3.11+
- PostgreSQL 14+
- Redis 6+
- YouTube Data API key
- Google OAuth credentials
- Stripe API keys (for payment features)
# 1. Clone the repository
git clone https://github.com/theresaanna/sentiment_analyzer.git
cd sentiment_analyzer
# 2. Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install Python dependencies
pip install -r requirements.txt
# 4. Install JavaScript dependencies and build frontend
npm install
npm run web:install # Install frontend dependencie# 6. Set up the database
flask db upgrade
# 7. Start Redis (in a separate terminal)
redis-server
# 8. Start the worker (in another terminal)
python analysis_worker.py
# 9. Run the application
python run.pyThe application will be available at http://localhost:5000
# Flask Configuration
FLASK_APP=run.py
FLASK_ENV=development # or production
SECRET_KEY=your-secret-key-here
# Database
DATABASE_URL=postgresql://user:password@localhost/sentiment_analyzer
# Redis
REDIS_URL=redis://localhost:6379/0
# YouTube API
YOUTUBE_API_KEY=your-youtube-api-key
# Google OAuth
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
# ML Service
MODAL_ML_BASE_URL=https://your-modal-endpoint.modal.run
SENTIMENT_API_URL=https://your-modal-endpoint.modal.run
# Stripe (Optional)
STRIPE_PUBLIC_KEY=your-stripe-publishable-key
STRIPE_SECRET_KEY=your-stripe-secret-key
STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret# Performance
PRECOMPUTE_ANALYSIS_ON_PRELOAD=true
PRELOAD_ANALYSIS_LIMIT=2500
# Email (for notifications)
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-passwordsentiment_analyzer/
βββ app/
β βββ __init__.py # Application factory with extensions
β βββ config.py # Configuration management
β βββ models.py # Database models (User, Analysis, etc.)
β βββ cache.py # Redis caching utilities
β βββ auth/ # Authentication blueprint
β β βββ routes.py # Login, OAuth, subscription routes
β β βββ forms.py # Authentication forms
β βββ main/ # Main application blueprint
β β βββ routes.py # Core analysis routes
β β βββ dashboard_routes.py # User dashboard
β β βββ analysis_queue_routes.py # Queue management
β β βββ forms.py # Analysis forms
β βββ services/ # Business logic layer
β β βββ youtube_service.py # YouTube API integration
β β βββ sentiment_api_service.py # ML service client
β β βββ analysis_service.py # Analysis orchestration
β β βββ channel_service.py # Channel analysis
β βββ templates/ # Jinja2 templates
β β βββ analyze.html # Main analysis page
β β βββ dashboard.html # User dashboard
β β βββ analysis_results.html # Results display
β βββ static/ # CSS, JS, images
βββ migrations/ # Database migrations
βββ tests/ # Comprehensive test suite
βββ scripts/ # Utility scripts
βββ analysis_worker.py # Background job processor
βββ railway.json # Railway deployment config
βββ requirements.txt # Python dependencies
βββ run.py # Application entry point
- Service Layer: Clean separation of business logic from routes
- Queue Architecture: Redis-based async processing for scalability
- Database Models: User management, analysis history, subscriptions
- ML Integration: RESTful API client for Modal-hosted ML service
- Caching Strategy: Multi-level caching for performance
- Testing: 85%+ test coverage with unit and integration tests
- Visit the homepage
- Enter a YouTube video or channel URL
- Click "Analyze Comments"
- View real-time analysis progress
- Explore sentiment charts, word clouds, and theme detection
- Sign in with Google OAuth
- Access your personal dashboard
- View analysis history
- Save and manage favorite analyses
- Export results as JSON/CSV
- Subscribe for premium features (higher limits, priority processing)
https://www.youtube.com/watch?v=VIDEO_IDhttps://youtu.be/VIDEO_IDhttps://www.youtube.com/embed/VIDEO_IDhttps://m.youtube.com/watch?v=VIDEO_ID
https://www.youtube.com/channel/CHANNEL_IDhttps://www.youtube.com/@usernamehttps://www.youtube.com/c/channelname
- Sentiment Distribution: Positive, negative, neutral percentages
- Confidence Scores: Model confidence for each prediction
- Word Clouds: Visual representation of common themes
- Time-based Analysis: Sentiment trends over time
- Theme Detection: Identifies social media discussion topics
- Export Options: Download results in multiple formats
# Run all front end tests (unit and e2e)
npm run test
# Run all Python tests (will cause failures if app is not running on 8001)
# pytest# Format code
black app/ tests/
# Lint
flake8 app/ tests/
# Type checking (if using)
mypy app/# Create migration
flask db migrate -m "Description"
# Apply migrations
flask db upgrade
# Rollback
flask db downgrade- Hot Reload: Flask debug mode enables automatic reloading
- Test Data: Use
scripts/generate_test_data.pyfor sample data - API Mocking: Set
MOCK_SENTIMENT_API=truefor offline development - Debug Mode: Set
FLASK_DEBUG=1for detailed error pages
The application is deployed on Railway with the following services:
- Web Service: Main Flask application
- Worker Service: Background job processor
- PostgreSQL: Primary database
- Redis: Cache and job queue
- Modal ML Service: GPU-accelerated sentiment analysis
# Deploy all services
./deploy_all.sh
# Deploy worker only
./deploy_worker.sh-
Create Railway Project
railway login railway link [project-id]
-
Add Services
- PostgreSQL: Add from Railway dashboard
- Redis: Add from Railway dashboard
- Web: Deploy from GitHub
- Worker: Deploy with custom start command
-
Configure Environment
- Copy variables from
.env.production.template - Set production values in Railway dashboard
- Enable health checks
- Copy variables from
- Test Matrix: Python 3.11, 3.12, 3.13
- Services: PostgreSQL and Redis for integration tests
- Coverage: Reports uploaded to artifacts
- Security: Secrets scanning and dependency checks
- Auto-deploy: Pushes to main trigger deployment
- Health Checks: Ensures zero-downtime deployments
- Rollback: Automatic rollback on failures
- Scaling: Horizontal scaling for high traffic
# View logs
railway logs
# Check service status
railway status
# Run production shell
railway run pythonGET /- HomepagePOST /analyze- Start analysis (returns job ID)GET /analysis/status/<job_id>- Check analysis progressGET /analysis/results/<job_id>- Get analysis results
GET /dashboard- User dashboardGET /api/analyses- List user's analysesDELETE /api/analyses/<id>- Delete analysisGET /api/export/<id>- Export results
analysis_progress- Real-time progress updatesanalysis_complete- Analysis completion notification
- Comment fetching with pagination
- Video/channel metadata
- Rate limit handling
POST /analyze- Batch sentiment analysisPOST /analyze/themes- Theme detectionGET /health- Service health check
- Full YouTube API integration with up to 50K comment support
- Transformer-based sentiment analysis (RoBERTa)
- Real-time analysis with progress tracking
- Interactive visualizations (charts, word clouds)
- Google OAuth authentication
- User dashboard with history
- Redis caching and queue management
- CSV/JSON export functionality
- Social media theme detection
- Stripe payment integration
- Channel analysis support
- Mobile-responsive design
- Production deployment on Railway
- Playlist batch analysis
- Sentiment trend predictions
- Multi-language support
- API rate limit dashboard
- Advanced filtering options
- Collaborative analysis sharing
- Email notifications
- Webhook integrations
- A/B testing for UI improvements
- Redis: 24-hour cache for YouTube data
- In-memory: Frequently accessed analysis results
- Database: Persistent storage with indexed queries
- Horizontal scaling: Multiple worker processes
- Queue management: Priority queues for subscribers
- Rate limiting: Prevents API abuse
- CDN: Static asset delivery (planned)
- CSRF Protection: All forms protected
- SQL Injection: Parameterized queries via SQLAlchemy
- XSS Prevention: Template auto-escaping
- Secure Sessions: HTTPOnly cookies
- Rate Limiting: API and analysis endpoints
- Input Validation: Server-side validation
- Regular dependency updates
- Security headers (CSP, HSTS)
- Environment variable encryption
- Audit logging for sensitive actions
-
Redis Connection Error
# Check Redis is running redis-cli ping # Should return: PONG
-
Database Migration Issues
# Reset migrations flask db stamp head flask db migrate flask db upgrade -
Worker Not Processing Jobs
# Check worker logs tail -f worker.log # Restart worker pkill -f analysis_worker.py python analysis_worker.py
We welcome contributions! Please see our Contributing Guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Write tests for your changes
- Ensure all tests pass (
pytest) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PEP 8
- Use Black for formatting
- Add type hints where applicable
- Write comprehensive docstrings
This project is licensed under the MIT License - see the LICENSE file for details.
- YouTube Data API v3 for video data access
- Hugging Face for transformer models
- Modal for GPU infrastructure and ML service hosting
- Railway for seamless deployment and application hosting
- Flask community for the excellent framework
- Bootstrap team for UI components
- All contributors and users of VibeCheckAI
- GitHub Issues: Report bugs or request features
- Discussions: Join the conversation