A production-ready web application for real-time sentiment analysis using state-of-the-art transformer models. Built with Streamlit and Hugging Face Transformers.
- Real-time Sentiment Analysis: Instantly analyze the sentiment of any text input
- Batch Processing: Analyze multiple texts simultaneously
- Interactive Visualizations: Beautiful charts and gauges showing sentiment scores
- Analysis History: Track all your previous analyses with timestamps
- Confidence Scoring: See how confident the AI is about each prediction
- Responsive UI: Clean, modern interface that works on all devices
[Add your deployed app link here after deployment]
This application uses a pre-trained DistilBERT model fine-tuned on the SST-2 (Stanford Sentiment Treebank) dataset. The model achieves state-of-the-art performance with:
- Model:
distilbert-base-uncased-finetuned-sst-2-english - Architecture: Transformer-based (DistilBERT)
- Task: Binary sentiment classification (Positive/Negative)
- Accuracy: ~91% on SST-2 test set
- Input Processing: Text is tokenized using DistilBERT tokenizer
- Model Inference: Processed through 6-layer transformer network
- Classification: Outputs probability distribution over sentiment classes
- Visualization: Results displayed with confidence scores and interactive charts
- Python 3.8 or higher
- pip (Python package manager)
- 2GB RAM minimum (4GB recommended)
- Internet connection (for first-time model download)
- Clone the repository
git clone https://github.com/yourusername/sentiment-analysis-app.git
cd sentiment-analysis-app- Create a virtual environment (recommended)
# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Run the application
streamlit run app.py- Open your browser
- The app will automatically open at
http://localhost:8501 - If not, manually navigate to that URL
- The app will automatically open at
docker build -t sentiment-app .
docker run -p 8501:8501 sentiment-app- Navigate to the "Single Text Analysis" tab
- Enter your text in the input box
- Click "Analyze Sentiment"
- View the results, confidence score, and visualization
- Go to the "Batch Analysis" tab
- Enter multiple texts (one per line)
- Click "Analyze Batch"
- See results table and sentiment distribution chart
- Click the "History" tab
- See all your previous analyses
- Explore sentiment trends over time
- Clear history if needed
sentiment-analysis-app/
β
βββ app.py # Main Streamlit application
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
βββ .gitignore # Git ignore file
βββ Dockerfile # Docker configuration (optional)
βββ screenshots/ # App screenshots (for README)
βββ main.png
βββ batch.png
βββ history.png
- Uses
@st.cache_resourcefor efficient model loading - Single model instance shared across all requests
- GPU acceleration support (automatic CUDA detection)
- Graceful degradation when model fails to load
- Input validation and text truncation
- User-friendly error messages
- Lazy loading of transformer model
- Efficient batch processing
- Minimal memory footprint
- Clean, well-documented code
- Modular function design
- PEP 8 style compliance
- Type hints and docstrings
# Run basic functionality test
python -c "from transformers import pipeline; print('Setup successful!')"| Metric | Score |
|---|---|
| Accuracy | 91.3% |
| F1 Score | 91.1% |
| Inference Speed | ~50ms per text |
| Model Size | 255MB |
This project demonstrates several important concepts:
- Natural Language Processing (NLP)
- Transformer Models
- Transfer Learning
- Web Application Development
- Data Visualization
- Software Engineering Best Practices
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Problem: Model takes too long to load
- Solution: First download is ~255MB. Subsequent loads use cached model.
Problem: Out of memory error
- Solution: Close other applications or use a machine with more RAM.
Problem: App won't start
- Solution: Ensure all dependencies are installed:
pip install -r requirements.txt
- Multi-language support
- Emotion detection (beyond positive/negative)
- Integration with social media APIs
- Export results to CSV/PDF
- Custom model training interface
- A/B testing different models
- Real-time streaming data analysis
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name
- GitHub: @4ktLuffy
- LinkedIn: https://www.linkedin.com/in/henos-dereje-221aa2215/
- Email: henosd19@gmail.com
- Hugging Face for the amazing Transformers library
- Streamlit for the easy-to-use web framework
- Stanford NLP for the SST-2 dataset
- The open-source community
β If you found this project helpful, please give it a star!


