Spaces:
Paused

File size: 3,258 Bytes
a2cfb1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ─────────────────────────────────────────────────────────────────────────────
# ONNX Grid Vision API β€” Docker Deployment Configuration
# ─────────────────────────────────────────────────────────────────────────────
# Deploys a FastAPI grid classification service that uses:
#   - patchright (Chromium browser automation)
#   - ONNX Runtime (image classification/segmentation)
#   - Pillow (image processing)
#
# Port: 7860
# ─────────────────────────────────────────────────────────────────────────────

FROM python:3.11-slim

# ── System dependencies for Chromium ────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
    libnss3 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libcups2 \
    libdrm2 \
    libxkbcommon0 \
    libxcomposite1 \
    libxdamage1 \
    libxfixes3 \
    libxrandr2 \
    libgbm1 \
    libpango-1.0-0 \
    libcairo2 \
    libasound2 \
    libatspi2.0-0 \
    libxshmfence1 \
    curl \
    libjpeg62-turbo \
    libpng16-16 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# ── Python dependencies ────────────────────────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# ── Install Chromium via patchright ────────────────────────────────────────
RUN patchright install chromium

# ── Copy application code ─────────────────────────────────────────────────
COPY app.py .
COPY browser_engine.py .
COPY grid_classifier.py .
COPY models/ ./models/

# ── Environment ────────────────────────────────────────────────────────────
ENV PYTHONUNBUFFERED=1
ENV PORT=7860

# ── Health check ───────────────────────────────────────────────────────────
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# ── Run ────────────────────────────────────────────────────────────────────
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]