Creating a movie recommendation system for iOS with Turi Create
This code pattern is an iOS Application that helps you find new movies to watch! It's been built to show you how you can use Turi Create, Apple's new deep learning framework, to build amazing recommendation systems very quickly, locally, on your machine - in under 2 minutes training time.
When the reader has completed this Code Pattern, they will understand how to:
The following are prerequisites to start developing this application:
In order to get the MovieLens dataset setup, run the following script:
$ sh setup.sh
It'll download the data and move the files to their relevant locations.
In order for the recommendations to work, you need a trained model. Turi Create is a Python package that will train this model for you.
Go ahead and start your Jupyter Notebooks. In the local_model_training
folder, open the TrainRecommendationModel.ipynb
notebook. Run the notebook, and once it's done executing, you're going to have a folder called movie_rec
, which contains the trained Turi Create model. Unlike other machine learning libraries, Turi Create does not use files for models; instead, it uses folders.
Turi Create supports exporting recommender models to CoreML, so they can run on-device, and there's no need for a backend. However, it only works with iOS 12 and above (which is currently in Beta), and there's an issue with linking the custom model framework. Therefore, this code pattern will use a backend that takes requests from the iOS Application, and runs the users' preferences through the Turi Create model, to return predictions as to what the user would like to watch next.
First, copy the movie_rec
folder (your trained model) from local_model_training
, and paste it into the serverside_prediction_api
folder. Once that's done, run the following command from a terminal window within that folder:
FLASK_APP=backend.py flask run
This will run the backend.py
file, which is the flask application.
Next, open up a tunnel to the backend with ngrok, so your iOS App can access it:
ngrok http 5000
(change 5000 to whichever port you chose with Flask)
Finally, you can run the front-end of the application.
Start by pointing your iOS app to the backend. Go to the iOS_Frontend/MovieRecommender/MovieRecommender/MovieHandler.swift
file, and change the backend
constant to the link of the ngrok tunnel.
Then, in the iOS_frontend/MovieRecommender
folder, and open the xcworkspace
file. Once you're there, run the application by hitting ⌘ + R or clicking the run button beside the window controls on the top left of Xcode.
This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.