This short post will walk you through all of the steps necessary to deploy your app
Build Model and app notebook
- Once it is model is trained and notebook is ready, create a duplicate of your working notebook with minimal content. Here is sample notebook from my work (Find My Food app) of what it should look like
- Once done, download export.pkl & the minimal version of your notebook created in step 1 above
Setup repository in Github
- Create a Github account by clicking here
- Create a repository in Github by clicking here
Note: Repository Name can be ‘FindBear’, Type can be ‘Public’ and you can check ‘Initialize this repository with a README’ option. Finally, click on Create repository button to create it
- Upload your model (export.pkl), notebook to this repository. Additionally, you also need requirements.txt file, which you can download from here. You do not need to modify requirements.txt. Use as-is.
Note: If your model (export.pkl) is larger than 25 MBs (which is very possible, even with Resnet18, you need to use Git Large File Storage service. Steps for same are given at the end of this post
- You only need 3 files (+1 README.md) to build this app. Same are highlighted below
Using Binder to launch your app
- Head over to binder by clicking here
- Configure binder as shown below. Please ensure to add /voila/render/ before your notebook name
- Once done, click on launch button and you are all set
- Share URL to your app (marked with text 3 in the above image) with others to explore
In case your model is larger than 25 Mb, please use below steps to set up Git Large File Storage
Note: Below steps are tested on Windows
- If you do not have Git installed locally, please download from here
- Download and install Git Large File Storage
- Next, create a new folder to hold your Github repository in one of your drive
- Open Git bash and head over to above-created folder by using “cd” command
- Next, Clone your github repository using “git clone (URL)”
Note: You can find URL here
Note: You may be prompted for username and password. If so, please provide your Github username and password
- Finally, run below commands in same order to upload large file. Run in the same folder where you cloned your Github repository
git lfs install
git lfs track "*.pkl"
Note: Please use double quotes around .pkl keyword
git add .gitattributes
git add export.pkl
git commit -m "Add model"
git push -u origin master
- This shall upload your large model file to Github
Good luck and keep learning!
Thanks for posting this as it really helped to get me to understand what I needed.
I changed the requirements.txt:
I also took a look at your sample notebook which was great that you gave me that as a reference. I changed this in my notebook:
from fastai.vision.all import *
from fastai.vision.widgets import *
With that it almost worked.
Binder wanted to deploy at url that looked like this
but when I looked at it on binder and ran the voila from there it worked but the path took out the /tree directory and then it was working!!!
- I later found out this was because I didn’t change it to URL and left it as File as the image shows. It should really be like this:
Thanks for your very insightful post!
Also don’t share those hub.gke links around. They time out after a while and won’t work. Use the /v2/gh/ link it gives you in your screenshot.
Thanks for the comment. I didn’t realize they’ll timeout!
I made a fastai binder app github template based on the instructions in this thread.
It also includes some additional links to things you need to run your app on binder.
I tested it out on Paperspace Gradient (and to a lesser extent, Colab) but if you encounter errors, feel free to reply in this thread so I can update it.
Just to mention that Github has changed things a bit and the default branch is now called main not master
So the last command should read
git push -u origin main
Right now deploying on Binder doesn’t seem to work, but this is another topic.
(Lesson 2: Binder deployment not working with voila)
I can second after working for multiple days with people from Binder, Microsoft, the people on this forum, and looking through the Voila documentation, Binder does not seem to render voila at all, however has no problem with jupyter notebooks as is. Heroku seems to be fine at the moment.
Hi @joedockrill ,
I went through all the steps you shared in your guide - https://course.fast.ai/deployment_heroku
which was fantastic btw. Thanks for putting it together.
I managed to get through all the steps however the app throws an error when I try to view it.
There was an error when executing cell . Please run Voilà with --debug to see the error message.
Here are all steps I took
Used package versions you’d suggested in the requirements.txt file including cpu for pytorch
Included model.pkl file in repo
Included ipython notebook
The app works fine in Jupyter.
The app deployed successfully in Heroku
I get this error when I view the app
Wondering if you could help me out? I feel like I’m nearly there.
Hey Adi. In the requirements file you used
fastai==1.0.6 but as I see you use fastai v2 in your notebook. Try to change fastai requirement to v2 and see if it helps. Also the latest version of fastai requires pytorch 1.7, so to use it you need to change the first two lines in the requirements.txt too
I tried running my notebook with the pinned versions that are compatible with heroku. Unfortunately fastai.vision.widgets throws a module not found error with the older version of fastai.
It feels like a version compatibility issue. Any suggestions?
I think you are right. I tried using the pinned versions of fastai, fastcore, torch, torchvision which I trained the model and had installed in the stripped down version of the notebook.
I originally used wheels that matched this
When that did not work I downgraded to a wheel that Heroku supports. Tried your suggested and it confirmed my original hunch.
I think Heroku does not support anything above
What I’m thinking is to retrain model and reinstall the packages in the stripped down notebook using the versions heroku supports and trying again.
Thanks a lot for your help!