No description
- Python 65.2%
- JavaScript 11%
- Shell 10.5%
- CSS 6.3%
- HTML 6%
- Other 1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| ocr-output | ||
| scripts | ||
| server | ||
| tests | ||
| .dockerignore | ||
| .env.example | ||
| .gcloudignore | ||
| .gitignore | ||
| cloudbuild.yaml | ||
| Dockerfile | ||
| pytest.ini | ||
| README.md | ||
| requirements-dev.txt | ||
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.