curemind / docker-entrypoint.sh
Alishba Siddique
fix: lazy Pinecone init so FastAPI starts cleanly on HF Spaces
1689c36
Raw
History Blame Contribute Delete
1.09 kB
#!/bin/bash
set -e
echo "[CureMind] Starting FastAPI backend on port 8000..."
cd /home/user/app/server
uvicorn main:app --host 0.0.0.0 --port 8000 &
BACKEND_PID=$!
echo "[CureMind] Polling API health (max 90s)..."
READY=0
for i in $(seq 1 45); do
if python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" 2>/dev/null; then
echo "[CureMind] API is ready after ~$((i * 2))s."
READY=1
break
fi
if ! kill -0 $BACKEND_PID 2>/dev/null; then
echo "[ERROR] FastAPI process crashed. Check your API keys and Pinecone config in Space secrets."
exit 1
fi
echo "[CureMind] Waiting... ($i/45)"
sleep 2
done
if [ $READY -eq 0 ]; then
echo "[WARN] API did not respond in 90s — starting Streamlit anyway."
fi
echo "[CureMind] Starting Streamlit frontend on port 7860..."
export CUREMIND_API_URL=http://localhost:8000
cd /home/user/app/client
exec streamlit run app.py \
--server.port 7860 \
--server.address 0.0.0.0 \
--server.headless true \
--browser.gatherUsageStats false