CoolFace
Apppublic

ek-developers/my-ocr-api

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
start.sh56 linesDownload Raw Back to root
1#!/bin/bash2set -e3 4# ── Ollama tuning for free HuggingFace tier (2 vCPU, 16GB RAM) ───5# export OLLAMA_NUM_PARALLEL=1          # only 1 request at a time — saves RAM6# export OLLAMA_MAX_LOADED_MODELS=1     # only keep 1 model in RAM7# export OLLAMA_KEEP_ALIVE=20m          # keep model loaded for 20 min8# export OLLAMA_MAX_QUEUE=4             # queue up to 4 requests, reject rest9# export OLLAMA_FLASH_ATTENTION=0       # disable — not supported on this CPU10# export OLLAMA_NOHISTORY=1             # no chat history — saves memory11 12echo "Installing Ollama..."13curl -fsSL https://ollama.com/install.sh | sh14 15echo "Starting Ollama..."16ollama serve &17OLLAMA_PID=$!18 19# Wait for Ollama to be ready20echo "Waiting for Ollama..."21for i in $(seq 1 30); do22    if curl -s http://localhost:11434/ > /dev/null 2>&1; then23        echo "Ollama ready."24        break25    fi26    sleep 127done28 29# Pull model — uses cache if already downloaded30echo "Pulling deepseek-ocr..."31# ollama pull deepseek-ocr32ollama list | grep -q deepseek-ocr || ollama pull deepseek-ocr33 34# Pre-load model into RAM with the exact options we'll use in production35# This means the first real user request won't wait for the 8s load time36echo "Pre-loading model into RAM..."37curl -s -X POST http://localhost:11434/api/generate \38    -H "Content-Type: application/json" \39    -d '{40        "model":      "deepseek-ocr",41        "prompt":     "ready",42        "stream":     false,43        "keep_alive": "20m",44        "options": {45            "temperature": 0,46            "num_predict": 1,47            "num_thread":  2,48            "num_ctx":     512,49            "num_batch":   128,50        }51    }' > /dev/null52 53echo "Model loaded and warm. Starting API..."54 55# Start FastAPI56exec uvicorn app:app --host 0.0.0.0 --port 7860 --workers 1