#!/bin/bash # Customs Compass entrypoint — starts Ollama in background, waits for it # to be ready, ensures the model is available, then launches Streamlit. set -e echo "==> Starting Ollama server in background…" ollama serve > /tmp/ollama.log 2>&1 & OLLAMA_PID=$! # Wait up to 60s for Ollama to accept connections echo "==> Waiting for Ollama to be ready…" for i in {1..60}; do if curl -sf http://localhost:11434/api/tags > /dev/null 2>&1; then echo "==> Ollama is ready (after ${i}s)." break fi sleep 1 done # Verify the model is present (it was pulled at build time, but double-check) if ! ollama list | grep -q "llama3.2:1b"; then echo "==> Pulling llama3.2:1b (this may take 1-2 minutes)…" ollama pull llama3.2:1b fi echo "==> Pre-warming the model so first user request is fast…" curl -sf -X POST http://localhost:11434/api/generate \ -H "Content-Type: application/json" \ -d '{"model":"llama3.2:1b","prompt":"hi","stream":false,"keep_alive":"15m"}' \ > /dev/null 2>&1 || true echo "==> Launching Streamlit on port ${PORT:-7860}…" exec streamlit run app.py \ --server.port="${PORT:-7860}" \ --server.address=0.0.0.0 \ --server.headless=true \ --browser.gatherUsageStats=false