Spaces:
Sleeping
Sleeping
File size: 2,665 Bytes
23654e5 4e9938a 23654e5 4e9938a 23654e5 4e9938a 23654e5 b55f151 23654e5 d6a961e b08ba59 2ccb2e4 e60b22c 434e8da 2ccb2e4 434e8da 0a4e3e9 434e8da 0a4e3e9 434e8da 0a4e3e9 434e8da 0a4e3e9 18bfe26 2ccb2e4 23654e5 2ccb2e4 23654e5 b55f151 2ccb2e4 e70b2c2 23654e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# Hugging Face Spaces Dockerfile
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Install system dependencies including GDAL for contextily/maps
RUN apt-get update && apt-get install -y \
build-essential \
curl \
gdal-bin \
libgdal-dev \
python3-gdal \
&& rm -rf /var/lib/apt/lists/*
# Set GDAL environment variables
ENV GDAL_CONFIG=/usr/bin/gdal-config
ENV CPLUS_INCLUDE_PATH=/usr/include/gdal
ENV C_INCLUDE_PATH=/usr/include/gdal
# Copy requirements
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create data directory in a writable location for HF Spaces
# HF Spaces has persistent storage at /data
RUN mkdir -p /data && chmod 777 /data
# Create cache directory for Hugging Face models
RUN mkdir -p /data/.cache/huggingface && chmod -R 777 /data/.cache
# Create models directory for fine-tuned models
RUN mkdir -p /data/models/finetuned && chmod -R 777 /data/models
# Create model cache in container (not in /data) to save persistent storage
RUN mkdir -p /app/.cache && chmod -R 777 /app/.cache
# Create matplotlib config directory (prevent permission errors)
RUN mkdir -p /tmp/matplotlib && chmod 777 /tmp/matplotlib
ENV MPLCONFIGDIR=/tmp/matplotlib
# Pre-download models into container image to avoid using /data storage
ENV HF_HOME=/app/.cache/huggingface
# Download zero-shot models (for immediate analysis capability)
# These are loaded on first analysis, pre-downloading saves time and /data space
RUN python -c "from transformers import pipeline; \
print('Downloading BART-large-MNLI...'); \
pipeline('zero-shot-classification', model='facebook/bart-large-mnli', device=-1); \
print('Downloading DeBERTa-v3-base-MNLI...'); \
pipeline('zero-shot-classification', model='MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli', device=-1); \
print('Downloading DistilBART-MNLI...'); \
pipeline('zero-shot-classification', model='valhalla/distilbart-mnli-12-3', device=-1); \
print('All models downloaded successfully')" \
&& chmod -R 777 /app/.cache
# Hugging Face Spaces uses port 7860
EXPOSE 7860
# Set runtime environment variables
ENV FLASK_ENV=production
ENV PYTHONUNBUFFERED=1
ENV PORT=7860
ENV DATABASE_PATH=/data/app.db
# Keep model cache in container, only store database and fine-tuned models in /data
ENV HF_HOME=/app/.cache/huggingface
ENV HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:7860/login || exit 1
# Run the application
CMD ["python", "app_hf.py"]
|