Spaces:
Running
Running
Create start.sh
Browse files
start.sh
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
export HF_HUB_DISABLE_TELEMETRY=1
|
| 5 |
+
MODEL_DIR="/app/bert_tf"
|
| 6 |
+
mkdir -p "$MODEL_DIR"
|
| 7 |
+
|
| 8 |
+
echo "[start] BioBERT bootstrap..."
|
| 9 |
+
|
| 10 |
+
if [ -d "$MODEL_DIR" ] && [ -f "$MODEL_DIR/vocab.txt" ] && [ -f "$MODEL_DIR/config.json" ]; then
|
| 11 |
+
echo "[start] Model files already present in repo. Skipping download."
|
| 12 |
+
else
|
| 13 |
+
if [ -n "${WEIGHTS_URL_TAR_GZ:-}" ]; then
|
| 14 |
+
# Single tar.gz containing the 5 files; supports Dropbox 'dl=1'
|
| 15 |
+
echo "[start] Downloading tarball from $WEIGHTS_URL_TAR_GZ"
|
| 16 |
+
curl -L "$WEIGHTS_URL_TAR_GZ" -o /tmp/bert_min.tar.gz
|
| 17 |
+
tar -xzf /tmp/bert_min.tar.gz -C "$MODEL_DIR"
|
| 18 |
+
elif [ -n "${WEIGHTS_BASE_URL:-}" ]; then
|
| 19 |
+
# Download files one by one from a base URL (must be direct links)
|
| 20 |
+
echo "[start] Downloading files from base $WEIGHTS_BASE_URL"
|
| 21 |
+
for f in checkpoint config.json vocab.txt model.ckpt-150000.index model.ckpt-150000.data-00000-of-00001 bert_config.json; do
|
| 22 |
+
echo " - $f"
|
| 23 |
+
curl -fL "${WEIGHTS_BASE_URL%/}/$f" -o "$MODEL_DIR/$f" || true
|
| 24 |
+
done
|
| 25 |
+
else
|
| 26 |
+
echo "[start] ERROR: No weights source provided. Set WEIGHTS_URL_TAR_GZ or WEIGHTS_BASE_URL."
|
| 27 |
+
exit 1
|
| 28 |
+
fi
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
# Ensure checkpoint file is correct
|
| 32 |
+
if [ ! -f "$MODEL_DIR/checkpoint" ]; then
|
| 33 |
+
echo 'model_checkpoint_path: "model.ckpt-150000"' > "$MODEL_DIR/checkpoint"
|
| 34 |
+
echo 'all_model_checkpoint_paths: "model.ckpt-150000"' >> "$MODEL_DIR/checkpoint"
|
| 35 |
+
fi
|
| 36 |
+
|
| 37 |
+
# Fallback: if only bert_config.json exists, duplicate to config.json
|
| 38 |
+
if [ ! -f "$MODEL_DIR/config.json" ] && [ -f "$MODEL_DIR/bert_config.json" ]; then
|
| 39 |
+
cp "$MODEL_DIR/bert_config.json" "$MODEL_DIR/config.json"
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
echo "[start] Launching API on :${PORT:-7860}"
|
| 43 |
+
exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"
|