Spaces:
Running
Running
Update start.sh
Browse files
start.sh
CHANGED
|
@@ -1,19 +1,49 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -euo pipefail
|
| 3 |
|
| 4 |
-
|
| 5 |
-
mkdir -p "$
|
| 6 |
|
| 7 |
if [ -z "${WEIGHTS_URL_TAR_GZ:-}" ]; then
|
| 8 |
-
echo "ERROR: Set WEIGHTS_URL_TAR_GZ
|
| 9 |
exit 1
|
| 10 |
fi
|
| 11 |
|
| 12 |
echo "[start] downloading model tarball…"
|
| 13 |
-
curl -L "$WEIGHTS_URL_TAR_GZ" -o /tmp/
|
| 14 |
|
| 15 |
-
echo "[start] extracting…"
|
| 16 |
-
tar -xzf /tmp/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
echo "[start] launching API…"
|
| 19 |
exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -euo pipefail
|
| 3 |
|
| 4 |
+
MODEL_ROOT="/app/bert_tf"
|
| 5 |
+
mkdir -p "$MODEL_ROOT"
|
| 6 |
|
| 7 |
if [ -z "${WEIGHTS_URL_TAR_GZ:-}" ]; then
|
| 8 |
+
echo "ERROR: Set WEIGHTS_URL_TAR_GZ (direct .tar.gz link) in Settings → Variables."
|
| 9 |
exit 1
|
| 10 |
fi
|
| 11 |
|
| 12 |
echo "[start] downloading model tarball…"
|
| 13 |
+
curl -L "$WEIGHTS_URL_TAR_GZ" -o /tmp/model.tar.gz
|
| 14 |
|
| 15 |
+
echo "[start] extracting to $MODEL_ROOT…"
|
| 16 |
+
tar -xzf /tmp/model.tar.gz -C "$MODEL_ROOT"
|
| 17 |
+
|
| 18 |
+
# --- normalize layout ---
|
| 19 |
+
# If there is a single subfolder and it has vocab.txt, use it as model dir
|
| 20 |
+
SUB="$(find "$MODEL_ROOT" -mindepth 1 -maxdepth 1 -type d | head -n 1 || true)"
|
| 21 |
+
if [ -n "${SUB:-}" ] && [ -f "$SUB/vocab.txt" ]; then
|
| 22 |
+
export MODEL_DIR="$SUB"
|
| 23 |
+
else
|
| 24 |
+
export MODEL_DIR="$MODEL_ROOT"
|
| 25 |
+
fi
|
| 26 |
+
|
| 27 |
+
# Pull vocab up if it's inside a 'vocab' folder
|
| 28 |
+
if [ -d "$MODEL_DIR/vocab" ] && [ -f "$MODEL_DIR/vocab/vocab.txt" ]; then
|
| 29 |
+
mv "$MODEL_DIR/vocab/vocab.txt" "$MODEL_DIR/vocab.txt"
|
| 30 |
+
fi
|
| 31 |
+
|
| 32 |
+
# Some dumps have checkpoint.txt → rename to checkpoint
|
| 33 |
+
[ -f "$MODEL_DIR/checkpoint.txt" ] && mv "$MODEL_DIR/checkpoint.txt" "$MODEL_DIR/checkpoint"
|
| 34 |
+
|
| 35 |
+
# Some dumps have bert_config.json → duplicate to config.json
|
| 36 |
+
[ -f "$MODEL_DIR/bert_config.json" ] && cp "$MODEL_DIR/bert_config.json" "$MODEL_DIR/config.json"
|
| 37 |
+
|
| 38 |
+
echo "[debug] contents of MODEL_DIR=$MODEL_DIR"
|
| 39 |
+
ls -l "$MODEL_DIR" | sed 's/^/[debug] /'
|
| 40 |
+
|
| 41 |
+
# sanity check
|
| 42 |
+
for f in vocab.txt config.json checkpoint model.ckpt-150000.index model.ckpt-150000.data-00000-of-00001; do
|
| 43 |
+
if [ ! -f "$MODEL_DIR/$f" ]; then
|
| 44 |
+
echo "[fatal] missing $f in $MODEL_DIR"; exit 2
|
| 45 |
+
fi
|
| 46 |
+
done
|
| 47 |
|
| 48 |
echo "[start] launching API…"
|
| 49 |
exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
|