A simple and elegant web application built with Flask that performs sentiment analysis on user-provided text. The application uses TextBlob's natural language processing capabilities to analyze text and determine its sentiment (positive, negative, or neutral), along with polarity and subjectivity scores.
- Real-time Sentiment Analysis: Analyze the sentiment of any text input instantly
- Polarity Score: Get a numerical polarity score ranging from -1 (negative) to +1 (positive)
- Subjectivity Score: Understand how subjective or objective the text is (0 = objective, 1 = subjective)
- Modern UI: Clean and responsive web interface with smooth animations
- Easy to Use: Simple text input form with clear results display
- Flask: Python web framework for building the application
- TextBlob: Python library for processing textual data and performing sentiment analysis
- NLTK: Natural Language Toolkit (dependency of TextBlob)
- HTML/CSS: Frontend with modern styling and animations
- Python 3.11+ (tested with Python 3.11.2)
- pip (Python package installer)
-
Clone the repository (or navigate to the project directory):
cd SentimentAnalysis -
Create a virtual environment (recommended):
python3 -m venv venv
-
Activate the virtual environment:
- On Linux/Mac:
source venv/bin/activate - On Windows:
venv\Scripts\activate
- On Linux/Mac:
-
Install dependencies:
pip install -r requirements.txt
-
Download NLTK data (required for TextBlob):
python -c "import nltk; nltk.download('punkt'); nltk.download('brown'); nltk.download('movie_reviews')"
-
Start the Flask application:
python app.py
-
Open your web browser and navigate to:
http://localhost:5000 -
Enter text in the text area and click "Analyze Sentiment"
-
View the results:
- Sentiment classification (Positive 😊, Negative 😞, or Neutral 😐)
- Polarity score (ranges from -1 to +1)
- Subjectivity score (ranges from 0 to 1)
SentimentAnalysis/
├── app.py # Main Flask application
├── templates/
│ └── index.html # Frontend HTML template
├── venv/ # Virtual environment (not included in git)
├── requirements.txt # Python dependencies
└── README.md # This file
- The user submits text through the web form
- Flask receives the POST request and extracts the text
- TextBlob analyzes the text and calculates:
- Polarity: Measures how positive or negative the text is
- Subjectivity: Measures how opinionated or factual the text is
- The sentiment is classified based on polarity:
polarity > 0: Positivepolarity < 0: Negativepolarity = 0: Neutral
- Results are displayed to the user with color-coded sentiment labels
Input Text:
"I love this product! It's amazing and works perfectly."
Output:
- Sentiment: Positive 😊
- Polarity: 0.625
- Subjectivity: 0.6
The application runs in debug mode by default. To disable debug mode, modify app.py:
if __name__ == "__main__":
app.run(debug=False)This project is open source and available for educational purposes.
Feel free to submit issues, fork the repository, and create pull requests for any improvements..