intial commit (forked from private repo)
This commit is contained in:
22
extract_cells.py
Normal file
22
extract_cells.py
Normal file
@ -0,0 +1,22 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def extractToFiles(filePath: str, folder: str = "extracted_cells"):
|
||||
with open(filePath, "r") as file:
|
||||
fileContent = file.read()
|
||||
content = json.loads(fileContent)
|
||||
i=0
|
||||
for cell in content["cells"]:
|
||||
if cell["cell_type"] == "code":
|
||||
codeStr = ""
|
||||
for line in cell["source"]:
|
||||
codeStr += line
|
||||
Path(folder).mkdir(parents=True, exist_ok=True)
|
||||
location = os.path.join(folder, f"cell{i}.py")
|
||||
with open(location, "w+") as file:
|
||||
file.write(codeStr)
|
||||
i += 1
|
||||
|
||||
|
||||
extractToFiles("Explainable_AI_Adult_Census_Income.ipynb")
|
||||
Reference in New Issue
Block a user