#!/bin/bash # Start Ollama server in the background # We bind it to port 11434 as expected by HF Spaces OLLAMA_HOST=0.0.0.0:11434 ollama serve & # Wait for the server to be ready until curl -s localhost:11434/api/tags > /dev/null; do echo "Waiting for Ollama server..." sleep 2 done # Pull the cloud model using the secret environment variable # HF automatically injects your secret as an ENV variable if [ -n "$OLLAMA_API_KEY" ]; then echo "Authenticating and pulling cloud model..." ollama pull gpt-oss:120b-cloud ollama pull deepseek-v3.2:cloud ollama pull gemini-3-flash-preview:cloud ollama pull minimax-m2.7:cloud ollama pull gemma4:31b-cloud ollama pull digitsflow/bonsai-8b else echo "Error: OLLAMA_API_KEY secret not found in Space settings." fi export ACCESS_TOKEN=${ACCESS_TOKEN} export OLLAMA_API_KEY=${OLLAMA_API_KEY} ollama signin ollama ls envsubst '${ACCESS_TOKEN}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf echo "Starting Nginx Reverse Proxy..." nginx -g "daemon on;" echo "------------------------------------------------------" echo "READY: Port 7860 is now active" echo "------------------------------------------------------" wait -n