How vinayhr01/twitter-sentiment-analysis-web-application-project works
Project Type and Purpose
• This is a full-stack web application built with the Django framework that performs real-time Twitter sentiment analysis focused on economic consequences of COVID-19.
• The README explains that three ML models (Naive Bayes, SVM, Logistic Regression) are trained on a historical dataset (finalD.csv), compared for accuracy, and the best (SVM) is used in production alongside the VADER social-media sentiment library.
• Users land on a web interface, submit or trigger live tweet fetches, and view classification results.
File Structure
• Top Level
• manage.py, requirements.txt → Django project entry, dependencies
• finalD.csv, compare.csv, results/... → training data and outputs
• sentiment_analysis/ → Django project settings & WSGI
• sentiment_home/ → “home” Django app for landing pages
• sentiment/ → core Django app handling forms, views, ML code
• “sentiment” app
• sentiment_analysis_code.py → offline training and model-loading logic
• tweepy_sentiment.py → real-time tweet fetch from Twitter API
• views.py, forms.py, models.py → request handling, form definitions, and any persisted models
• templates/ & static/ → HTML pages and assets for sentiment features
• “sentiment_home” app
• views.py, templates/ & static/ → home page UI
• Configuration files
• sentiment_analysis/settings.py → database & app registration
• urls.py in each app plus root → URL routing
README for Additional Insights
• Confirms Python/Django stack, NLTK downloads for preprocessing, CSV-based training pipeline, real-time classification via Tweepy + SVM + VADER.
• No mention of heavy external infrastructure—uses Django runserver and SQLite by default.
a. Main Components
• Client Browser (User Interface)
• Django Web Server
‑ URL Dispatcher
‑ Views & Forms
‑ Template Renderer
‑ Static File Server
• Database (SQLite/MySQL/PostgreSQL)
• Machine Learning Engine
‑ Offline Trainer (NaiveBayes, SVM, LogisticRegression)
‑ Runtime Classifier (SVM model + VADER)
• External Service: Twitter API (via Tweepy)
• Auxiliary: NLTK data store (punkt, wordnet, tagger)
b. Relationships & Data Flow
1. Browser → HTTP request → Django URL Dispatcher
2. URL → sentiment.views or sentiment_home.views
3. If classification requested:
‑ sentiment.views invokes tweepy_sentiment.py to fetch tweets
‑ Preprocess via sentiment_analysis_code.py (tokenize, vectorize)
‑ Pass text to SVM classifier & VADER library
‑ Receive sentiment label
4. View renders sentiment HTML template with results → Response to Browser
5. Optionally, persistence: view writes query & result to Database via Django models
c. Architectural Patterns & Principles
• Monolithic MVC (Model-View-Controller) via Django
• Separation of concerns:
• sentiment_home app for static landing pages
• sentiment app for dynamic ML-driven features
• Reuse of third-party libraries (NLTK, Scikit-Learn, VADER, Tweepy)
d. Key Technologies/Frameworks
• Backend: Python 3.x, Django
• ML: Scikit-Learn, NLTK, VADER
• External API: Tweepy (Twitter)
• Frontend: HTML5, CSS3, Bootstrap, custom JS
• Data store: SQLite (default) or any Django-supported RDBMS