Spaces:
Sleeping
Sleeping
| # Use Python 3.9 slim as the base image | |
| FROM python:3.9-slim | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 \ | |
| DEBIAN_FRONTEND=noninteractive \ | |
| MPLCONFIGDIR=/tmp/.matplotlib \ | |
| XDG_CACHE_HOME=/tmp/.cache | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| git \ | |
| wget \ | |
| build-essential \ | |
| python3-dev \ | |
| cmake \ | |
| libopencv-dev \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender1 \ | |
| && apt-get clean && rm -rf /var/lib/apt/lists/* | |
| # Set the working directory | |
| WORKDIR /app | |
| # Install PyTorch CPU version | |
| RUN pip3 install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu | |
| # Install Python dependencies | |
| RUN pip3 install --no-cache-dir \ | |
| numpy \ | |
| pyyaml \ | |
| fastapi \ | |
| uvicorn \ | |
| python-multipart \ | |
| opencv-python-headless \ | |
| scipy \ | |
| pillow \ | |
| matplotlib==3.9.0 | |
| RUN pip3 install --no-cache-dir "omegaconf>=2.4.0.dev2" | |
| Run pip3 install --no-cache-dir "hydra-core==1.1.0" | |
| # Clone and install Detectron2 | |
| RUN git clone https://github.com/facebookresearch/detectron2.git && \ | |
| cd detectron2 && \ | |
| python setup.py build develop && \ | |
| cd .. && rm -rf detectron2/.git | |
| # Copy application files | |
| COPY ./app.py /app | |
| COPY ./mask_rcnn_config.yaml /app/ | |
| COPY ./model_final.pth /app/ | |
| # Create directory for uploads | |
| RUN mkdir -p /app/uploads && chmod -R 777 /app/uploads | |
| # Expose the application port | |
| EXPOSE 8000 | |
| # Set the command to run the FastAPI server | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |