This project is a sentiment analysis application that classifies tweets as positive or negative. The application is built using Python and Flask and containerized using Docker. The dataset consists of labeled tweets, and the best-performing model is selected from multiple machine learning models.
sentiment_analysis/ │ ├── app.py # Flask application ├── Dockerfile # Docker configuration file ├── labeled_tweets.csv # CSV file containing the labeled tweet data ├── requirements.txt # Python dependencies ├── sentiment_analysis.py # Data preprocessing, training models, and saving the best model ├── .gitignore # Git ignore file ├── README.md # Project documentation ├── venv/ # Virtual environment (not included in version control) └── .github/ # GitHub configuration directory └── workflows/ # GitHub Actions workflows directory └── ci-cd.yml # CI/CD pipeline configuration file
- Python 3.x
- Docker
-
Create Virtual Environment
cd sentiment_analysis python -m venv venv
-
Activate Virtual Environment
-
On Windows:
.\venv\Scripts\Activate.ps1
-
On macOS and Linux:
source venv/bin/activate
-
-
Install Dependencies
pip install -r requirements.txt
Run the sentiment_analysis.py
script to preprocess the data, train the models, and save the best model:
python sentiment_analysis.py
Run the Flask app locally to test the sentiment prediction API:
python app.py
Send a POST request to http://127.0.0.1:5000/predict with a JSON body containing the text to predict. For example, using PowerShell:
$headers = @{'Content-Type' = 'application/json'}
$body = '{"text": "I love this product!"}'
$response = Invoke-WebRequest -Uri http://127.0.0.1:5000/predict -Method POST -Headers $headers -Body $body
$response.Content
To run the Docker image on any machine with Docker installed:
docker pull aarize/sentiment-analysis:latest
docker run --rm -p 3000:5000 aarize/sentiment-analysis:latest