How kishan0725/ajax-movie-recommendation-system-with-sentiment-analysis works
Project Type and Purpose
• This is a full-stack, single-page style web application built with Python/Flask on the backend and plain HTML/CSS/JavaScript on the frontend.
• Purpose: Provide content-based movie recommendations enriched with sentiment analysis of user-provided movie reviews. It fetches movie metadata from the TMDB API, scrapes user reviews from IMDB, runs a sentiment model on those reviews, and returns both recommendations and sentiment scores to the user via AJAX.
Main Components
a. Client Browser & UI
• HTML templates (templates/home.html, templates/recommend.html)
• Static assets: CSS (static/style.css), JavaScript controllers (static/autocomplete.js for live search, static/recommend.js for recommendation/AJAX calls)
b. Flask Backend (main.py)
• HTTP endpoints:
• GET “/” serves the home page
• POST or AJAX endpoint “/recommend” that takes a movie title and returns JSON with recommendations + sentiment
• Controller logic for orchestrating calls to:
• TMDB REST API (external)
• IMDb scraping routine (BeautifulSoup inside main.py)
• Local ML models (nlp_model.pkl, tranform.pkl)
c. Data & Model Artifacts
• Raw and processed CSVs under datasets/ and main_data.csv – used to build the content-based recommender (CountVectorizer matrix, cosine similarity)
• Pickled transformer (tranform.pkl) and trained sentiment model (nlp_model.pkl)
d. External Services
• TMDB API for movie metadata (poster URLs, genres, runtime, ratings, etc.)
• IMDB site (web scraped for user reviews)
e. Deployment/Runtime
• Procfile indicates Heroku (or similar PaaS) deployment
• requirements.txt lists Python dependencies: Flask, requests, BeautifulSoup4, scikit-learn, pandas, etc.
Relationships and Data Flows
1. User enters a movie title → autocomplete.js queries backend for matching titles (AJAX GET).
2. User selects or submits a title → recommend.js POSTs title to Flask endpoint.
3. Backend receives title →
a. Calls TMDB API (external) to fetch movie metadata.
b. Scrapes IMDB for user reviews (BeautifulSoup).
c. Runs sentiment analysis: reviews → transform.pkl → nlp_model.pkl → sentiment score.
d. Runs content-based recommender: lookup in main_data.csv/datasets/*.csv, compute similarity via precomputed cosine matrix or compute on the fly.
4. Backend packages: top N similar movies + sentiment summary → returns JSON to frontend.
5. Frontend (JavaScript) receives JSON → dynamically updates the UI with movie cards and sentiment metrics.
Architectural Patterns & Design Principles
• MVC-light:
• Model = CSV datasets + pickled ML artifacts
• View = HTML/CSS templates
• Controller = Flask routes (main.py)
• Single-page feel via AJAX: decouples UI rendering from full-page reload.
• Separation of concerns: scraping, API integration, recommendation logic, and sentiment analysis each encapsulated in dedicated code blocks (in main.py or separate notebooks for preprocessing).
• Reusable/pre-trained assets: pickled models and precomputed similarity matrices stored locally and loaded at startup.