File size: 4,593 Bytes
3517d32
a6cdaab
e3310d6
 
 
3517d32
 
 
 
 
 
aa15811
e3310d6
 
82cf28b
 
 
e3310d6
21c88c7
 
 
5150658
 
 
768a8d3
 
 
21c88c7
1eac1e9
 
 
e412b9c
e3310d6
8d4088c
 
 
 
a6cdaab
7ebd053
a6cdaab
 
 
 
21c88c7
 
 
 
 
 
 
 
 
a6cdaab
e3310d6
 
 
 
 
39c03a8
e3310d6
a6cdaab
3517d32
 
 
 
a6cdaab
 
82cf28b
21c88c7
 
 
 
 
 
 
 
e3310d6
 
21c88c7
 
1a4d163
867a67d
e3310d6
 
768a8d3
 
 
9800705
 
 
73d7d5f
300132c
 
 
 
21c88c7
 
 
5150658
 
 
21c88c7
e3310d6
a6cdaab
 
 
 
 
 
 
 
 
3517d32
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Restore full pre-retirement app + patch frontend + backend models + auto-continue V17 + auto-approve + document uploads
FROM node:20-alpine AS frontend-builder
RUN apk add --no-cache git python3
RUN git clone --depth 1 https://huggingface.co/spaces/smolagents/ml-intern /source

# Restore the pre-retirement full app (upstream retired it: App.tsx -> RetirementPage,
# backend/start.sh -> retired_main:app). This puts back the full UI + real backend
# BEFORE our model patches run, so they take effect again.
COPY patch_restore_full_app.py /tmp/patch_restore_full_app.py
RUN python3 /tmp/patch_restore_full_app.py

# Patch frontend: add OpenRouter models
COPY patch_frontend.py /tmp/patch_frontend.py
RUN python3 /tmp/patch_frontend.py
# Patch frontend: add stealth/space-bunny-alpha
COPY patch_space_bunny.py /tmp/patch_space_bunny.py
RUN python3 /tmp/patch_space_bunny.py

# Patch frontend: multi-format file uploads (PDF/images/Excel/Word/PPT/ODF/text)
COPY patch_frontend_uploads.py /tmp/patch_frontend_uploads.py
RUN python3 /tmp/patch_frontend_uploads.py
# Patch frontend: multi-file uploads (many images/files at once)
COPY patch_frontend_multi.py /tmp/patch_frontend_multi.py
RUN python3 /tmp/patch_frontend_multi.py
# Patch frontend: add 3 new OpenRouter models
COPY patch_frontend_new_models.py /tmp/patch_frontend_new_models.py
RUN python3 /tmp/patch_frontend_new_models.py

# Patch auto-continue V17
COPY patch_auto_continue_v17.py /tmp/patch_auto_continue_v17.py
RUN python3 /tmp/patch_auto_continue_v17.py

WORKDIR /source/frontend
RUN npm config set fetch-timeout 120000 && \
    npm config set fetch-retries 3 && \
    npm install && \
    npm run build

# Stage 2: Production
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN useradd -m -u 1000 user
WORKDIR /app
# System deps: git/curl/ca-certificates plus document parsing tools.
#   tesseract-ocr        -> OCR for image uploads (with eng + vie language packs)
#   libreoffice-writer + libreoffice-calc + libreoffice-impress
#                        -> legacy/OpenDocument formats (.xls, .doc, .odt, .ods, .odp, .rtf)
RUN apt-get update && apt-get install -y --no-install-recommends \
    git curl ca-certificates \
    tesseract-ocr tesseract-ocr-eng tesseract-ocr-vie \
    libreoffice-writer libreoffice-calc libreoffice-impress \
    && rm -rf /var/lib/apt/lists/*

RUN git clone --depth 1 https://huggingface.co/spaces/smolagents/ml-intern /tmp/source && \
    cp /tmp/source/pyproject.toml /tmp/source/uv.lock ./ && \
    cp -r /tmp/source/agent ./agent && \
    cp -r /tmp/source/backend ./backend && \
    cp -r /tmp/source/configs ./configs && \
    cp -r /tmp/source/scripts ./scripts && \
    rm -rf /tmp/source

# Restore pre-retirement backend entrypoint (start.sh -> uvicorn main:app instead of retired_main:app)
COPY patch_restore_full_app.py /tmp/patch_restore_full_app.py
RUN python3 /tmp/patch_restore_full_app.py

RUN uv sync --no-dev --frozen

# Document parsing Python deps (PDF, images/OCR, Excel, Word, PPT, OpenDocument (ODT/ODS/ODP, RTF)
RUN uv pip install --python /app/.venv/bin/python \
    pypdf \
    python-docx \
    openpyxl \
    python-pptx \
    pytesseract \
    Pillow

COPY --from=frontend-builder /source/frontend/dist ./static/
COPY configs/frontend_agent_config.json ./configs/frontend_agent_config.json
# Document text extractor module used by the backend upload route
COPY backend/document_parser.py /app/backend/document_parser.py

# Patch backend: accept new model IDs
COPY patch_models.py /tmp/patch_models.py
RUN python /tmp/patch_models.py
# Patch backend: add 3 new OpenRouter models
COPY patch_new_models.py /tmp/patch_new_models.py
RUN python /tmp/patch_new_models.py
# Patch backend: fix OpenRouter provider resolution (custom_llm_provider)
COPY patch_openrouter_fix.py /tmp/patch_openrouter_fix.py
RUN python /tmp/patch_openrouter_fix.py

# Patch backend: auto-continue detection + auto-approve
COPY patch_agent_backend.py /tmp/patch_agent_backend.py
RUN python /tmp/patch_agent_backend.py

# Patch backend: multi-format document uploads + text extraction
COPY patch_document_upload.py /tmp/patch_document_upload.py
RUN python /tmp/patch_document_upload.py
# Patch backend: multi-file uploads (many files per request)
COPY patch_multi_upload.py /tmp/patch_multi_upload.py
RUN python /tmp/patch_multi_upload.py

RUN mkdir -p /app/session_logs && chown -R user:user /app

USER user
ENV HOME=/home/user \
    PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app \
    PATH="/app/.venv/bin:$PATH"

EXPOSE 7860
WORKDIR /app/backend
CMD ["sh", "start.sh"]