Spaces:
Sleeping
Sleeping
Chirag
commited on
Commit
·
0c41250
1
Parent(s):
580ba54
Te
Browse files
app..sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
pip install -q nbconvert nbformat jupyter ipykernel lxml_html_clean
|
| 4 |
+
|
| 5 |
+
python app.py
|
app.py
CHANGED
|
@@ -1,23 +1,17 @@
|
|
| 1 |
import nbformat
|
| 2 |
from nbconvert.preprocessors import ExecutePreprocessor
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
# Load the notebook
|
| 6 |
-
with open(notebook_path, "r", encoding="utf-8") as f:
|
| 7 |
-
notebook = nbformat.read(f, as_version=4)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
ep.preprocess(
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
nbformat.write(notebook, f)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Example usage
|
| 22 |
-
if __name__ == "__main__":
|
| 23 |
-
run_notebook("app.ipynb")
|
|
|
|
| 1 |
import nbformat
|
| 2 |
from nbconvert.preprocessors import ExecutePreprocessor
|
| 3 |
+
import jupyter_client
|
| 4 |
|
| 5 |
+
print("Available kernels:", jupyter_client.kernelspec.find_kernel_specs())
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def run_notebook(path):
|
| 8 |
+
with open(path, "r", encoding="utf-8") as f:
|
| 9 |
+
nb = nbformat.read(f, as_version=4)
|
| 10 |
|
| 11 |
+
ep = ExecutePreprocessor(timeout=600, kernel_name="python3")
|
| 12 |
+
ep.preprocess(nb, {"metadata": {"path": "./"}})
|
| 13 |
|
| 14 |
+
with open("executed_" + path, "w", encoding="utf-8") as f:
|
| 15 |
+
nbformat.write(nb, f)
|
|
|
|
| 16 |
|
| 17 |
+
run_notebook("app.ipynb")
|
|
|
|
|
|
|
|
|
|
|
|