Segmentation-lulc / Dockerfile
Vishalpainjane's picture
Add model with Git LFS
9beb225
FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /code
# Install system dependencies
# fonts-liberation is a good open-source substitute for common fonts like Arial/Times New Roman
# which helps Pillow/ImageFont find a font file.
# Install system dependencies, including Git and Git LFS
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
git-lfs \
&& git lfs install \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy the requirements file into the container at /code
COPY requirements.txt .
# FIX: Create a cache directory AND set its permissions to be world-writable (777).
# This ensures the runtime user (which may not be root) can write to it.
RUN mkdir .cache && chmod 777 .cache
ENV TORCH_HOME=/code/.cache
ENV HF_HOME=/code/.cache/huggingface
# Install Python dependencies
# We specify the CPU-only version of PyTorch for faster builds and smaller image size,
# which is ideal for standard Hugging Face Spaces hardware.
#
# FIX: Use --extra-index-url instead of --index-url.
# This tells pip to use the PyTorch repository as an *additional* source,
# while still allowing it to download other packages like 'gradio' from the default PyPI.
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
# Copy the rest of your application's code and assets into the container at /code
# This includes app.py, your .pth model, and your .jpg example images.
COPY . .
# Pull actual LFS files
RUN git lfs install && git lfs pull
# Command to run the application
# Gradio automatically listens on port 7860, which Hugging Face exposes.
CMD ["python", "app.py"]