How sumityadav329/book-recommender-app works
Project Type and Purpose
• This is a full-stack web application focused on delivering book recommendations.
• The app uses Natural Language Processing (NLP) methods (TF-IDF vectorization and cosine similarity) to process book data and generate recommendations.
• The user interface is built with Streamlit, with a backend that handles data ingest, preprocessing, model training, and recommendation logic.
Analyzing the File Structure
• Top-Level Files and Directories:
• Files like app.py, Dockerfile, requirements.txt, setup.py, and LICENSE form the core of the deployment and execution.
• The artifacts folder contains both the raw data file (books.csv) and persisted models (vectorizer.pkl and cosine_sim.pkl).
• The src directory holds the key backend components: data_loader.py, data_preprocessor.py, model_trainer.py, recommender.py etc., representing a modular approach to separate responsibilities like data ingestion, preprocessing, model operations, and logging/exception handling.
• Notebooks directory provides exploratory analysis (e.g., a notebook for the recommender) for prototyping or demonstration purposes.
• Test.py indicates unit testing for overall functionality.
Insights from README
• The README provides a clear system workflow detailing data download, data preprocessing, model training and persistence, and the recommendation engine workflow.
• It outlines that the app interacts with model artifacts to quickly serve recommendations without repeated retraining.
• Technologies involved include Python (core), Streamlit (frontend), scikit-learn for NLP, Pandas, and Joblib for model saving.
Main Components
a. Data Ingestion & Preprocessing:
• Data Loader: Fetches and loads books.csv from an external URL.
• Data Preprocessor: Cleans and transforms the data into a suitable format for vectorization.
b. Model Training and Persistence:
• Model Trainer: Processes text using TF-IDF, computes cosine similarity, and produces models.
• Model Saver: Persists the trained models (TF-IDF vectorizer and cosine similarity matrix) to disk.
• Model Loader: Loads saved models for inference.
c. Recommendation Engine:
• Core recommender logic that leverages the cosine similarity matrix to provide similar book suggestions.
d. Web Interface:
• The Streamlit-based UI (app.py) that interacts with users, takes book title input, and displays recommendations.
e. Supporting Components:
• Custom logger (logger.py) and exception handling (exception.py) modules.
• The artifacts directory serves as the storage for both input data and trained model files.
Relationships and Interactions
• Data Flow:
• Initially, the data loader downloads the dataset which then flows to the data preprocessor.
• Preprocessed data is used by the model trainer to train the TF-IDF vectorizer and compute the cosine similarity matrix.
• Trained models are stored in the artifacts directory and later loaded by the model loader when a recommendation is requested.
• Interaction with the UI:
• The Streamlit web app (app.py) ties the front-end with the backend modules.
• User input flows from the UI to the recommender module, which in turn uses the precomputed models to fetch and display recommendations.
• External Interfaces:
• Dockerfile indicates containerized deployment.
• The setup.py file suggests package encapsulation for environment consistency.
• Data Ingestion (Data Loader)
• Data Preprocessing
• Model Training (TF-IDF and Cosine Similarity computation)
• Model Persistence (Saving and Loading modules)
• Recommendation Engine
• Streamlit Web UI
• Auxiliary modules (Logging, Exception handling)
• External interaction points including Docker container deployment and any potential API endpoints if applicable.