felixbet commited on
Commit
ac7f7f1
·
verified ·
1 Parent(s): 5ab3ad8

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +18 -24
start.sh CHANGED
@@ -5,43 +5,37 @@ 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 ending with dl=1) 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" || { echo "[fatal] tar extract failed"; exit 2; }
17
 
18
- # --- normalize layout ---
19
- SUB="$(find "$MODEL_ROOT" -mindepth 1 -maxdepth 1 -type d | head -n 1 || true)"
20
- if [ -n "${SUB:-}" ] && [ -f "$SUB/vocab.txt" ]; then
21
- export MODEL_DIR="$SUB"
22
- else
23
- export MODEL_DIR="$MODEL_ROOT"
24
  fi
 
25
 
26
- # move vocab/vocab.txt up if needed
27
- if [ -d "$MODEL_DIR/vocab" ] && [ -f "$MODEL_DIR/vocab/vocab.txt" ]; then
28
- mv "$MODEL_DIR/vocab/vocab.txt" "$MODEL_DIR/vocab.txt"
29
- fi
30
-
31
- # rename checkpoint.txt → checkpoint
32
- [ -f "$MODEL_DIR/checkpoint.txt" ] && mv "$MODEL_DIR/checkpoint.txt" "$MODEL_DIR/checkpoint"
33
- # duplicate bert_config.json → config.json if needed
34
  [ -f "$MODEL_DIR/bert_config.json" ] && cp "$MODEL_DIR/bert_config.json" "$MODEL_DIR/config.json"
 
 
35
 
36
- echo "[debug] contents of MODEL_DIR=$MODEL_DIR"
37
  ls -l "$MODEL_DIR" | sed 's/^/[debug] /'
38
 
39
- # sanity check
40
- for f in vocab.txt config.json checkpoint model.ckpt-150000.index model.ckpt-150000.data-00000-of-00001; do
41
- if [ ! -f "$MODEL_DIR/$f" ]; then
42
- echo "[fatal] missing $f in $MODEL_DIR"; exit 3
43
- fi
44
  done
 
 
45
 
46
  echo "[start] launching API…"
47
  exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
 
5
  mkdir -p "$MODEL_ROOT"
6
 
7
  if [ -z "${WEIGHTS_URL_TAR_GZ:-}" ]; then
8
+ echo "[fatal] Set WEIGHTS_URL_TAR_GZ to a DIRECT .tar.gz link (Dropbox must end with dl=1)" >&2
9
  exit 1
10
  fi
11
 
12
+ echo "[start] downloading model…"
13
  curl -L "$WEIGHTS_URL_TAR_GZ" -o /tmp/model.tar.gz
14
 
15
+ echo "[start] extracting…"
16
+ tar -xzf /tmp/model.tar.gz -C "$MODEL_ROOT" || { echo "[fatal] extract failed"; exit 2; }
17
 
18
+ # ---- Find the directory that actually contains vocab.txt (handles any nesting) ----
19
+ FOUND="$(find "$MODEL_ROOT" -maxdepth 4 -type f -name 'vocab.txt' | head -n1 || true)"
20
+ if [ -z "$FOUND" ]; then
21
+ echo "[fatal] vocab.txt not found under $MODEL_ROOT"; ls -R "$MODEL_ROOT"; exit 3
 
 
22
  fi
23
+ export MODEL_DIR="$(dirname "$FOUND")"
24
 
25
+ # Normalize names expected by HF + TF
 
 
 
 
 
 
 
26
  [ -f "$MODEL_DIR/bert_config.json" ] && cp "$MODEL_DIR/bert_config.json" "$MODEL_DIR/config.json"
27
+ [ -d "$MODEL_DIR/vocab" ] && [ -f "$MODEL_DIR/vocab/vocab.txt" ] && mv "$MODEL_DIR/vocab/vocab.txt" "$MODEL_DIR/vocab.txt"
28
+ [ -f "$MODEL_DIR/checkpoint.txt" ] && mv "$MODEL_DIR/checkpoint.txt" "$MODEL_DIR/checkpoint"
29
 
30
+ echo "[debug] MODEL_DIR=$MODEL_DIR"
31
  ls -l "$MODEL_DIR" | sed 's/^/[debug] /'
32
 
33
+ # Basic sanity
34
+ for f in vocab.txt config.json checkpoint; do
35
+ [ -f "$MODEL_DIR/$f" ] || { echo "[fatal] missing $f"; exit 4; }
 
 
36
  done
37
+ if ! ls "$MODEL_DIR"/model.ckpt-*.index >/dev/null 2>&1; then echo "[fatal] missing ckpt index"; exit 5; fi
38
+ if ! ls "$MODEL_DIR"/model.ckpt-*.data-00000-of-00001 >/dev/null 2>&1; then echo "[fatal] missing ckpt data"; exit 6; fi
39
 
40
  echo "[start] launching API…"
41
  exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"