SnehaJais's picture
Initial Commit
c37645b verified
import streamlit as st
#===============================
import pandas as pd
from pathlib import Path
import os
import sys
# Define the data directory outside the function
data_dir = Path(__file__).parent / 'data'
# 1. Use st.cache_data to run this function only once
@st.cache_data
def load_ratings_data():
chunks = []
# Using nullable integers ('Int32') is correct
dtype_ratings = {'userId': 'Int32', 'movieId': 'Int32', 'rating': 'float32'}
# Add a spinner to show the user the file is loading
with st.spinner('Loading ratings data (please bear with me)...'):
for chunk in pd.read_csv(
data_dir / 'ratings.csv',
dtype=dtype_ratings,
chunksize=1_000_000
):
# Drop rows where 'userId' or 'movieId' is NaN (as requested)
chunk = chunk.dropna(subset=['userId', 'movieId'])
chunks.append(chunk)
# Concatenate all chunks into the final dataframe
ratings = pd.concat(chunks, ignore_index=True)
return ratings
# 2. Call the function to load and cache the data.
# This DataFrame is now available globally or can be passed to functions.
ratings_df = load_ratings_data()
st.session_state['ratings_df'] = ratings_df # Use session_state to share it easily
#==============================
# Basic page styling
st.markdown(
"""
<style>
.stApp {
background-color: white;
color: #116A91;
}
.title {
text-align: center;
color: #116A91;
font-size: 36px;
margin-bottom: 10px;
}
.subtitle {
text-align: center;
color: #444444;
font-size: 18px;
margin-bottom: 30px;
}
.section {
background-color: #f9f9f9;
padding: 20px;
margin-bottom: 20px;
border-radius: 6px;
}
.header {
color: #116A91;
font-size: 20px;
margin-bottom: 10px;
}
.content {
color: #333333;
font-size: 16px;
line-height: 1.6;
}
</style>
""", unsafe_allow_html=True
)
# Page Title and Subtitle
st.markdown("<div class='title'>Movie Recommender System</div>", unsafe_allow_html=True)
st.markdown("<div class='subtitle'>Discover movies you'll love using different recommendation techniques 🎬</div>", unsafe_allow_html=True)
# Creator Section
st.markdown("""
<div class='section'>
<div class='header'>πŸ‘€ About the Creator</div>
<div class='content'>
<strong>SJ</strong> is the creator of this Movie Recommender System.
<br><br>
Currently working as a <strong>Product Manager</strong>, SJ specializes in leading cross-functional teams to build and launch user-centric digital products. With a strong foundation in both business strategy and data, SJ is passionate about solving real-world problems through thoughtful product design.
<br><br>
Prior to becoming a Product Manager, SJ held roles as:
<ul>
<li><strong>Data Analyst</strong> – Experienced in SQL, Excel, Tableau, Python, Consumer Bureau data, and Microfinance analytics</li>
<li><strong>Data Engineer</strong> – Worked with IBM DataStage, Informatica, Ataccama, and Collibra</li>
</ul>
This diverse background is what inspired SJ to build tools like this β€” combining the power of data with simple, intuitive products.
</div>
</div>
""", unsafe_allow_html=True)
# Purpose Section
st.markdown("""
<div class='section'>
<div class='header'>πŸ“Œ Purpose of This App</div>
<div class='content'>
This Movie Recommender System helps users discover movies they might enjoy based on different recommendation techniques:
<ul>
<li>πŸ”₯ Popularity Based Filtering – Recommend trending movies</li>
<li>🎬 Content-Based Filtering – Recommend movies similar to your favorites</li>
<li>πŸ‘₯ Collaborative User-Based – Recommend movies liked by users similar to you</li>
<li>πŸ›οΈ Collaborative Item-Based – Recommend movies similar to ones you've rated highly</li>
</ul>
The goal is to provide a simple, interactive way to explore movie recommendations tailored to your preferences.
</div>
</div>
""", unsafe_allow_html=True)
# Technology Section
st.markdown("""
<div class='section'>
<div class='header'>πŸ› οΈ Technology Used</div>
<div class='content'>
The application is developed using <strong>Streamlit</strong>, a lightweight and efficient Python framework for building data apps.
<br><br>
Key Python libraries used include <strong>Pandas</strong>, <strong>NumPy</strong>, <strong>Scikit-Learn</strong>, and <strong>Scipy</strong> for data processing and recommendation algorithms.
</div>
</div>
""", unsafe_allow_html=True)
# Features Section
st.markdown("""
<div class='section'>
<div class='header'>πŸ” What You Can Do with It</div>
<div class='content'>
With this app, users can:
<ul>
<li>Explore movie recommendations based on popularity, content similarity, or collaborative filtering</li>
<li>View detailed recommendations for a specific user</li>
<li>Filter movies based on ratings and user activity</li>
<li>Understand hidden patterns in user preferences using latent features</li>
</ul>
The system helps both casual viewers and movie enthusiasts find movies they are likely to enjoy.
</div>
</div>
""", unsafe_allow_html=True)
# Footer / Call-to-action
st.markdown("""
<div class='section'>
<div class='header'>🎯 Ready to Discover Movies?</div>
<div class='content'>
Choose a recommendation technique from the sidebar and start exploring movies tailored to your tastes.
<br><br>
Enjoy discovering new favorites!
</div>
</div>
""", unsafe_allow_html=True)