Chirag commited on
Commit
0c41250
·
1 Parent(s): 580ba54
Files changed (2) hide show
  1. app..sh +5 -0
  2. app.py +10 -16
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
- def run_notebook(notebook_path, timeout=600):
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
- # Set up the executor
10
- ep = ExecutePreprocessor(timeout=timeout, kernel_name="python3")
 
11
 
12
- # Execute the notebook
13
- ep.preprocess(notebook, {"metadata": {"path": "./"}})
14
 
15
- # Optionally, save the executed notebook
16
- with open("executed_" + notebook_path, "w", encoding="utf-8") as f:
17
- nbformat.write(notebook, f)
18
 
19
- print(f"Notebook '{notebook_path}' executed successfully.")
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")