Skip to content

Instantly share code, notes, and snippets.

@hamelsmu
Last active November 14, 2022 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamelsmu/35be07d242f3f19063c3a3839127dc67 to your computer and use it in GitHub Desktop.
Save hamelsmu/35be07d242f3f19063c3a3839127dc67 to your computer and use it in GitHub Desktop.
A demo of creating a gradio app with nbdev
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cerkut
Copy link

cerkut commented Nov 14, 2022

The last step "Convert this notebook into a Gradio app" silently fails, no app.py is created. Tried on VSCode, jupyter, juypter lab, colab and kaggle. When I try the CLI with nbdev_export I get the following error. Is there another way to auto-generate the app.py without manual editing? Thanks.

Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/bin/nbdev_export", line 8, in
sys.exit(nbdev_export())
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/site-packages/fastcore/script.py", line 119, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/site-packages/nbdev/doclinks.py", line 138, in nbdev_export
_build_modidx()
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/site-packages/nbdev/doclinks.py", line 96, in _build_modidx
res['settings'] = {k:v for k,v in get_config().d.items()
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/site-packages/nbdev/doclinks.py", line 96, in
res['settings'] = {k:v for k,v in get_config().d.items()
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/_collections_abc.py", line 851, in iter
yield (key, self._mapping[key])
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/configparser.py", line 1258, in getitem
return self._parser.get(self._name, key)
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/configparser.py", line 799, in get
return self._interpolation.before_get(self, section, option, value,
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/configparser.py", line 395, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/opt/homebrew/Caskroom/miniforge/base/envs/MLME-22/lib/python3.9/configparser.py", line 434, in _interpolate_some
raise InterpolationMissingOptionError(
configparser.InterpolationMissingOptionError: Bad value substitution: option 'lib_name' in section 'DEFAULT' contains an interpolation key 'repo' which is not a valid option name. Raw value: '%(repo)s'

@cerkut
Copy link

cerkut commented Nov 14, 2022

Tried also installing nbdev with conda or pip, since this PR#1024 seems to be included in release 2.3.9 but still no success. These were in place of first input of the notebook, which installs nbdev 2.3.10. But none of them worked. Also inserted debug=True before name but still silent. What else could I try? Thanks.

@hamelsmu
Copy link
Author

hamelsmu commented Nov 14, 2022

Don't use the CLI, use the method I suggested in the blog post 😄 , I'm not certain that the CLI nbdev_export supports this.

@hamelsmu
Copy link
Author

Tried also installing nbdev with conda or pip, since this fastai/nbdev#1204 seems to be included in release 2.3.9 but still no success. These were in place of first input of the notebook, which installs nbdev 2.3.10. But none of them worked. Also inserted debug=True before name but still silent. What else could I try? Thanks.

Per the blog post, install from github pip install git+https://github.com/fastai/nbdev.git

@cerkut
Copy link

cerkut commented Nov 14, 2022

Thanks, CLI was a fallback, the method in your blog post runs in 0.3 secs, but no app.py in the folder (or nowhere else). Relative or absolute paths like lib_path='/Users/cer/vc/projects/hfds-size/' did not matter. Can't really figure out why it fails. In any case, thanks for the idea and blog post.

from nbdev.export import nb_export
nb_export('app.ipynb', lib_path='.', name='app') 

@hamelsmu
Copy link
Author

the method in your blog post runs in 0.3 secs, but no app.py in the folder

It's hard to debug this way, if you would like to provide a minimally reproducible example it might be easier. The code in a repo format is on HFhub incase that helps. https://huggingface.co/spaces/hamel/hfspace_demo/tree/main

@cerkut
Copy link

cerkut commented Nov 14, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment