Spaces:
Sleeping
Sleeping
| # Use an official Python runtime as a parent image | |
| FROM python:3.10-slim-bullseye | |
| # Set Python to use unbuffered mode | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PATH="/var/www/.local/bin:${PATH}" | |
| # Create a non-root user | |
| RUN useradd -m -u 1000 -U -s /bin/bash myuser | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| python3-pip python3-dev git && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Set the working directory in the container | |
| RUN mkdir /var/www | |
| ENV HOME=/var/www | |
| WORKDIR /var/www | |
| # Change ownership of /var/www to the non-root user | |
| RUN chown -R myuser:myuser /var/www | |
| # Switch to the non-root user | |
| USER myuser | |
| # Copy the current directory contents into the container at /var/www | |
| COPY --chown=myuser:myuser . /var/www | |
| # Install dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt && \ | |
| pip install --no-cache-dir transformers sentencepiece | |
| # Define tokenizer name | |
| ARG TOKENIZER_NAME=unsloth/Llama-3.3-70B-Instruct | |
| ENV TOKENIZER_NAME=${TOKENIZER_NAME} | |
| ARG APP_PORT=7860 | |
| ENV APP_PORT=${APP_PORT} | |
| # Download the tokenizer and store it in the image | |
| RUN python -c "from transformers import AutoTokenizer; \ | |
| AutoTokenizer.from_pretrained('${TOKENIZER_NAME}')" | |
| # Expose the port | |
| EXPOSE ${APP_PORT} | |
| # Run FastAPI app with Uvicorn | |
| CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port $APP_PORT"] | |