No description
  • Python 65.2%
  • JavaScript 11%
  • Shell 10.5%
  • CSS 6.3%
  • HTML 6%
  • Other 1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-24 02:44:28 +00:00
ocr-output code 2026-09-24 02:44:28 +00:00
scripts code 2026-09-24 02:44:28 +00:00
server code 2026-09-24 02:44:28 +00:00
tests code 2026-09-24 02:44:28 +00:00
.dockerignore code 2026-09-24 02:44:28 +00:00
.env.example code 2026-09-24 02:44:28 +00:00
.gcloudignore code 2026-09-24 02:44:28 +00:00
.gitignore code 2026-09-24 02:44:28 +00:00
cloudbuild.yaml code 2026-09-24 02:44:28 +00:00
Dockerfile code 2026-09-24 02:44:28 +00:00
pytest.ini code 2026-09-24 02:44:28 +00:00
README.md first commit 2026-09-24 02:42:47 +00:00
requirements-dev.txt code 2026-09-24 02:44:28 +00:00

Mistral OCR API

FastAPI + Jinja2 templates · deployable to Google Cloud Run.

Uses mistral-ocr-latest (OCR 4.1).

Setup

cd ~/ocr-mistral-api
cp .env.example .env
# edit .env — set MISTRAL_API_KEY=...

That's it. Local dev loads .env automatically (python-dotenv). Cloud Run deploy passes the same file via --env-vars-file.

Local

pip install -r server/requirements.txt
cd server && uvicorn main:app --reload --port 8080

Cloud Run

chmod +x scripts/deploy-cloud-run.sh
./scripts/deploy-cloud-run.sh

Reads MISTRAL_API_KEY, MISTRAL_OCR_MODEL, and optional GEMINI_* from .env (strips PORT — Cloud Run sets that itself).

403 Forbidden in browser? Deploy succeeded but public access wasn't granted. A project Owner must run:

gcloud run services add-iam-policy-binding mistral-ocr-api \
  --region=europe-central2 --member=allUsers --role=roles/run.invoker

(Or grant you Cloud Run Admin / run.services.setIamPolicy.) Org policy may also block allUsers — check iam.allowedPolicyMemberDomains.

Build only (CI):

gcloud builds submit --config=cloudbuild.yaml
./scripts/deploy-cloud-run.sh

API

Method Path Description
GET / Upload UI
GET /health Readiness + model
POST /api/ocr OCR upload. After Mistral succeeds, Gemini fixes obvious typos (spellcheck in the JSON). Fail-soft if Gemini is down or unset. Form: spellcheck_enabled=true

Tests

pip install -r requirements-dev.txt
pytest -v

.env

Variable Required Default
MISTRAL_API_KEY yes —
MISTRAL_OCR_MODEL no mistral-ocr-latest
GEMINI_API_KEY no — (skips spellcheck if unset)
GEMINI_MODEL no gemini-2.5-flash
GEMINI_SPELLCHECK no 1 (0 to disable)
PORT local only 8080

Don't commit .env.