How to deploy Fastai model on Binder

Bug description

The build of my project is successful but the page files to load and returns a 404 : Not Found Error.
I am following the fastai book tutorial on how to deploy models on binder as shortly described in this blog post.
I added a requirements.txt file as well as a runtime.txt file in my github repo and docker image builds correctly, only the server fails to load the page afterward. As it is the very last step, the logs provide no useful information of what is going on.

How to reproduce

Follow Step 7 of the blog post tutorial above with my repo details. Should be a simple copy paste of the repo URL and the notebook name. Select URL (not file) adding before the notebook name /voila/render/<notebook_name>.

You have not installed Voila which should be rendering you app. Note the example you are following has voila and ipywidgets in the requirements.txt. You may be able to get away without listing ipywidgets as I believe it is a dependency of voila (you could try to test); however, you definitely need voila there. I think if you do that, the URL you crafted will work to launch the app.

One bit of advice is to work with voila launches from within sessions launched via before trying to make the URL to share it with the world. To that, launch from the page using the repo URL in the main line of the form (direct link is here and then open your notebook from the list. Try running it as a notebook first and then switch to Voila mode via the button on the toolbar. And if you had done that you would have already puzzled as to why there is no Voila mode button on the toolbar. (Although I am noting now the documentation is now all JupyterLab focused and does not show this button. So how would anyone trying to learn know. I’ve added below a picture showing the button in roughly the middle of the toolbar in the classic interface served via MyBinder. One suggestion might be when the JupyterLab 3.0 dust settles and MyBinder is using it so the preview pane is visible, that some folks make a post about using Voila served via MyBinder that better shows what those not familiar with developing in both yet how to work with things so troubleshooting and developing is much more intuitive for new users. There’s a lot of ‘moving parts’ involved due to Binder, Voila, and possible notebook interfaces.) And also the ipywidgets wouldn’t have rendered when you tried to run the notebook directly.

(I 'm still wondering if the blog poster formatted the launch badge on their page correctly but I get the token may be for git-lfs.)


Thanks a lot @fomightez. Your answer is amazing! Yes, you were right: voila was missing and it is not necessary to list ipywidgets in requirements.txt.

I tried launching the repo again as you instructed (i.e. using the repo URL, then clicking on the notebook to check that e.g. fastai is installed and can be important AND then clicking on the voila icon).

At the beginning I was getting an error in cell 10 due to the wrong path to the model (export.pkl) file. In this case, I could guess quickly but how can I run voila --debug for future cases?

I tried opening a terminal and doing voila notebok_name.ipynb --debug but it did not return the error message, only that voila was running.

This is the output voila renders:

How can I get rid of the !jupyter serverextension enable voila --sys-prefix to make it a bit prettier?

And, most important, the app works when I navigate to it from the main repo but not when in I select the URL option indicating my notebook name. Why am I getting in this direct way a 403 error? How can I send my users directly to the app and not the whole repo?

I’m having a little trouble following what you are saying in some parts, and this is probably because I only run your notebook from your launch binder button. (In fact, I only ever run Voila online served by MyBinder.) I think I follow along most of your questions and so let me try to address them:

A: I’m not sure you got the idea you need this? Or where you got that such code belonged in your notebook.You don’t need it for Binder, at least, as the installation also enables Voila. You should look at other Voila deployments and model your code after them. Especially if they are close to what you are trying to do, such as this bear classifier that the fastai folks provide that runs on MyBinder via the launch badge. Ideally, get the originals working in your own repo so that you know the backing tech is handled and then adapt them to use your code. The Voila folks made an entire gallery of examples available that is backed by Binder launches. You can go to the source repositories of any of them by pressing the Source button below the description that links to the launch.
And if you were working with a less fancy extension that did need enabling, a command like that to enable it would go in the postBuild configuration files, (or possibly start), see this example repo and more about config files here.

I’m unsure why you would need this? I think this works in MyBinder, but I haven’t checked. And from the commit where that flag was added it looks to me that it just allows some logging when you launch from the terminal using the voila command. That last part is a very important distinction. It is meant to be used when you launch from the command line, which you don’t use when running from MyBinder.

You see the errors by running it in the notebook mode as I tried to direct you last time. If you can Run all on your notebook in notebook mode and test all the features and options then your code should run cleanly in app mode, too. In other words, you’ll be debugging in the notebook mode so there is not any real need for voila --debug. I should add though that this is being said by someone who only runs Voila in sessions on MyBinder. Maybe running on the command line locally using voila --debug adds some benefits of which I am unaware.

A: As for the URL needed to launch the app direct, it should work now. I think you had that !jupyter serverextension line messing things up before. For others trying to form the URL to do this, I have several examples of launching direct in my own repo here.

1 Like

A: I’m not sure you got the idea you need this? Or where you got that such code belonged in your notebook.You don’t need it for Binder, at least, as the installation also enables Voila

It was in the fastai book chapter 2 (deployment of an app) but maybe is only necessary when on jupyter notebook, I do not really understand how voila works yet. As you said, I removed the line and also worked!

A: As for the URL needed to launch the app direct, it should work now. I think you had that !jupyter serverextension line messing things up before. For others trying to form the URL to do this, I have several examples of launching direct in my own repo here.

Yes, you are right. I was forgetting the following, the notebook name has to be preceded with /voila/render, e.g. /voila/render/Crocodile_vs_Alligator_App.ipynb changing File to URL and then it works!

I would like to take a moment to really appreciate your help! Is there any resources you would recommend to learn more about voila and ipywidgets. It seems to me quite a powerful tool or maybe you know of even better alternatives. Thanks a lot again!

1 Like

There are some other dashboard alternatives but Voila is definitely the best for integration with Jupyter. The developers and community keep making it better. For Jupyter there is also a simple Appmode.

As for learning how to use Voila and ipywidgets, I wish there was something better than the examples (Gallery and others out there) and documentation I could point you to; however, at the present that is the best of which I am aware. I usually find looking at others examples helps a lot. Things take a bit of trial and error. An important thing is to be aware of all the widget options available, see them listed in the documentation here.
I’ll point out though unless you are trying to let others who are deathly afraid of code use your code, most of the things you can do, you can do with just Jupyter and code and markdown cells, if you guide the user through steps, see here for example. The app interface often is just placing things in a more user-friendly, streamlined space. So I would suggest your time is better spent learning standard Jupyter notebooks until you have some advanced code you must share. If you follow it through, this repo featuring scatter plots sort of features a series of notebooks that better reflects a more typical development cycle where you develop in a notebook to get closer to what you want to be user facing and then transform that into voila by adding features. Most of the time is figuring out first what you want to present in the notebook and how. Making the UI to then do that is more of refining how to present it cleanly.


For those, looking into the --debug feature and using Voila with MyBinder. I did actually find an example where running in a notebook worked yet running in Voila app mode failed. I was trying to use Javascript with IPython.notebook.kernel.execute() to inject setting a variable into Python.

In regards to activating debugging in MyBinder, I wonder if you can use a jupyter_config.json file to “configure VoilaConfiguration.show_tracebacks”, like I do here for using real-time collaboration with RetroLab?

Answered my own question, looks like you can according to here.
These other examples here & here show implementing variations on that.

I suspect a minimal jupyter_config.json activating tracebacks would be the following placed at the root of the repository:

  "VoilaConfiguration": {
    "show_tracebacks": true,

However, I just tried it in my Voila demo repo, and it failed. Then looking around to see if it was a known issue, I found @12rambau had posted it here in August 2021. According to @jtpio it is because only a few options are currently read in that way for now, see here.