A professional full-stack sentiment analysis application powered by DistilBERT transformer model with FastAPI backend and modular React frontend.
- Real-time sentiment analysis using DistilBERT model
- Modular React frontend with component separation
- GPU acceleration support (NVIDIA CUDA)
- Analysis history tracking with 10-item limit
- Example text suggestions for quick testing
- Environment-aware configuration (dev/prod modes)
- Professional error handling and user feedback
- Responsive design for desktop and mobile
- Character encoding properly handled
- Development mode indicator for environment awareness
- FastAPI - Modern Python web framework
- Transformers (Hugging Face) - ML model integration
- PyTorch - Deep learning framework
- DistilBERT - Pre-trained sentiment analysis model
- CUDA - GPU acceleration support
- React - Component-based UI library
- Modern JavaScript - ES6+ features
- Modular Architecture - Separated components and utilities
- Environment Configuration - Dev/prod aware setup
- CSS3 - Professional styling with animations
.
βββ README.md
βββ .gitignore
βββ backend/
β βββ webapp/
β β βββ sentiment-api-basic.py # Basic sentiment analysis FastAPI server
β β βββ sentiment-api-metrics.py # Sentiment API with inference time metrics
β β βββ sentiment-api-client.py # Comprehensive test suite and API client
β βββ requirements.txt # Python dependencies
β βββ venv/ # Virtual environment (not in Git)
βββ frontend/
βββ components/
β βββ Icons.js # SVG icon components
β βββ AnalysisResult.js # Result display component
βββ utils/
β βββ config.js # Environment configuration
β βββ api.js # API communication
β βββ helpers.js # Utility functions
βββ data/
β βββ constants.js # Application constants
βββ sentiment-analyzer.html # Main HTML file
βββ app.js # Main React component
βββ styles.css # Professional styling
- Python 3.8+
- NVIDIA GPU (optional, for faster inference)
- Modern web browser (Chrome, Firefox, Safari, Edge)
-
Clone this repository
git clone <repository-url> cd distilbert-sentiment-analyzer
-
Set up the backend
cd backend python -m venv venv venv\Scripts\activate # Windows source venv/bin/activate # Linux/Mac pip install -r requirements.txt
-
Start the FastAPI server
python webapp/main-distbert.py
-
Open the frontend
- Navigate to the
frontenddirectory - Open
sentiment-analyzer.htmlin your web browser - Or serve via a local HTTP server for best results
- Navigate to the
cd frontend
python -m http.server 9000
# Then open: http://localhost:9000/sentiment-analyzer.html- Positive: "I love this course!" β POSITIVE (99.9% confidence)
- Negative: "This is terrible!" β NEGATIVE (99.8% confidence)
- Mixed: "The weather is okay today" β POSITIVE (68.4% confidence)
- Click example buttons for instant text input
- Use Ctrl+Enter for quick analysis
- View analysis history in the sidebar
- Clear history with one click
- Real-time character feedback
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | API information and examples |
/health |
GET | Health check and system status |
/analyze |
POST | Sentiment analysis endpoint |
POST /analyze
{
"text": "I love this application!"
}{
"text": "I love this application!",
"sentiment": "POSITIVE",
"confidence": 0.999
}- Model: DistilBERT (66M parameters)
- Speed: ~60% faster than BERT-base
- Accuracy: ~97% of BERT's performance
- Memory Usage: ~250MB GPU memory
- Inference Time: <100ms per request (GPU)
- Component Separation: Modular React components
- Utility Functions: Reusable helper functions
- Environment Configuration: Dev/prod environment handling
- Constant Management: Centralized configuration
- Error Handling: Comprehensive error management
- Model Caching: Pre-loaded models for instant inference
- GPU Acceleration: CUDA support for faster processing
- Component Efficiency: Optimized React rendering
- Request Optimization: Efficient API communication
cd backend
venv\Scripts\activate # Ensure virtual environment is active
python webapp/test-distbert.py- Health checks - API availability verification
- Single analysis - Individual text processing
- Batch processing - Multiple text analysis
- Edge cases - Empty text, long text, special characters
- Performance testing - Response time measurement
The application automatically detects the environment:
- Development Mode:
localhostβ Shows "(Development Mode)" indicator - Production Mode: Deployed domains β Clean production interface
Configuration managed in frontend/utils/config.js:
- API endpoints
- Timeout settings
- Debug flags
- Environment-specific features
This project demonstrates professional development practices:
- Full-stack development with modern technologies
- Machine learning integration using state-of-the-art models
- API design following RESTful principles
- Frontend architecture with component-based design
- Environment management for deployment flexibility
- Error handling and user experience optimization
- Code organization and maintainability practices
- Git version control with proper .gitignore
- Virtual environment management
- Dependency tracking with requirements.txt
- Modular architecture for scalability
- Professional documentation and code comments
This project is open source and available under the MIT License.
For questions about implementation or deployment:
- Check the comprehensive test suite in
test-distbert.py - Review the API documentation at
http://localhost:8000/docs(when server is running) - Examine the modular frontend code for customization examples
Built with β€οΈ using DistilBERT, FastAPI, and React