Voila does not work for me

I finally got to the point where I was ready to deploy my model, and as always, nothing works as advertised:

I created my inference notebook with this simple code, which runs just fine in Jupyter Notebooks:

from utils import *
from fastai2.vision.widgets import *
from fastai2.vision.all import *

inferencer = load_learner('export.pkl')
btn_upload = widgets.FileUpload()
out_pl = widgets.Output()
lbl_pred = widgets.Label()
# listener method:
def on_click_classify(change):
    img = PILImage.create(btn_upload.data[-1])
    out_pl.clear_output()
    with out_pl:
        display(img.to_thumb(128,128))
    pred, idx, probs = inferencer.predict(img)
    lbl_pred.value = f'Predicted {pred} with {probs[idx]*100:.01f}% certainty'
    
btn_run.on_click(on_click_classify)

VBox([
     widgets.Label('Squash IT!'),
     btn_upload,
     btn_run,
     out_pl,
     lbl_pred
     ])

Then I click “voila” to run it and I get a very cryptic error message:

There was an error when executing cell [6]. Please run Voila with --debug to see the error message.

I try running “voila inference.ipynb --debug” to see what the error is, but get this back:

[Voila] Voila is running at:
http://localhost:8866/
WARNING | No web browser found: could not locate runnable browser

As a side note, I try this both on my local terminal where I SSH into my VM, and on the Cloud Console provided command line.

Nothing is running on port 8886 on local machine, which makes sense since I’m using Google Cloud. But I can’t navigate to wherever voila is running on the cloud. So, I decide to just pull the repo down to my local machine and try it there, but my notebook won’t run at all on my local machine because of this totally unrelated error:

NotImplementedError: cannot instantiate 'PosixPath' on your system,

which I read somewhere MIGHT be because I’ve been developing the notebook on Google Cloud, which is using a Unix virtual machine, and it won’t run because my local machine is windows.

So basically, I never got to find out why Voila won’t work, and I’ve been stuck on trying to deploy my model for 3 days.

Am I the only one having this many problems? Does anyone have a solution to any of these numerous problems?

2 Likes

Hi @wcneill,

I run into this same Problem but fixed that by running from shell: voila mywebapp0.ipynb
Basically voila nameofyournotebook and then copy the url you get into your web browser. I also notice that your code is slightly different your Jeremy note which has

display(VBox([ widgets.Label(‘Squash IT!’), btn_upload, out_pl, lbl_pred ]))

But display() is missing in your above code. Plus you have additional parameter ‘‘btn_run’’ . I am not sure if this make a difference or fix your your problem!

  1. Forward an additional port (8866) in your connection script to gcp instance.

  2. run voila from the command line in your gcp instance typing

voila yournotebook.ipynb

  1. on your local machine go to localhost:8866

You should be able to use the application on your local machine.

1 Like

Hi there

Did you manage to figure out the original issue with the deployment?
I can run voila locally and it all works fine locally but on mybinder.org I just get this error message for every cell:
“There was an error when executing cell [1]. Please run Voila with --debug to see the error message”
I created the notebook from scratch as there were some Colab bits in there, copied someone else’s notebook and just added my export file and still the same!
About to give up and try something else now.

Thanks,
Perusha

You actually need the export.pkl file and the requirements.txt in your repo , the error that you have in cell one is because its trying to import the export.pkl file . my requrements.txt looks like this
voila
fastai>=0.0.16
pillow<7
packaging
ipywidgets==7.5.1

1 Like

Can anyone confirm if Voila works on Colab?
I’m trying to run this line of code
!jupyter serverextension enable voila --sys-prefix
and getting this error:
Enabling: voila
- Writing config: /usr/etc/jupyter
- Validating…
Error loading server extension voila
X is voila importable?
How to fix this error?

4 Likes

This is what I have tried so far:

iypnb file:

requirement.txt

2.- requirements

readme file

my github repo, which you can see here:

and my settings in binder

and I still get this error:

