Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·83 lines (72 loc) · 2.04 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·83 lines (72 loc) · 2.04 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
#!/usr/bin/env bash
# Start the local tiny-voca web interface.
#
# ./run.sh
#
# The first run creates app/.venv, installs the Python packages and downloads
# the model weights from Hugging Face. Later runs start in a second or two.
set -euo pipefail
cd "$(dirname "$0")"
VENV="app/.venv"
PYTHON="$VENV/bin/python"
install_packages() {
echo "Installing the Python packages…"
if command -v uv >/dev/null 2>&1; then
uv pip install --python "$PYTHON" -r app/requirements.txt
else
"$PYTHON" -m pip install -r app/requirements.txt
fi
}
if [ ! -x "$PYTHON" ]; then
echo "Creating a Python environment…"
if command -v uv >/dev/null 2>&1; then
uv venv --python 3.12 "$VENV"
else
python3 -m venv "$VENV"
"$PYTHON" -m pip install --upgrade pip
fi
install_packages
fi
if ! "$PYTHON" -c "import fastapi, uvicorn, dizione, soundfile, onnxruntime" >/dev/null 2>&1; then
install_packages
fi
if [ ! -f weights/tiny-voca.pt ] || [ ! -f weights/phonemizer/lexicon.tsv ]; then
echo "Downloading the model weights (about 40 MB)…"
"$PYTHON" - <<'PY'
from huggingface_hub import snapshot_download
snapshot_download("n4ze3m/tiny-voca", local_dir="weights")
PY
fi
HOST="${TINY_VOCA_HOST:-127.0.0.1}"
PORT="${TINY_VOCA_PORT:-8000}"
BROWSER_HOST="$HOST"
if [ "$HOST" = "0.0.0.0" ]; then
BROWSER_HOST="127.0.0.1"
fi
URL="http://$BROWSER_HOST:$PORT"
open_browser() {
if command -v open >/dev/null 2>&1; then
open "$1" >/dev/null 2>&1 || true
elif command -v xdg-open >/dev/null 2>&1; then
xdg-open "$1" >/dev/null 2>&1 || true
fi
}
if [ "${TINY_VOCA_NO_OPEN:-0}" != "1" ]; then
(
for _ in $(seq 1 120); do
if curl -fsS "http://$BROWSER_HOST:$PORT/health" >/dev/null 2>&1; then
open_browser "$URL"
break
fi
sleep 0.5
done
) &
fi
echo
echo " tiny-voca is starting at $URL"
if [ "$HOST" = "0.0.0.0" ]; then
echo " Reachable from other devices at http://<this-machine-ip>:$PORT"
fi
echo " Press Ctrl+C to stop."
echo
exec "$PYTHON" -m uvicorn app.server:app --host "$HOST" --port "$PORT"