A simple yet powerful movie recommender system built with Flask, leveraging NLP techniques like BoW and Cosine Similarity to suggest movies based on user preferences.
This project uses content-based filtering:
- Uses Bag of Words and Cosine Similarity for measuring movie similarity
- Serves recommendations through a Flask web interface
- Fetches movie posters dynamically using the TMDb API
- Python 3.8+
- Git
-
Clone the repository
git clone https://github.com/Amogh04/movie-recommender.git cd movie-recommender -
Create and activate a virtual environment
python -m venv venv source venv/bin/activate # or `venv\Scripts\activate` on Windows
-
Install dependencies
pip install -r requirements.txt
-
Add your TMDb API key Create a
.envfile and add:api_key=your_tmdb_api_key -
Place data files Ensure
data.pklandsimilarity.pklare present in the root directory. They can be generated by running preprocess.py then vectorize.py. If the similarity file is too large, consider downloading it from https://drive.google.com/file/d/1RgoRbmDGVjQhMAJJ9ryObBis2gc-HY4o/view?usp=sharing or you can run fetch_pickle.py to automatically download them
To run the Flask server:
flask runOpen your browser and navigate to:
http://127.0.0.1:5000/
Select a movie and view the top similar recommendations along with their posters.
app.py: Flask app and routingdata.pkl: Preprocessed movie metadatasimilarity.pkl: Similarity matrix (can be large)recommend_movies(): Core recommendation logic using similarity scores
- Bag of Words: Movie features (overview, genres, keywords, etc.) are combined into a single string and vectorized.
- Cosine Similarity: Used to calculate similarity between vectorized movies.
- Top Matches: Returns the most similar movies excluding the selected one.
Posters are fetched in real-time from The Movie Database (TMDb).
Make sure to sign up and get an API key: https://www.themoviedb.org/