def generate_notebooks(config, eval_dir, colab_dir): """Add a colab setup code cell and then save to colab_dir""" if not config['github_repo']: return # copy notebook fron eval_dir to colab_dir run_cmd(['rm -rf', colab_dir]) run_cmd(['cp -r', eval_dir, colab_dir]) notebooks = find_files('**/*.ipynb', colab_dir) for fn in notebooks: with open(fn, 'r') as f: notebook = nbformat.read(f, as_version=4) # Use Python3 as the kernel update_notebook_kernel(notebook, "python3", "Python 3") # Check if GPU is needed use_gpu = False for cell in notebook.cells: if cell.cell_type == 'code': if config['gpu_pattern'] in cell.source: use_gpu = True break if use_gpu: notebook['metadata'].update({"accelerator": "GPU"}) logging.info('Use GPU for ' + fn) # Update SVG image URLs if config['replace_svg_url']: update_svg_urls(notebook, config['replace_svg_url'], fn, colab_dir) insert_additional_installation(notebook, config) with open(fn, 'w') as f: f.write(nbformat.writes(notebook))
def generate_notebooks(self, eval_dir, colab_dir, tab): if not self._valid: return # copy notebook fron eval_dir to colab_dir utils.run_cmd(['rm -rf', colab_dir]) utils.run_cmd(['cp -r', eval_dir, colab_dir]) notebooks = utils.find_files('**/*.ipynb', colab_dir) for fn in notebooks: nb = notebook.read(fn) if not nb: continue # Use Python3 as the kernel update_notebook_kernel(nb, "python3", "Python 3") # Check if GPU is needed use_gpu = False for cell in nb.cells: if cell.cell_type == 'code': if self.config['gpu_pattern'] in cell.source: use_gpu = True break if use_gpu: nb['metadata'].update({"accelerator": "GPU"}) logging.info('Use GPU for ' + fn) # Update SVG image URLs if self.config['replace_svg_url']: _update_svg_urls(nb, self.config['replace_svg_url'], fn, colab_dir) insert_additional_installation(nb, self._libs[tab], self.config['libs_header']) with open(fn, 'w') as f: f.write(nbformat.writes(nb))
def deploy(self): if not self._valid: return repo = self._repo.get(self.config.tab, '') if not repo: return bash_fname = os.path.join(os.path.dirname(__file__), 'upload_github.sh') utils.run_cmd([ 'bash', bash_fname, self.config.slides_dir, repo, self.config.project['release'] ])
def generate_notebooks(config, eval_dir, sagemaker_dir): if not config['github_repo']: return # copy notebook fron eval_dir to colab_dir run_cmd(['rm -rf', sagemaker_dir]) run_cmd(['cp -r', eval_dir, sagemaker_dir]) notebooks = find_files('**/*.ipynb', sagemaker_dir) for fn in notebooks: with open(fn, 'r') as f: notebook = nbformat.read(f, as_version=4) update_notebook_kernel(notebook, config['kernel']) insert_additional_installation(notebook, config) with open(fn, 'w') as f: f.write(nbformat.writes(notebook))
def generate_notebooks(self, eval_dir, sagemaker_dir, tab): if not self._valid: return utils.run_cmd(['rm -rf', sagemaker_dir]) utils.run_cmd(['cp -r', eval_dir, sagemaker_dir]) notebooks = utils.find_files('**/*.ipynb', sagemaker_dir) for fn in notebooks: nb = notebook.read(fn) if not nb: continue colab.update_notebook_kernel(nb, self._kernel[tab]) colab.insert_additional_installation(nb, self._libs[tab], self.config['libs_header']) with open(fn, 'w') as f: f.write(nbformat.writes(nb))
def generate_notebooks(config, eval_dir, colab_dir): """Add a colab setup code cell and then save to colab_dir""" if not config['github_repo']: return # copy notebook fron eval_dir to colab_dir run_cmd(['rm -rf', colab_dir]) run_cmd(['cp -r', eval_dir, colab_dir]) notebooks = find_files('**/*.ipynb', colab_dir) for fn in notebooks: with open(fn, 'r') as f: notebook = nbformat.read(f, as_version=4) # Use Python3 as the kernel notebook['metadata'].update({"kernelspec": { "name": "python3", "display_name": "Python 3" }}) # Check if GPU is needed use_gpu = False for cell in notebook.cells: if cell.cell_type == 'code': if config['gpu_pattern'] in cell.source: use_gpu = True break if use_gpu: notebook['metadata'].update({"accelerator": "GPU"}) logging.info('Use GPU for '+fn) # Update SVG image URLs if config['replace_svg_url']: update_svg_urls(notebook, config['replace_svg_url'], fn, colab_dir) # Add additional libraries if config['libs']: cell = get_installation_cell(notebook, config['libs']) if cell: notebook.cells.insert(0, cell) if config['libs_header']: notebook.cells.insert( 0, nbformat.v4.new_markdown_cell(source=config['libs_header'])) with open(fn, 'w') as f: f.write(nbformat.writes(notebook))