indic-ocr / Dockerfile
Sidd2899's picture
Deploy Indic OCR Studio
460e003 verified
Raw History Blame Contribute Delete
1.82 kB
# Hugging Face Space (Docker SDK, GPU hardware). Built by HF from the files deploy_hf.sh uploads.
# Spaces run the container as uid 1000, so everything the app or install.sh writes is owned by that user.
FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive PIP_NO_CACHE_DIR=1
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates git wget libgl1 libglib2.0-0 fonts-dejavu-core \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -m -u 1000 user \
&& mkdir -p /repo /models /app && chown -R user /repo /models /app
# Ubuntu 22.04's python3.11 is a 3.11 release candidate that current torch can't import on; uv brings a full 3.11
COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /usr/local/bin/uv
USER user
ENV HOME=/home/user VIRTUAL_ENV=/home/user/venv PATH=/home/user/venv/bin:$PATH
RUN uv venv --python 3.11 $VIRTUAL_ENV # install.sh uses uv too when it finds it
COPY --chown=user requirements.txt /app/requirements.txt
RUN uv pip install -r /app/requirements.txt
RUN wget -q -O /models/RealESRGAN_x4plus.pth \
https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth
# model repo + its installer; HF_TOKEN is the Space secret, mounted only for this step (never in a layer).
# The build machine has no GPU, so install.sh would pick CPU torch: force the CUDA 12 wheels.
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
python -c "from huggingface_hub import snapshot_download as d; d('bodhan-ai/indic-ocr', local_dir='/repo', token=open('/run/secrets/HF_TOKEN').read().strip())" \
&& cd /repo && IDP_CUDA=cu124 bash install.sh
COPY --chown=user . /app
WORKDIR /app
ENV OCR_REPO=/repo OCR_ESRGAN_PATH=/models/RealESRGAN_x4plus.pth OCR_JOBS_DIR=/tmp
EXPOSE 7860
CMD ["bash", "start.sh"]