A powerful web application that leverages the Instagram Graph API to fetch post captions and performs Natural Language Processing (NLP) to determine sentiment. Built with Django and VADER Sentiment Analysis, this tool provides real-time insights into the emotional tone of your social media content.
- Instagram Integration: Fetches real-time media and captions directly from Instagram via the Graph API.
- AI-Powered Analysis: Utilizes
vaderSentimentto calculate polarity scores (Positive, Negative, Neutral, and Compound) for every caption. - Web Dashboard: A clean, server-side rendered interface to view posts alongside their sentiment data.
- API Endpoint: Includes a JSON endpoint (
api_sentiment_analysis) for integrating sentiment data into external applications. - Secure Configuration: Uses environment variables to manage sensitive API credentials securely.
sentiment-analysis/
├── AI Sentiment Analysis Project Folder/
│ ├── sentiment_analysis.py # Standalone script for quick testing
│ └── sentiment_app/ # Main Django Project
│ ├── manage.py
│ ├── sentiment/ # Core App
│ │ ├── models.py
│ │ ├── views.py # Logic for API fetch & VADER analysis
│ │ ├── urls.py
│ │ └── templates/ # HTML Dashboard
│ └── sentiment_app/ # Project Settings
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── README.md- Python 3.x installed
- An active Instagram Business/Creator Account linked to a Facebook Page.
- Instagram Graph API Token (User Access Token).
-
Clone the repository
git clone [https://github.com/nowarkcodes/sentiment-analysis.git](https://github.com/nowarkcodes/sentiment-analysis.git) cd sentiment-analysis -
Create and activate a virtual environment
python -m venv venv # Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies Note: Ensure
django,requests, andvaderSentimentare installed.pip install django requests vaderSentiment
-
Navigate to the project directory
cd "AI Sentiment Analysis Project Folder/sentiment_app"
To protect your API credentials, this project utilizes environment variables. You must set these up before running the server.
-
Set Environment Variables (Linux/macOS)
export INSTAGRAM_ACCESS_TOKEN="your_actual_access_token" export INSTAGRAM_USER_ID="your_instagram_user_id"
-
Set Environment Variables (Windows PowerShell)
$env:INSTAGRAM_ACCESS_TOKEN="your_actual_access_token" $env:INSTAGRAM_USER_ID="your_instagram_user_id"
Note: If these are not set, the application will default to placeholder values ("your_default_token_here"), which will result in API errors.
-
Apply Migrations
python manage.py migrate
-
Run the Server
python manage.py runserver
-
Access the Dashboard Open your browser and navigate to
http://127.0.0.1:8000/. You will see a list of your recent Instagram posts with their calculated sentiment scores.
If you prefer to run a quick analysis without starting the full Django server, use the standalone script:
cd "AI Sentiment Analysis Project Folder"
python sentiment_analysis.pyNote: You may need to manually update the ACCESS_TOKEN and USER_ID variables inside sentiment_analysis.py before running it.
The application exposes a JSON endpoint for programmatic access to the sentiment data.
- URL:
/api/sentiment/(Note: Ensure this path is mapped insentiment/urls.pyto theapi_sentiment_analysisview) - Method:
GET - Response Example:
{ "posts": [ { "caption": "Loving this beautiful sunset! #nature", "sentiment": { "neg": 0.0, "neu": 0.417, "pos": 0.583, "compound": 0.6369 } } ] }
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature). - Commit your changes.
- Push to the branch.
- Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.