This tool analyzes the sentiment of comments on YouTube videos. It uses sentiment analysis to classify comments as positive, negative, or neutral, and provides visualizations to display the distribution of these sentiments.
Here’s a quick demo of the YouTube-Comment-Analysis:
- YouTube Comment Analysis: Fetch and analyze comments on a YouTube video.
- Sentiment Classification: Categorizes comments into Positive, Negative, or Neutral sentiments.
- Visualization: Displays sentiment distribution as bar and pie charts.
- Notable Comments: Highlights the most positive and negative comments with sentiment scores.
- Jupyter Notebook / Google Colab
- Python 3+
- Python packages
- Google API Client -
pip install google-api-python-client
- VaderSentiment -
pip install vaderSentiment
- Matplotlib -
pip install matplotlib
- Emoji -
pip install emoji
- Numpy -
pip install numpy
- Flask -
pip install flask
- Google API Client -
- HTML5
- CSS3
-
Clone the repository:
git clone https://github.com/LasithaAmarasinghe/YouTube-Comment-Analysis.git
-
Navigate to the project directory:
cd YouTube-Comment-Analysis
-
Install dependencies:
pip install -r requirements.txt
-
Set Up YouTube API
To interact with the YouTube API, you need an API key. Follow these steps to get a YouTube API key:
- Go to the Google Developer Console.
- Create a new project.
- Enable the YouTube Data API v3 for your project.
- Generate an API key for your project.
- Paste the generated API key into the
app.py
file under theAPI_KEY
variable:
API_KEY = 'your_api_key_here' # Replace with your actual API key
-
Run the Flask application:
python app.py
-
Use the Analysis
- Open your browser and go to
http://127.0.0.1:5000/
. - Enter the YouTube video URL in the provided input field.
- Click on "Analyze Comments" to process the comments of the video.
- The results page will display the sentiment analysis results along with sentiment distribution charts.
- Open your browser and go to
- Extract Video ID: The user provides a YouTube video URL, which is parsed to extract the video ID.
- Fetch Comments: The YouTube Data API fetches up to 1000 comments from the video.
- Clean and Filter Comments: The comments are cleaned (HTML tags removed) and filtered for relevance.
- Sentiment Analysis: Each comment is analyzed using Vader Sentiment Analysis to classify it as positive, negative, or neutral.
- Visualization: Visual representations of sentiment distributions are displayed as bar and pie charts.
- Display Results: Results, including sentiment statistics and notable comments, are shown to the user.
- This project is licensed under the MIT License. See the LICENSE file for details.