it still does not work/ do you see something wrong?

1 Like

I think its because you haven’t uploaded the .pkl file in your repo and its trying to find it .

Thanks for helping me, but the export.pkl is in the repo.

Can you try changing the fastai version in requirements.txt to fastai>=0.0.16

This is the error that occurs in your path/‘export.pkl’ line
AttributeError: ‘str’ object has no attribute 'stored_args’

@Uh_shwin I really appreciate you taking the time to reply to my comments. Well I did the changes as you sugested and I updated the screeshots in my previous comments. Maybe you could check it to see if you find some mistake.

its okay this will help someone in the future

unfortunately , I cant figure out what’s wrong , if you figure out a way lemme know too .

for the poxis path error

when you train your model on colab / gradient and download it
then do inference on windows

Just redirect PosixPath to WindowsPath.

import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath

1 Like

yes i am having the same problem, did you fix it?

Nopes. I guess, you cannot run voila on Colab. If you wanna run Voila, go for PaperSpace Gradient instead. Colab won’t allow you to run a web application I guess. Please correct me someone if I’m wrong, or if someone else has done it.

I believe this path thing (converting from / to , linux vs windows) is the real issue here. I already have the lines that you are suggesting, but the same problem remains. Was anyone able to fix this issue?

have you manage to solve the issue? I am facing same problem when using Colab + Binder

In my case the error was caused by missing import required by VBox:

from ipywidgets import *

Additionally I have switched from requirements.txt to Docker file

If you directly use webbrowser.open() - it will always open the link in the default browser. What you can do is to register the any other browser and then launch a new tab. Something like this:

webbrowser.register(name, constructor, instance=None)

Once a python browser type is registered, the get() function can return a controller for that browser type. You can run open, open_new and open_new_tab on the controller object. This will ensure the commands are executed on the same browser instance you opened.

import webbrowser    
url='https://www.google.com'
chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
webbrowser.register('chrome', None,webbrowser.BackgroundBrowser(chrome_path),1)
webbrowser.get('chrome').open_new_tab(url)

If you want to get recognized browsers on your system:

import webbrowser
print webbrowser._browsers

@wcneill @ricardocalleja
I can see I am almost a year/half year behind you but hope that if it doesn’t help you, it might someone else searching on a similar problem.

TL;DR
There is a missing creation of the btn_run object but a later call to it, which fails the script samples you’ve both provided.
Separately, I also found that there is a python/pip change post Oct 2020 that affects if copy pasting from the example nb from fastai.

Detail
I’ve debugged this particular bit of code, which seems to be confusing in the fastai lesson because of the mixing of a components to do step by step checking (with #hide descriptors at the top of the cell) and the code you need to pull out to create a local voila.
What I can see is that the object for ‘btn_run’ hasn’t been created prior to the function in either of your code samples and its called later on, causing a execution stop.

I.e. there is no classify button object for btn_run.on_click(on_click_classify) to act upon and therefore there is a execution error and the error message.
I also don’t see a modifier for the btn_upload to carry this out either, like Jeremy must of done in the demonstration in Lesson 3 video (i think lesson 3?!).

Adding:
btn_run = widgets.Button(description=‘Classify’)

results in a working program.

For those also copy pasting, there is a python change that will have voila fail when rendering the .ipynb. I would avoid or comment out
!pip install -Uqq fastbook

or add the modifier to test, as the way pip deals with dependencies has changed recently >Oct 2020 and this will result in a failure of the nbconvert script that voila relies on for conversion.

I found by "repip’ing’:
pip install voila
resolved to the correct version of nbconvert and allowed a successful render of the program to a local server.

I’ve tested at binder and this works also.
There are a few odd behavioral bugs but they aren’t functional, so I chose to ignore them with toy code.

I’ve found using jupyterlabs is tricky and needs a couple of extensions to be added, so things such as GCP are difficult, and it was easier to resolve on local machine with a copy of jupyter notebooks in a virtualenv.

HTH
Steve

2 Likes