Skip to content

Commit aeca17b

Browse files
add html generation as makefile target
1 parent 19fe38a commit aeca17b

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
HTML_OUT_DIR := ~/code/py-lidbox.github.io
2+
EXAMPLE_DIRS := common-voice-small common-voice-augmenting common-voice-embeddings common-voice-angular-lstm
23

3-
.PHONY: common-voice-small common-voice-large common-voice-augmenting
4+
.PHONY: $(EXAMPLE_DIRS) index
45

5-
common-voice-small common-voice-large common-voice-augmenting:
6+
all: index $(EXAMPLE_DIRS)
7+
8+
$(EXAMPLE_DIRS):
69
@mkdir -pv $(HTML_OUT_DIR)/$@
710
@jupyter nbconvert --to html $@/main.ipynb --stdout > $(HTML_OUT_DIR)/$@/main.html
11+
@echo "wrote '$(HTML_OUT_DIR)/$@/main.html'"
12+
13+
index:
14+
@python3 md2html.py $(HTML_OUT_DIR)/index.html
15+
@echo "wrote '$(HTML_OUT_DIR)/index.html'"

index.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Example notebooks using `lidbox`
2+
3+
| Notebook as HTML | Description |
4+
|:---------------- |:----------- |
5+
| [`common-voice-small`](./common-voice-small/main.html) | Classifying 4 languages from the Mozilla Common Voice dataset |
6+
| [`common-voice-augmenting`](./common-voice-augmenting/main.html) | Repeating example 1 with speech data augmentation |
7+
| [`common-voice-embeddings`](./common-voice-embeddings/main.html) | Using the trained model from example 2 as a language vector extractor for a back-end classifier |
8+
| [`common-voice-angular-lstm`](./common-voice-angular-lstm/main.html) | Training a language vector model with a dedicated, angular proximity loss function to maximize distance between vectors from different languages |

index.template.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>lidbox examples</title>
8+
</head>
9+
10+
<body>
11+
$body
12+
</body>
13+
14+
</html>

md2html.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import argparse
2+
import string
3+
4+
import mistune
5+
6+
7+
def readf(path):
8+
with open(path) as f:
9+
return f.read()
10+
11+
12+
def main(outpath, template="./index.template.html", md_body="./index.md"):
13+
html_body = mistune.markdown(readf(md_body))
14+
html_full = string.Template(readf(template)).substitute(body=html_body)
15+
with open(outpath, "w") as out_f:
16+
print(html_full, file=out_f)
17+
18+
19+
if __name__ == "__main__":
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("outpath")
22+
23+
args = parser.parse_args()
24+
main(args.outpath)

0 commit comments

Comments
 (0)