prshntdxt's picture
Deploy Forest Segmentation API with LFS
c82cafe
raw
history blame
1.15 kB
# Use official Python runtime as base image
FROM python:3.11-slim
# Set working directory in container
WORKDIR /app
# Install system dependencies (OpenCV, HDF5 support)
RUN apt-get update && apt-get install -y \
libsm6 \
libxext6 \
libxrender-dev \
libhdf5-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements file
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY main.py .
COPY model.py .
COPY schemas.py .
COPY inference/ ./inference/
# Copy pre-trained model (use .keras format only)
COPY models/Forest_Segmentation_Best.keras ./models/
# Create logs directory
RUN mkdir -p logs
# Expose port (Hugging Face Spaces default)
EXPOSE 7860
# Set environment for production
ENV PYTHONUNBUFFERED=1
ENV PORT=7860
ENV HOST=0.0.0.0
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:7860/health')" || exit 1
# Run FastAPI application with uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]