Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python | |
| # coding: utf-8 | |
| # In[ ]: | |
| pip install nbconvert nbformat | |
| # In[4]: | |
| import nbformat | |
| from nbconvert import PythonExporter | |
| def convert_ipynb_to_py(ipynb_file, py_file): | |
| # Load the notebook file | |
| with open(ipynb_file, 'r', encoding='utf-8') as f: | |
| notebook_content = nbformat.read(f, as_version=4) | |
| # Create a Python exporter | |
| python_exporter = PythonExporter() | |
| # Convert the notebook to Python code | |
| python_code, _ = python_exporter.from_notebook_node(notebook_content) | |
| # Save the generated Python code to a .py file | |
| with open(py_file, 'w', encoding='utf-8') as f: | |
| f.write(python_code) | |
| print(f"Conversion complete! {ipynb_file} has been converted to {py_file}.") | |
| # Example usage: | |
| convert_ipynb_to_py('highPassFilter.ipynb', 'huggingface/highPassFilter.py') | |
| # In[ ]: | |