From b555cae462838af5efbef34c3d620a45bf4cf409 Mon Sep 17 00:00:00 2001 From: Aarize Siddique <97665948+Aarize29@users.noreply.github.com> Date: Sat, 6 Jul 2024 16:21:56 +0530 Subject: [PATCH] Create README.md --- README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0abdf00 --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# Sentiment Analysis Project + +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. + +## Project Structure + +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 + + +## Getting Started + +### Prerequisites + +- Python 3.x +- Docker + +### Set Up Virtual Environment and Install Dependencies + +1. **Create Virtual Environment** + + ```bash + cd sentiment_analysis + python -m venv venv + ``` + +2. **Activate Virtual Environment** + + - On Windows: + + ```bash + .\venv\Scripts\Activate.ps1 + ``` + + - On macOS and Linux: + + ```bash + source venv/bin/activate + ``` + +3. **Install Dependencies** + + ```bash + pip install -r requirements.txt + ``` + +### Preprocess Data and Train Models + +Run the `sentiment_analysis.py` script to preprocess the data, train the models, and save the best model: + +```bash +python sentiment_analysis.py +``` +### Test Flask App Locally +Run the Flask app locally to test the sentiment prediction API: + +```bash +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: +```bash +$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 +``` +### Using the Docker Image +To run the Docker image on any machine with Docker installed: +```bash +docker pull aarize/sentiment-analysis:latest +docker run --rm -p 3000:5000 your_dockerhub_username/sentiment-analysis:latest +``` + + +