-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBakefile
More file actions
140 lines (111 loc) · 4.69 KB
/
Copy pathBakefile
File metadata and controls
140 lines (111 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
VENDOR="vendor"
# If this folder does not exist, the build will still
# work, but the eSpeak engine in /pronounce will not function.
ESPEAK="$HOME/projects/exp/zkcnik-tts/dist"
build() {
setup
vendor
precache
}
setup() {
bun i
vendor
}
vendor() {
mkdir -p $VENDOR
echo "==> Copying prebuilt browser bundles"
cp node_modules/instant.page/instantpage.js $VENDOR/instant-page.js
cp node_modules/@jaames/iro/dist/iro.js $VENDOR/iro.js
cp node_modules/cronstrue/dist/cronstrue.js $VENDOR/cronstrue.js
cp node_modules/marked/lib/marked.umd.js $VENDOR/marked.js
cp node_modules/prettier/standalone.js $VENDOR/prettier.js
cp node_modules/prettier/plugins/babel.js $VENDOR/prettier-babel.js
cp node_modules/prettier/plugins/estree.js $VENDOR/prettier-estree.js
cp node_modules/prettier/plugins/postcss.js $VENDOR/prettier-postcss.js
cp node_modules/prettier/plugins/html.js $VENDOR/prettier-html.js
cp node_modules/prettier/plugins/markdown.js $VENDOR/prettier-markdown.js
cp node_modules/terser/dist/bundle.min.js $VENDOR/terser.js
cp node_modules/csso/dist/csso.js $VENDOR/csso.js
cp node_modules/html-minifier-terser/dist/htmlminifier.umd.bundle.min.js $VENDOR/html-minifier.js
cp -r node_modules/uuid/dist/esm-browser $VENDOR/uuid
cp node_modules/@huggingface/transformers/dist/ort-wasm-simd-threaded.jsep.mjs $VENDOR/
cp node_modules/@huggingface/transformers/dist/ort-wasm-simd-threaded.jsep.wasm $VENDOR/
if [ -d "$ESPEAK" ]; then
echo "==> Copying espeak wasm bundle"
mkdir -p $VENDOR/espeakng
cp $ESPEAK/espeak.js $ESPEAK/espeak.wasm $ESPEAK/espeak.data $VENDOR/espeakng/
fi
echo "==> Building other browser bundles"
bun build --target browser --format esm node_modules/@huggingface/transformers/dist/transformers.web.js --outfile $VENDOR/transformers.js >/dev/null
echo "==> Downloading image models"
# Keep this in sync with `dtype` in remove.html and translate.html
ONNX=model_quantized.onnx # q8, ~44MB
# Better models:
# ONNX=model_fp16.onnx # fp16, ~88MB
# ONNX=model.onnx # fp32, ~176MB
mkdir -p $VENDOR/models/briaai/RMBG-1.4/onnx
fetch https://huggingface.co/briaai/RMBG-1.4/resolve/main/config.json \
$VENDOR/models/briaai/RMBG-1.4/config.json
fetch "https://huggingface.co/briaai/RMBG-1.4/resolve/main/onnx/$ONNX" \
"$VENDOR/models/briaai/RMBG-1.4/onnx/$ONNX"
cat > $VENDOR/models/briaai/RMBG-1.4/preprocessor_config.json <<'EOF'
{
"feature_extractor_type": "ImageFeatureExtractor",
"do_normalize": true,
"do_pad": false,
"do_rescale": true,
"do_resize": true,
"image_mean": [0.5, 0.5, 0.5],
"image_std": [1, 1, 1],
"resample": 2,
"rescale_factor": 0.00392156862745098,
"size": { "width": 1024, "height": 1024 }
}
EOF
echo "==> Downloading translation models"
for model in Xenova/opus-mt-en-nl Xenova/opus-mt-nl-en; do
mkdir -p "$VENDOR/models/$model/onnx"
for file in config.json tokenizer.json tokenizer_config.json \
onnx/encoder_model_quantized.onnx \
onnx/decoder_model_merged_quantized.onnx; do
fetch "https://huggingface.co/$model/resolve/main/$file" \
"$VENDOR/models/$model/$file"
done
done
}
serve() {
waiter --dev
}
clean() {
rm -rf node_modules
rm -rf $VENDOR
}
precache() {
{
find . -maxdepth 1 -name "*.html"
find . -maxdepth 1 -name "*.css"
find . -maxdepth 1 -name "*.json"
find . -maxdepth 1 -name "*.js" ! -name "sw.js"
find ./$VENDOR -type f
} | sort > .listing.tmp
CACHE_HASH=$(xargs cat < .listing.tmp | openssl dgst -sha1 | awk '{print $NF}' | cut -c1-8)
{ printf " '/',\n"; sed "s|^\./|/|; s|.*| '&',|" .listing.tmp; } > .precache.tmp
awk -v hash="tools-${CACHE_HASH}" '
/^const CACHE_KEY = / { q=sprintf("%c", 39); print "const CACHE_KEY = " q hash q ";"; next }
/^const PRECACHE = \[/ { print; in_block=1; while ((getline line < ".precache.tmp") > 0) print line; next }
/^\];/ && in_block { in_block=0 }
!in_block { print }
' sw.js > .sw.tmp && mv .sw.tmp sw.js
rm .listing.tmp .precache.tmp
}
deploy() {
lift deploy
}
fetch() {
if [ -f "$2" ]; then
echo "Skipped $2"
else
curl -fL --progress-bar "$1" -o "$2"
fi
}