Project Wiki - AbdlRahman2020/MovieBuddy Wiki
We all have this friend that has watched so many movies and we would go to in case we would like to get a movie recommendation. But the problem is when this friend's taste doesn't match our taste. This is the motivation behind Movie Buddy application. Movie Buddy uses Machine Learning to suggest a list of movies to the user based on their last watched/ preferred movie. For example, if your favorite movie is Inception, the recommender is going to go through the Kaggle movie data set and figure out some other movies you might like to watch based on many factors such as Director, User Ratings, Genre, Actors, etc.
The Projects consists of 3 main components:
- Backend: Flask application exposing a ML model API for giving recommendations.
- ML model: in python and uses movies dataset from kaggle, Pandas library,
The project consists mainly of:
Model repo: contains tmdb.cv, movies dataset obtained from Kaggle.
Templates repository: Holds all the main application HTML files.
Static repository: Holds the .css styling sheets.
app.py: Main python file for running the Flask application.
The webpage takes into consideration simple UI/UX requirements. We tried to design it so that it looks very simple yet informative enough for everyone to understand.
We provide the main input field inside a form where the user input’s the movie name and the form is submitted by the action of the button. Upon submission, the movie name is captured at the backend and further processed. We also provide good effects on the div and other CSS properties so that the UI looks eye friendly and easy to use.
First we have created the index.html web page. It contains the main UI for the application where the user can input their favorite movie's name. We connected index.html to the flask. The page is rendered when the application is initially opened.
So let’s jump to the basics of the flask web application framework to render it for the user.
We use the following code in app.py to simply render the page we just created.
import flaskapp = flask.Flask(__name__, template_folder=’templates’)# Set up the main route @app.route(‘/’, methods=[‘GET’, ‘POST’])def main(): if flask.request.method == ‘GET’: return(flask.render_template(‘index.html’))
Now that we have our index.html rendered, We prompt the user to enter their favorite movie's name. For this part we are using a standard HTML form where it takes the user's input and sends it to the backend. Upon entering, the user clicks on the submit button and the form is submitted.
Once we have a movie name, which is submitted by the user in the form. Let’s hold this name into the m_name variable in python. We accept the form submission using the post method.
if flask.request.method == ‘POST’: m_name = flask.request.form[‘movie_name’] m_name = m_name.title()
We also convert the input movie name to the title format. The title form will simply convert every character of each word to upper case. Now we have 2 options:
- If the input movie name is misspelled or does not exist in the database then show error page & possible similar movie name based on the input.
- If a correct movie name is entered & present in the database, then show the recommendations.
The code below is responsible for doing this:
if m_name not in all_titles: return(flask.render_template(‘negative.html’,name=m_name)) else: result_final = get_recommendations(m_name) names =  dates =  for i in range(len(result_final)): names.append(result_final.iloc[i]) dates.append(result_final.iloc[i]) return flask.render_template(‘positive.html’,movie_names=names,movie_date=dates,search_name=m_name)
Let’s carefully look into positive.html & negative.html.
positive.html is rendered if the input movie name matches with the database. If so, we call the get_recommendations function by passing the movie name. The get_recommendations function is the same as we have discussed in section 2. We take the movie name, calculate the cosine matrix with respect to the dataset and find the most similar movie to the input movie. We sort the results and return back top 10 results. We send similar movie names as well as their release date in a list to the positive.html. We create a tabular layout and print the 10 movies along with their release dates.