4NK d6a61e7cbe chandra: document and script local HuggingFace install (hf extra, run-chandra-hf)
- Add install-local-hf.sh (uv sync --extra hf or pip install -e .[hf])
- Add run-chandra-hf.sh defaulting to --method hf
- Expand .env.example for upstream/local.env (MODEL_CHECKPOINT, TORCH_*)
2026-04-03 22:28:20 +02:00

2.8 KiB
Raw Blame History

Chandra OCR (amont)

Chandra OCR 2 convertit images et PDF en Markdown, HTML ou JSON en conservant la mise en page (tableaux, formulaires, écriture manuscrite, math). Code sous Apache-2.0 ; les poids du modèle suivent une licence dédiée (MODEL_LICENSE dans upstream/) — voir le dépôt amont.

Ce répertoire services/chandra/ contient :

  • upstream/ : sous-module Git vers datalab-to/chandra.
  • install-local-hf.sh : installe les dépendances Hugging Face (Torch, Transformers, etc.) dans upstream/.venv.
  • run-chandra-hf.sh : lance la CLI avec --method hf (inférence locale).
  • run-chandra.sh : lance chandra tel quel (passer --method vllm ou hf).
  • .env.example : variables pour upstream/local.env (modèle, GPU, tokens).

Configuration locale (Hugging Face)

Une fois le sous-module présent :

cd services/chandra
./install-local-hf.sh
cp .env.example upstream/local.env
# Éditer upstream/local.env si besoin (TORCH_DEVICE, MAX_OUTPUT_TOKENS, HF_TOKEN).
  • GPU : laisser TORCH_DEVICE vide pour device_map="auto" (comportement amont), ou fixer par ex. TORCH_DEVICE=cuda:0.
  • CPU : possible mais lent ; indiquer TORCH_DEVICE=cpu.
  • Le modèle MODEL_CHECKPOINT est téléchargé depuis Hugging Face au premier run (connexion requise ; espace disque important).

Lamont recommande flash-attention pour de meilleures perfs GPU ; après installation, TORCH_ATTN=flash_attention_2 dans local.env.

Usage (HF local)

cd services/chandra
./run-chandra-hf.sh /chemin/document.pdf ./sortie_ocr
# répertoire dentrée :
./run-chandra-hf.sh /chemin/documents ./sortie_ocr

Équivalent : ./run-chandra.sh … --method hf.

Usage (vLLM, optionnel)

Si tu préfères un serveur vLLM plutôt que le chargement local du modèle :

cd services/chandra/upstream
uv sync
# puis démarrer chandra_vllm selon README amont
cd ..
./run-chandra.sh input.pdf ./output --method vllm

Rôle dans smart_ide

  • OCR / numérisation structurée pour pipelines documentaires, en amont de PageIndex (PageIndex) ou dAnythingLLM / docv.
  • Pas de service HTTP dans ce dépôt : exécution CLI (comme services/pageindex/).

Documentation : docs/repo/service-chandra.md, docs/features/chandra-ocr-documents.md.

Ressources amont

  • Dépôt : datalab-to/chandra
  • Paquet PyPI : chandra-ocr (alternative : pip install chandra-ocr[hf])