Skip to content

Commit

Permalink
example.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ashesh-0 committed Apr 10, 2024
1 parent fb7a31e commit 2580655
Show file tree
Hide file tree
Showing 4 changed files with 1,102 additions and 0 deletions.
44 changes: 44 additions & 0 deletions denoisplit/notebooks/convert_to_ipynb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Taken from https://github.com/dlmbl/image_restoration/blob/07f7e3612e506902834d8e425b43398dad99f24f/pyscripts/convert-solution.py
"""
import argparse
from traitlets.config import Config
import nbformat as nbf
from nbconvert.preprocessors import TagRemovePreprocessor, ClearOutputPreprocessor
from nbconvert.exporters import NotebookExporter


def get_arg_parser():
parser = argparse.ArgumentParser()

parser.add_argument('input_file')
parser.add_argument('output_file')

return parser


def convert(input_file, output_file):
c = Config()
c.TagRemovePreprocessor.remove_cell_tags = ("solution",)
c.TagRemovePreprocessor.enabled = True
c.ClearOutputPreprocesser.enabled = True
c.NotebookExporter.preprocessors = [
"nbconvert.preprocessors.TagRemovePreprocessor",
"nbconvert.preprocessors.ClearOutputPreprocessor"
]

exporter = NotebookExporter(config=c)
exporter.register_preprocessor(TagRemovePreprocessor(config=c), True)
exporter.register_preprocessor(ClearOutputPreprocessor(), True)

output = NotebookExporter(config=c).from_filename(input_file)
with open(output_file, 'w') as f:
f.write(output[0])


if __name__ == "__main__":
parser = get_arg_parser()
args = parser.parse_args()

convert(args.input_file, args.output_file)
print(f'Converted {args.input_file} to {args.output_file}')
Loading

0 comments on commit 2580655

Please sign in to comment.