Spaces:
Running
Running
Commit ·
7b97a14
1
Parent(s): 197a18e
fix: run model download and ML predictors in background so services start immediately
Browse files- docker-entrypoint.sh +82 -87
docker-entrypoint.sh
CHANGED
|
@@ -118,107 +118,102 @@ hf_download() {
|
|
| 118 |
fi
|
| 119 |
}
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
hf_download "starry-dist" "$model_path/.state.yaml"
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
hf_download "starry-dist" "$model_path/$sub/$sub_file"
|
| 158 |
fi
|
| 159 |
fi
|
| 160 |
-
|
| 161 |
-
|
| 162 |
fi
|
| 163 |
-
|
| 164 |
-
done
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
fi
|
| 183 |
-
done
|
| 184 |
-
fi
|
| 185 |
-
else
|
| 186 |
-
# Directory-based model (loc) — download .state.yaml and model file
|
| 187 |
-
hf_download "ocr-dist" "$config_path/.state.yaml"
|
| 188 |
-
state_yaml="$MODELS_BASE/ocr-dist/$config_path/.state.yaml"
|
| 189 |
-
if [ -f "$state_yaml" ]; then
|
| 190 |
-
model_file=$(sed -n 's/^file: *//p' "$state_yaml" | head -1)
|
| 191 |
-
if [ -n "$model_file" ]; then
|
| 192 |
-
hf_download "ocr-dist" "$config_path/$model_file"
|
| 193 |
fi
|
| 194 |
fi
|
| 195 |
fi
|
| 196 |
-
|
| 197 |
-
done
|
| 198 |
-
|
| 199 |
-
echo "Model download complete."
|
| 200 |
-
fi
|
| 201 |
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
export PREDICTOR_GAUGE="${PREDICTOR_GAUGE:-tcp://127.0.0.1:12023}"
|
| 205 |
-
export PREDICTOR_GAUGE_RENDERER="${PREDICTOR_GAUGE_RENDERER:-tcp://127.0.0.1:15656}"
|
| 206 |
-
export PREDICTOR_MASK="${PREDICTOR_MASK:-tcp://127.0.0.1:12024}"
|
| 207 |
-
export PREDICTOR_SEMANTIC="${PREDICTOR_SEMANTIC:-tcp://127.0.0.1:12025}"
|
| 208 |
-
export PREDICTOR_LOC="${PREDICTOR_LOC:-tcp://127.0.0.1:12026}"
|
| 209 |
-
export PREDICTOR_OCR="${PREDICTOR_OCR:-tcp://127.0.0.1:12027}"
|
| 210 |
-
export PREDICTOR_BRACKETS="${PREDICTOR_BRACKETS:-tcp://127.0.0.1:12028}"
|
| 211 |
|
| 212 |
-
#
|
| 213 |
-
if [ -f /home/node/app/supervisord.conf ] && [ -d /home/node/app/backend/python-services ]; then
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
fi
|
| 221 |
-
|
| 222 |
|
| 223 |
# ── Run database migrations ──
|
| 224 |
echo 'Running database migrations...'
|
|
|
|
| 118 |
fi
|
| 119 |
}
|
| 120 |
|
| 121 |
+
# ── Set predictor addresses (internal ZMQ) ──
|
| 122 |
+
export PREDICTOR_LAYOUT="${PREDICTOR_LAYOUT:-tcp://127.0.0.1:12022}"
|
| 123 |
+
export PREDICTOR_GAUGE="${PREDICTOR_GAUGE:-tcp://127.0.0.1:12023}"
|
| 124 |
+
export PREDICTOR_GAUGE_RENDERER="${PREDICTOR_GAUGE_RENDERER:-tcp://127.0.0.1:15656}"
|
| 125 |
+
export PREDICTOR_MASK="${PREDICTOR_MASK:-tcp://127.0.0.1:12024}"
|
| 126 |
+
export PREDICTOR_SEMANTIC="${PREDICTOR_SEMANTIC:-tcp://127.0.0.1:12025}"
|
| 127 |
+
export PREDICTOR_LOC="${PREDICTOR_LOC:-tcp://127.0.0.1:12026}"
|
| 128 |
+
export PREDICTOR_OCR="${PREDICTOR_OCR:-tcp://127.0.0.1:12027}"
|
| 129 |
+
export PREDICTOR_BRACKETS="${PREDICTOR_BRACKETS:-tcp://127.0.0.1:12028}"
|
| 130 |
|
| 131 |
+
# ── Download models & start ML predictors (background) ──
|
| 132 |
+
# Runs in background so Node services and nginx can start immediately.
|
| 133 |
+
(
|
| 134 |
+
if [ -n "$HF_TOKEN" ] && [ -f "$MODELS_YAML" ]; then
|
| 135 |
+
echo "Downloading model files from HuggingFace (background)..."
|
| 136 |
+
|
| 137 |
+
# Download bdtopo ONNX models
|
| 138 |
+
if [ -n "$BDTOPO_MODEL_PATH" ] && [ ! -f "$BDTOPO_MODEL_PATH" ]; then
|
| 139 |
+
_bdtopo_path=$(yaml_get bdtopo path)
|
| 140 |
+
_bdtopo_dir="$MODELS_BASE/starry-dist/$_bdtopo_path"
|
| 141 |
+
mkdir -p "$_bdtopo_dir"
|
| 142 |
+
|
| 143 |
+
sed -n '/^ files:/,/^[^ ]/{ /^ *- /p }' "$MODELS_YAML" | sed 's/^ *- *//' | while read -r FILE; do
|
| 144 |
+
hf_download "starry-dist" "$_bdtopo_path/$FILE"
|
| 145 |
+
done
|
| 146 |
+
fi
|
| 147 |
|
| 148 |
+
# Download PyTorch model directories (starry-dist)
|
| 149 |
+
for model_var in LAYOUT_MODEL_PATH MASK_MODEL_PATH SEMANTIC_MODEL_PATH GAUGE_MODEL_PATH; do
|
| 150 |
+
eval model_path=\$$model_var
|
| 151 |
+
if [ -n "$model_path" ]; then
|
| 152 |
+
hf_download "starry-dist" "$model_path/.state.yaml"
|
|
|
|
| 153 |
|
| 154 |
+
state_yaml="$MODELS_BASE/starry-dist/$model_path/.state.yaml"
|
| 155 |
+
if [ -f "$state_yaml" ]; then
|
| 156 |
+
model_file=$(sed -n 's/^file: *//p' "$state_yaml" | head -1)
|
| 157 |
+
if [ -n "$model_file" ]; then
|
| 158 |
+
hf_download "starry-dist" "$model_path/$model_file"
|
| 159 |
+
fi
|
| 160 |
+
sed -n '/^subs:/,/^[a-z]/{ /^ - /p }' "$state_yaml" | sed 's/^ *- *//' | while read -r sub; do
|
| 161 |
+
if [ -n "$sub" ]; then
|
| 162 |
+
hf_download "starry-dist" "$model_path/$sub/.state.yaml"
|
| 163 |
+
sub_state="$MODELS_BASE/starry-dist/$model_path/$sub/.state.yaml"
|
| 164 |
+
if [ -f "$sub_state" ]; then
|
| 165 |
+
sub_file=$(sed -n 's/^file: *//p' "$sub_state" | head -1)
|
| 166 |
+
if [ -n "$sub_file" ]; then
|
| 167 |
+
hf_download "starry-dist" "$model_path/$sub/$sub_file"
|
| 168 |
+
fi
|
|
|
|
| 169 |
fi
|
| 170 |
fi
|
| 171 |
+
done
|
| 172 |
+
fi
|
| 173 |
fi
|
| 174 |
+
done
|
|
|
|
| 175 |
|
| 176 |
+
# Download OCR/TF models (ocr-dist)
|
| 177 |
+
for config_var in LOC_MODEL_PATH OCR_CONFIG BRACKETS_CONFIG; do
|
| 178 |
+
eval config_path=\$$config_var
|
| 179 |
+
if [ -n "$config_path" ]; then
|
| 180 |
+
if echo "$config_path" | grep -q '\.yaml$\|\.yml$'; then
|
| 181 |
+
hf_download "ocr-dist" "$config_path"
|
| 182 |
+
config_file="$MODELS_BASE/ocr-dist/$config_path"
|
| 183 |
+
if [ -f "$config_file" ]; then
|
| 184 |
+
sed -n 's/^ *model_path: *//p' "$config_file" | while read -r mpath; do
|
| 185 |
+
if [ -n "$mpath" ]; then
|
| 186 |
+
_dir=$(dirname "$config_path")
|
| 187 |
+
hf_download "ocr-dist" "$_dir/$mpath"
|
| 188 |
+
fi
|
| 189 |
+
done
|
| 190 |
+
fi
|
| 191 |
+
else
|
| 192 |
+
hf_download "ocr-dist" "$config_path/.state.yaml"
|
| 193 |
+
state_yaml="$MODELS_BASE/ocr-dist/$config_path/.state.yaml"
|
| 194 |
+
if [ -f "$state_yaml" ]; then
|
| 195 |
+
model_file=$(sed -n 's/^file: *//p' "$state_yaml" | head -1)
|
| 196 |
+
if [ -n "$model_file" ]; then
|
| 197 |
+
hf_download "ocr-dist" "$config_path/$model_file"
|
| 198 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
fi
|
| 200 |
fi
|
| 201 |
fi
|
| 202 |
+
done
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
+
echo "Model download complete."
|
| 205 |
+
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
+
# Start ML predictors after models are downloaded
|
| 208 |
+
if [ -f /home/node/app/supervisord.conf ] && [ -d /home/node/app/backend/python-services ]; then
|
| 209 |
+
if [ -n "$LAYOUT_MODEL_PATH" ]; then
|
| 210 |
+
echo "Starting Python ML predictors via supervisord..."
|
| 211 |
+
supervisord -c /home/node/app/supervisord.conf
|
| 212 |
+
else
|
| 213 |
+
echo "Skipping ML predictors (no model paths configured)."
|
| 214 |
+
fi
|
| 215 |
fi
|
| 216 |
+
) &
|
| 217 |
|
| 218 |
# ── Run database migrations ──
|
| 219 |
echo 'Running database migrations...'
|