File size: 608 Bytes
c87c295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert.preprocessors.execute import CellExecutionError

nb = nbformat.v4.new_notebook()

# Add a cell with your code
code_cell = nbformat.v4.new_code_cell(source=f'import os\nprint(os.getcwd())')
nb.cells.append(code_cell)

# Execute the notebook
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
output_str, error_str = None, None

ep.preprocess(nb)
if nb.cells[0].outputs:  # Check if there are any outputs
    output = nb.cells[-1].outputs[0]

print(output)
# Repo path :: /home/seungyoun/llama_code_interpreter\n