Integrate FastAI colorization with Firebase auth and Gradio UI - Replace main.py with FastAI implementation - Add Gradio interface for Space UI - Add Firebase authentication to /colorize endpoint - Add curl examples documentation - Update test.py with User-Agent headers
e4599d1
| FROM python:3.10-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| libgomp1 \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements first for better caching | |
| COPY requirements.txt . | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application code | |
| COPY . . | |
| # Create directories for uploads and results | |
| # Note: /data is already writable in Hugging Face Spaces, no chmod needed | |
| RUN mkdir -p /data/uploads /data/results | |
| # Handle Firebase credentials from environment variable (for Hugging Face Spaces secrets) | |
| # This allows the credentials to be passed as a secret and written to file at runtime | |
| # Note: Python code will create /data/hf_cache with proper permissions | |
| # Make Firebase credentials writing non-fatal (use || true to continue on error) | |
| RUN echo '#!/bin/sh' > /entrypoint.sh && \ | |
| echo 'mkdir -p /tmp/colorize_uploads /tmp/colorize_results /tmp/hf_cache || true' >> /entrypoint.sh && \ | |
| echo 'if [ -n "$FIREBASE_CREDENTIALS" ]; then' >> /entrypoint.sh && \ | |
| echo ' printf "%s" "$FIREBASE_CREDENTIALS" > /tmp/firebase-adminsdk.json 2>/dev/null || true' >> /entrypoint.sh && \ | |
| echo 'fi' >> /entrypoint.sh && \ | |
| echo 'exec "$@"' >> /entrypoint.sh && \ | |
| chmod +x /entrypoint.sh | |
| # Expose port (Hugging Face Spaces uses port 7860) | |
| EXPOSE 7860 | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV BASE_URL=${SPACE_HOST} | |
| ENV PORT=7860 | |
| ENV DATA_DIR=/data | |
| ENV OMP_NUM_THREADS=1 | |
| ENV HF_HOME=/tmp/hf_cache | |
| ENV TRANSFORMERS_CACHE=/tmp/hf_cache | |
| ENV HUGGINGFACE_HUB_CACHE=/tmp/hf_cache | |
| ENV HF_HUB_CACHE=/tmp/hf_cache | |
| ENV XDG_CACHE_HOME=/tmp/hf_cache | |
| ENV MPLCONFIGDIR=/tmp/matplotlib_config | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
| CMD python -c "import requests; requests.get('http://localhost:7860/health', timeout=5)" || exit 1 | |
| # Set entrypoint | |
| ENTRYPOINT ["/entrypoint.sh"] | |
| # Run the application (port will be set via environment variable) | |
| CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860}"] |