verdicto-ml / Dockerfile
A-I-C-A's picture
Upload Dockerfile
dbd9bf5 verified
# Optimized Dockerfile for Hugging Face Spaces
FROM python:3.10-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Create cache directories with proper permissions
RUN mkdir -p /tmp/transformers_cache /tmp/huggingface /tmp/torch && \
chmod -R 777 /tmp/transformers_cache /tmp/huggingface /tmp/torch
# Copy requirements and install Python dependencies
COPY requirements.txt .
# Install dependencies in stages for better caching
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir \
fastapi==0.104.0 \
uvicorn[standard]==0.24.0 \
pydantic==2.5.0 \
python-multipart==0.0.6 \
python-dotenv==1.0.0 \
requests==2.31.0 \
googletrans==4.0.0rc1 \
langdetect==1.0.9 && \
pip install --no-cache-dir \
numpy==1.24.0 \
pandas==2.0.0 \
scikit-learn==1.3.0 && \
pip install --no-cache-dir \
torch==2.0.0 \
transformers==4.35.0 \
sentence-transformers==2.2.0
# Copy application code
COPY . .
# Expose port (Hugging Face Spaces uses 7860 by default)
EXPOSE 7860
# Set environment variables for cache directories
ENV PORT=7860
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
ENV HF_HOME=/tmp/huggingface
ENV TORCH_HOME=/tmp/torch
# Start the application
CMD ["python", "app.py"]