This is a simple Flask-based web application that uses the Twitter API v2 to fetch recent tweets based on a keyword and performs sentiment analysis using TextBlob. It classifies each tweet as Positive, Negative, or Neutral.
- Fetches recent tweets using Twitter API v2
- Performs sentiment analysis using
TextBlob
- Displays results in a clean and responsive web interface
- Built with Flask, Tweepy, and Jinja2
- Python 3.x
- Flask
- Tweepy (Twitter API v2)
- TextBlob
- dotenv (
python-dotenv
) - HTML (Jinja2 templating)
- Clone the repository
git clone https://github.com/Chirag-joshi123/tweet-sentiment-analysis.git
cd tweet-sentiment-analysis
- Create a virtual environment and activate it (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Set up your environment variables
Create a .env
file in the root directory:
touch .env
Inside .env
, add your Twitter Bearer Token:
BEARER_TOKEN=your_twitter_api_bearer_token_here
-
Go to the Twitter Developer Portal
-
Log in with your Twitter account and click on Developer Portal
-
Click Projects & Apps > Overview > + Create App
-
After creating the app:
- Go to your App Settings
- Navigate to Keys and Tokens
- Copy the Bearer Token and paste it into your
.env
file
Make sure to keep it private and never expose it in public repositories.
python app.py
Then open your browser and go to: 👉 http://127.0.0.1:5000
Render makes it easy to deploy Flask apps.
-
Push your code to GitHub
-
Go to https://render.com and sign in
-
Click on "New Web Service"
-
Connect your GitHub repo and select this project
-
Use the following settings:
-
Build Command:
pip install -r requirements.txt
-
Start Command:
gunicorn app:app
-
Runtime: Python 3.x
-
Environment Variables: Add your
BEARER_TOKEN
key here.
-
-
Click "Create Web Service"
Your app will be live at a Render-provided URL!
tweet-sentiment-analysis/
├── app.py # Main Flask app
├── templates/
│ └── index.html # HTML template for UI
├── .env # Environment variables (not to be shared)
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── Procfile # Optional (for deployment platforms like Heroku/Render)
- Only tweets in English (
lang='en'
) are analyzed. - The app fetches a maximum of 10 tweets per query to respect API rate limits.
- Twitter API v2 Bearer Token is required — you can get one by creating a project on the Twitter Developer Portal.
- Support for analyzing tweet trends
- Graphical visualization of sentiment
- OAuth login for posting or interacting with tweets
- Support for multiple languages
This project is open-source under the MIT License.
Chirag Joshi – @Chirag-joshi123 Feel free to fork, contribute, or reach out with suggestions!