Skip to content

huseyinaslim/twitter-sentimental-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Sentiment Analysis

A full-stack application for analyzing sentiment in tweets and text using AI models. Developed by Hüseyin ASLIM as part of the Başkent University BIL479 - Pattern Recognition course project.

Application Screenshot

Features

  • Text Sentiment Analysis
  • Tweet URL Sentiment Analysis
  • Twitter User Sentiment Analysis
  • Visualization of sentiment results
  • Multi-language support (English, Turkish, and more)
  • Modern UI with light and dark mode

Model Information

The project uses the cardiffnlp/twitter-xlm-roberta-base-sentiment model from the Hugging Face Transformers library. This model:

  • Is based on XLM-RoBERTa architecture
  • Supports multilingual sentiment analysis
  • Classifies text into three categories: Positive, Neutral, and Negative
  • Provides confidence scores for each sentiment category

Model Evaluation

Tech Stack

Backend

  • FastAPI
  • Transformers
  • PyTorch
  • Pandas
  • Matplotlib
  • Playwright (for web scraping)
  • ntscraper (for Twitter scraping)

Frontend

  • Next.js
  • React
  • Tailwind CSS
  • shadcn/ui (UI components)
  • Axios (API client)

Project Structure

├── backend/             # FastAPI backend
│   ├── main.py          # Main API file
│   └── requirements.txt # Python dependencies
│
└── frontend/            # Next.js frontend
    ├── public/          # Static assets
    ├── src/             # Source code
    │   ├── app/         # Next.js app router
    │   ├── components/  # React components
    │   ├── lib/         # Utilities
    │   └── types/       # TypeScript types
    └── package.json     # Node dependencies

Setup Instructions

Backend

  1. Navigate to the backend directory:

    cd backend
  2. Install dependencies:

    pip install -r requirements.txt
  3. Install Playwright browsers:

    playwright install
  4. Start the server:

    uvicorn main:app --reload

The API will be available at http://localhost:8000

Frontend

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev

The frontend will be available at http://localhost:3000

API Endpoints

Health Check

  • GET /: Check if the API is running

Text Analysis

  • POST /analyze/text: Analyze sentiment of provided text
    • Body: {"text": "Your text here"}
    • Returns: Sentiment label, confidence scores, and visualization

Tweet Analysis

  • POST /analyze/tweet: Analyze sentiment of a tweet from URL
    • Body: {"url": "https://twitter.com/username/status/tweetid"}
    • Returns: Tweet content, sentiment label, confidence scores, and visualization

User Analysis

  • POST /analyze/user: Analyze sentiment of tweets from a specific user
    • Body: {"username": "username", "max_results": 20}
    • Returns: User statistics, sentiment distribution, top positive/negative tweets with charts

Deployment

Backend Deployment

The backend can be deployed to any server that supports Python:

  1. Clone the repository
  2. Install the requirements: pip install -r backend/requirements.txt
  3. Install Playwright browsers: playwright install
  4. Run with Gunicorn (for production):
    gunicorn -w 4 -k uvicorn.workers.UvicornWorker backend.main:app

Frontend Deployment

The Next.js frontend can be deployed to Vercel or any hosting provider:

  1. Build the application:

    cd frontend
    npm run build
  2. Start the production server:

    npm start

Alternatively, deploy directly to Vercel:

vercel

Requirements

Backend Requirements

  • Python 3.9+
  • FastAPI 0.104.1+
  • Transformers 4.35.0+
  • PyTorch
  • Playwright 1.39.0+
  • Other dependencies listed in backend/requirements.txt

Frontend Requirements

  • Node.js 18+
  • Next.js 14+
  • React 18+
  • Other dependencies listed in frontend/package.json

About

A full-stack application for analyzing sentiment in tweets and text using AI models.

Topics

Resources

Stars

Watchers

Forks

Languages