# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker FROM python:3.9 WORKDIR /code # Set up a new user named "user" with user ID 1000 RUN useradd -m -u 1000 user # Switch to the "user" user USER user # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory to the user's home directory WORKDIR $HOME/app # --- CHANGED: Install Micromamba instead of Miniconda --- # Micromamba is a single binary (C++) that uses significantly less RAM than Conda + Python USER root RUN set -ex; \ ARCH=$(uname -m); \ if [ "$ARCH" = "x86_64" ]; then \ URL="https://micro.mamba.pm/api/micromamba/linux-64/latest"; \ elif [ "$ARCH" = "aarch64" ]; then \ URL="https://micro.mamba.pm/api/micromamba/linux-aarch64/latest"; \ else \ echo "Unsupported architecture: $ARCH"; exit 1; \ fi; \ # Install curl/tar if missing (python:3.9 usually has them, but good practice) apt-get update && apt-get install -y curl tar bzip2 && rm -rf /var/lib/apt/lists/*; \ # Download and extract binary to /bin/micromamba curl -Ls "$URL" | tar -xvj -C /usr/local/bin/ --strip-components=1 bin/micromamba; \ # Ensure it's executable chmod +x /usr/local/bin/micromamba # Switch back to user USER user # Configure Micromamba root location ENV MAMBA_ROOT_PREFIX=/home/user/micromamba # Clone the repo RUN git clone https://github.com/squaresLab/idioms # --- CHANGED: Create environment using Micromamba --- # Note: We removed 'conda tos accept' because Micromamba handles this differently/implicitly # We use 'create' to make the env named 'idioms' RUN micromamba create -y -n idioms -f idioms/env.yml && \ micromamba clean --all --yes # --- CHANGED: Update PATH to point to Micromamba env --- # Micromamba puts envs in $MAMBA_ROOT_PREFIX/envs ENV PATH="${MAMBA_ROOT_PREFIX}/envs/idioms/bin:${PATH}" ENV PYTHONPATH="${PYTHONPATH}:${HOME}/app/idioms" # Install the gradio app's requirements too COPY ./requirements.txt /code/requirements.txt RUN which pip RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # Copy the current directory contents into the container at $HOME/app setting the owner to the user COPY --chown=user . $HOME/app # Disable buffering to allow logging of standard output. ENV PYTHONUNBUFFERED=1 # Copy everything to stderr because huggingface spaces is annoying. CMD python main.py