-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathentrypoint.sh
executable file
·86 lines (73 loc) · 2.23 KB
/
entrypoint.sh
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
#!/bin/bash
# Entrypoint for the LlavaVision CUDA container
MODEL_REPO=${MODEL_REPO:-"https://huggingface.co/mys/ggml_bakllava-1/resolve/main/"}
MODEL=${MODEL:-"ggml-model-q4_k.gguf"}
MMPROJ=${MMPROJ:-"mmproj-model-f16.gguf"}
NLG=${NLG:-"35"}
TS=${TS:-"100,0"} # For GPU-only, single GPU
TUNNEL=${TUNNEL:-"false"}
HOST=${HOST:-0.0.0.0}
PORT=${PORT:-5000}
GENERATE_CERTS=${GENERATE_CERTS:-"false"}
CERT_SUBJ=${CERT_SUBJ:-"/C=AU/ST=VIC/O=MyOrg, Inc./CN=llavavision.local"}
DEBUG=${DEBUG:-""} # set to '--debug' to enable debug mode
function startFlask() {
cd /app/llavavision || exit
# --key key.pem --cert cert.pem
flask run --host="$HOST" --port "$PORT" "$DEBUG" &
llavaVisionPid=$!
}
function startLlama() {
/app/llama/build/bin/server -m "/app/models/${MODEL}" --mmproj "/app/models/${MMPROJ}" -ngl "$NLG" -ts "$TS"
llamaPid=$!
}
function downloadModel() {
cd /app/models || exit
# download the models if they don't exist
if [ -f "$MODEL" ]; then
echo "Model exists"
else
aria2c --split=4 --always-resume=true --enable-http-pipelining=true --http-accept-gzip=true --max-connection-per-server=6 --auto-file-renaming=false "${MODEL_REPO}${MODEL}" --out "$MODEL"
fi
if [ -f "$MMPROJ" ]; then
echo "MMProj exists"
else
aria2c --split=4 --always-resume=true --enable-http-pipelining=true --http-accept-gzip=true --max-connection-per-server=6 --auto-file-renaming=false "${MODEL_REPO}${MMPROJ}" --out "$MMPROJ"
fi
}
function genCerts() {
if [ "$GENERATE_CERTS" == "true" ]; then
cd /app/llavavision || exit
# Check if dummy certs exist, if not, create them
if [ ! -f "cert.pem" ]; then
echo "Generating certs"
openssl req -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out cert.pem -keyout key.pem -subj "$CERT_SUBJ"
fi
else
echo "Not generating certs"
fi
}
function tunnel() {
if [ "$TUNNEL" == "true" ]; then
echo "Tunnelling enabled"
cd /app/llavavision || exit
#
npx localtunnel --local-https --allow_invalid_cert ---port "$PORT" &
tunnelPid=$!
else
echo "Tunnelling disabled"
return
fi
}
function cleanup() {
kill "$llavaVisionPid"
kill "$llamaPid"
kill "$tunnelPid"
}
trap cleanup EXIT
downloadModel
genCerts
startFlask
startLlama
tunnel
wait