Skip to content

Commit 60f0050

Browse files
committed
fixed last ipynb
1 parent 52089d2 commit 60f0050

File tree

9 files changed

+1417
-3007
lines changed

9 files changed

+1417
-3007
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ tests/
33
.vscode/
44
.idea/
55

6-
secrets/
6+
secrets/
7+
8+
c_11_neural_networks_2/data
9+
c_11_neural_networks_2/logs

auto_build/BUILD.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,29 @@
44
from auto_build.build_site import build_site
55

66
do_ppt = 0
7+
run_ipynb = 0
78
is_convert_ipynb_to_html = 1
89

910
main_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
1011
dir_list = [
11-
"c_01_intro_to_CV_and_Python",
12-
"c_02a_basic_image_processing",
13-
"c_02b_filtering_and_resampling",
14-
"c_03_edge_detection",
15-
"c_04a_curve_fitting",
16-
"c_04b_hough_transform",
12+
# "c_01_intro_to_CV_and_Python",
13+
# "c_02a_basic_image_processing",
14+
# "c_02b_filtering_and_resampling",
15+
# "c_03_edge_detection",
16+
# "c_04a_curve_fitting",
17+
# "c_04b_hough_transform",
1718
# "c_05_image_formation",
1819
# "c_06_geometric_transformation",
1920
# "c_07_camera_calibration",
2021
# "c_08_features",
2122
# "c_09_stereo",
22-
# "c_10_neural_networks_basics",
23-
# "c_11_neural_networks_2",
23+
"c_10_neural_networks_basics",
24+
"c_11_neural_networks_2",
2425
]
2526

2627

2728
dir_list = [os.path.join(main_path, dir_i) for dir_i in dir_list]
2829

29-
file_converter.run_on_class_dir_list(dir_list, do_ppt=do_ppt)
30+
file_converter.run_on_class_dir_list(dir_list, do_ppt, run_ipynb)
3031

3132
build_site(dir_list, is_convert_ipynb_to_html)

auto_build/build_site.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def build_site(dirs, is_convert_ipynb_to_html):
5353
# === get shorten path
5454
bigimg_path_pages = (
5555
os.sep + "pages" + bigimg_path_pages.split("pages")[1]
56-
)
56+
).replace("\\", "/")
5757

5858
# === run on all metadata files
5959
for meta_file in os.listdir(fp):
@@ -78,10 +78,10 @@ def build_site(dirs, is_convert_ipynb_to_html):
7878
with open(main_toc_fp, "a+") as f:
7979
f.write(meta_file_data + "\n\n")
8080
url_toc = (
81-
os.sep
81+
"/"
8282
+ "pages"
83-
+ meta_file_pages_path.split("pages")[1][:-3]
84-
+ os.sep
83+
+ meta_file_pages_path.replace("\\", "/").split("pages")[1][:-3]
84+
+ "/"
8585
)
8686

8787
# ==== update readme
@@ -102,8 +102,10 @@ def build_site(dirs, is_convert_ipynb_to_html):
102102
if not fn.endswith(".pdf"):
103103
continue
104104
pdf_path_online = os.path.join(
105-
"https://www.aiismath.com/pages", pages_dir_path.split("/pages/")[1], fn
106-
)
105+
"https://www.aiismath.com/pages",
106+
pages_dir_path.split("\\pages\\")[1],
107+
fn,
108+
).replace("\\", "/")
107109

108110
with open(os.path.join(pages_dir_path, "class_slides.html"), "w") as f:
109111
bigimg_path_pages_fixed = bigimg_path_pages
@@ -136,6 +138,22 @@ def build_site(dirs, is_convert_ipynb_to_html):
136138
)
137139

138140
# ==== convert ipynb to html
141+
import nbformat
142+
143+
# Read the original notebook
144+
with open(ipynb_fp, "r", encoding="utf-8") as f:
145+
nb = nbformat.read(f, as_version=4)
146+
147+
# Remove the widgets metadata if it exists
148+
if "widgets" in nb["metadata"]:
149+
del nb["metadata"]["widgets"]
150+
151+
# Write the modified notebook
152+
with open(ipynb_fp, "w", encoding="utf-8") as f:
153+
nbformat.write(nb, f)
154+
155+
print(f"Fixed notebook saved to {ipynb_fp}")
156+
139157
os.system(
140158
"jupyter nbconvert --ExecutePreprocessor.timeout=60 --template basic --to html "
141159
+ ipynb_fp
@@ -185,7 +203,7 @@ def build_site(dirs, is_convert_ipynb_to_html):
185203
header_builder(
186204
title,
187205
subtitle,
188-
bigimg_path_pages,
206+
bigimg_path_pages_fixed,
189207
layout="notebook",
190208
)
191209
)

auto_build/file_converter.py

+7-21
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,13 @@
44
from ppt2pdf import PPTtoPDF
55

66

7-
def run_on_all_classes(do_ppt=1):
8-
# ==== get all git class dirs - starting with "c_"
9-
cwd = os.getcwd()
10-
git_main_dirs_cwd = os.path.abspath(os.path.join(cwd, ".."))
11-
git_class_subdirs = [x for x in os.listdir(git_main_dirs_cwd) if x.startswith("c_")]
12-
13-
for dir_name in git_class_subdirs:
14-
fp = os.path.join(git_main_dirs_cwd, dir_name)
15-
run_on_one_class_dir(fp, do_ppt=do_ppt)
16-
17-
18-
def run_on_class_dir_list(dir_list, do_ppt=1):
7+
def run_on_class_dir_list(dir_list, do_ppt=1, run_ipynb=1):
198
for fp in dir_list:
20-
run_on_one_class_dir(fp, do_ppt=do_ppt)
9+
print("\n===== IN DIR: " + fp + " =====\n")
2110

11+
run_on_one_dir(fp, do_ppt, run_ipynb)
2212

23-
def run_on_one_class_dir(fp, do_ppt=1):
24-
print("\n===== IN DIR: " + fp + " =====\n")
25-
26-
run_on_one_dir(fp, do_ppt=do_ppt)
27-
28-
build_ex_dir(fp)
13+
build_ex_dir(fp)
2914

3015

3116
def build_ex_dir(fp):
@@ -45,7 +30,7 @@ def build_ex_dir(fp):
4530
myzip.write(os.path.join(fp_ex, f), f)
4631

4732

48-
def run_on_one_dir(fp: str, do_ppt=1):
33+
def run_on_one_dir(fp: str, do_ppt, run_ipynb):
4934
# ==== run on all files
5035
for fn in os.listdir(fp):
5136
fn_no_ext = fn.split(".")[0]
@@ -63,7 +48,8 @@ def run_on_one_dir(fp: str, do_ppt=1):
6348
PPTtoPDF(os.path.join(fp, fn), os.path.join(docs_fp, fn_no_ext + ".pdf"))
6449

6550
# === ipynb
66-
elif fn.endswith(".ipynb"):
51+
52+
elif fn.endswith(".ipynb") and run_ipynb:
6753
fp_ipynb = os.path.join(fp, fn)
6854
print("- executing .ipynb: " + fn + "\n")
6955
os.system(

0 commit comments

Comments
 (0)