This tutorial will guide you through the steps to set up and run a sentiment analysis project using Python. The project includes analyzing comments from a CSV file, sending them to an Ollama API for sentiment analysis, and visualizing the sentiment distribution.
- Python 3.10 or higher
pip
(Python package installer)- Ollama API setup and running on
http://localhost:11434
First, clone the repository to your local machine:
git clone https://github.com/yourusername/sentiment-analysis-project.git
cd sentiment-analysis-project
Create and activate a virtual environment to manage dependencies:
python3 -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
Install all the required Python packages listed in requirements.txt
:
pip install -r requirements.txt
You can now run the main script to start the sentiment analysis:
python3 main.py
main.py
: The main script that handles reading comments from a CSV file, sending them to the Ollama API for sentiment analysis, and visualizing the sentiment distribution.requirements.txt
: A file listing all the Python dependencies.
Make sure you have a CSV file named commentsEng.csv
in the same directory as main.py
. The CSV file should have a column named commentText
containing the comments to be analyzed.
After setting up everything, you can run the project using:
python3 main.py
This will analyze the comments from the CSV file, print the comments with their detected sentiments, display a bar chart of the sentiment distribution, and print the CPU usage.
Feel free to submit issues and pull requests. For major changes, please open an issue first to discuss what you would like to change.