Spaces:
Sleeping
Sleeping
File size: 906 Bytes
cd1b576 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#!/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[ ]:
|