OmniPar / Dockerfile
Sanket17's picture
updaded file
d865512
FROM python:3.9-slim
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /code
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
TRANSFORMERS_CACHE=/code/.cache \
HF_HOME=/code/.cache
# Create cache directories with proper permissions
RUN mkdir -p /code/.cache && chmod 777 /code/.cache
# Install Python dependencies first to leverage Docker cache
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Create a non-root user
RUN useradd -m -u 1000 user \
&& chown -R user:user /code
# Copy application code
COPY . .
RUN chown -R user:user /code
# Switch to non-root user
USER user
# Download and cache models during build
RUN python -c "from transformers import AutoProcessor, AutoModelForVisualQuestionAnswering; \
processor = AutoProcessor.from_pretrained('microsoft/OmniParser', trust_remote_code=True); \
model = AutoModelForVisualQuestionAnswering.from_pretrained('microsoft/OmniParser', trust_remote_code=True)"
# Run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]