Skip to content

A Django-based web application that fetches Instagram posts via the Graph API and performs real-time sentiment analysis using VADER NLP.

License

Notifications You must be signed in to change notification settings

NowarkCodes/Sentiment-Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

🤖 AI Sentiment Analysis for Instagram

Python Django VADER

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.


📑 Table of Contents


✨ Features

  • Instagram Integration: Fetches real-time media and captions directly from Instagram via the Graph API.
  • AI-Powered Analysis: Utilizes vaderSentiment to 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.

📂 Project Structure

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

🚀 Getting Started

Prerequisites

  • Python 3.x installed
  • An active Instagram Business/Creator Account linked to a Facebook Page.
  • Instagram Graph API Token (User Access Token).

Installation

  1. Clone the repository

    git clone [https://github.com/nowarkcodes/sentiment-analysis.git](https://github.com/nowarkcodes/sentiment-analysis.git)
    cd sentiment-analysis
  2. Create and activate a virtual environment

    python -m venv venv
    # Windows
    venv\Scripts\activate
    # macOS/Linux
    source venv/bin/activate
  3. Install dependencies Note: Ensure django, requests, and vaderSentiment are installed.

    pip install django requests vaderSentiment
  4. Navigate to the project directory

    cd "AI Sentiment Analysis Project Folder/sentiment_app"

Configuration

To protect your API credentials, this project utilizes environment variables. You must set these up before running the server.

  1. Set Environment Variables (Linux/macOS)

    export INSTAGRAM_ACCESS_TOKEN="your_actual_access_token"
    export INSTAGRAM_USER_ID="your_instagram_user_id"
  2. 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.


🖥️ Usage

Running the Web App

  1. Apply Migrations

    python manage.py migrate
  2. Run the Server

    python manage.py runserver
  3. 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.

Standalone Script

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.py

Note: You may need to manually update the ACCESS_TOKEN and USER_ID variables inside sentiment_analysis.py before running it.


📡 API Reference

The application exposes a JSON endpoint for programmatic access to the sentiment data.

Get Sentiment Data

  • URL: /api/sentiment/ (Note: Ensure this path is mapped in sentiment/urls.py to the api_sentiment_analysis view)
  • Method: GET
  • Response Example:
    {
      "posts": [
        {
          "caption": "Loving this beautiful sunset! #nature",
          "sentiment": {
            "neg": 0.0,
            "neu": 0.417,
            "pos": 0.583,
            "compound": 0.6369
          }
        }
      ]
    }

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Commit your changes.
  4. Push to the branch.
  5. Open a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Django-based web application that fetches Instagram posts via the Graph API and performs real-time sentiment analysis using VADER NLP.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published