MohammadReza-Halakoo commited on
Commit
1981928
·
verified ·
1 Parent(s): f31d5ae

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +31 -11
Dockerfile CHANGED
@@ -1,38 +1,58 @@
 
1
  FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
 
5
  ENV HOME=/app \
6
  STREAMLIT_BROWSER_GATHER_USAGE_STATS=false \
7
- STREAMLIT_TELEMETRY_OPT_OUT=true
 
 
8
 
9
- # System deps
10
  RUN apt-get update && apt-get install -y --no-install-recommends \
11
- build-essential curl git libgl1 libglib2.0-0 tesseract-ocr tesseract-ocr-fas libtesseract-dev \
 
 
 
 
 
 
 
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Writable dirs
15
  RUN mkdir -p /app/.streamlit /tmp/.streamlit /tmp/hf_home && \
16
  chmod -R 777 /app/.streamlit /tmp/.streamlit /tmp/hf_home
17
 
18
- # Python deps
19
  COPY requirements.txt ./
20
  RUN python -m pip install --upgrade pip setuptools wheel && \
21
  pip install --no-cache-dir -r requirements.txt
22
 
23
- # Streamlit config
24
- RUN printf "[server]\nheadless=true\nenableXsrfProtection=false\nenableCORS=false\nmaxUploadSize=200\n\n[browser]\ngatherUsageStats=false\n" > /app/.streamlit/config.toml
 
 
 
 
 
 
25
 
26
- # Project files
27
  COPY . .
28
 
29
- # ---- CONFIGURE YOUR PERSONAL MODEL HERE (choose one) ----
30
- # (A) Local model folder baked into image (copy your folder into ./models/TrustOCR)
31
  # ENV TRUSTOCR_PATH=/app/models/TrustOCR
32
- # (B) Private HF repo (set token in Space Secrets or here)
33
  # ENV TRUSTOCR_REPO=MohammadReza-Halakoo/TrustOCR
34
  # ENV HUGGINGFACE_HUB_TOKEN=hf_xxx
35
 
 
36
  EXPOSE 8501
37
  HEALTHCHECK CMD curl --fail http://localhost:${PORT:-8501}/_stcore/health || exit 1
 
 
38
  ENTRYPOINT ["bash","-lc","streamlit run app.py --server.port=${PORT:-8501} --server.address=0.0.0.0"]
 
1
+ # ===== Dockerfile نهایی برای HF Spaces / Streamlit =====
2
  FROM python:3.11-slim
3
 
4
  WORKDIR /app
5
 
6
+ # محیط‌های لازم
7
  ENV HOME=/app \
8
  STREAMLIT_BROWSER_GATHER_USAGE_STATS=false \
9
+ STREAMLIT_TELEMETRY_OPT_OUT=true \
10
+ HF_HOME=/tmp/hf_home \
11
+ TRANSFORMERS_ATTENTION_IMPLEMENTATION=eager
12
 
13
+ # دیپندنسی‌های سیستمی: OpenCV + Tesseract (با فارسی) + ابزار Build
14
  RUN apt-get update && apt-get install -y --no-install-recommends \
15
+ build-essential \
16
+ curl \
17
+ git \
18
+ libgl1 \
19
+ libglib2.0-0 \
20
+ tesseract-ocr \
21
+ tesseract-ocr-fas \
22
+ libtesseract-dev \
23
  && rm -rf /var/lib/apt/lists/*
24
 
25
+ # دایرکتوری‌های قابل‌نوشتن برای Streamlit/HF
26
  RUN mkdir -p /app/.streamlit /tmp/.streamlit /tmp/hf_home && \
27
  chmod -R 777 /app/.streamlit /tmp/.streamlit /tmp/hf_home
28
 
29
+ # نصب پایتون‌پکیج‌ها (نسخه‌ها pinned برای سازگاری با surya_order)
30
  COPY requirements.txt ./
31
  RUN python -m pip install --upgrade pip setuptools wheel && \
32
  pip install --no-cache-dir -r requirements.txt
33
 
34
+ # تنظیمات Streamlit: خاموش کردن XSRF/CORS و افزایش سقف آپلود
35
+ RUN printf "[server]\n\
36
+ headless = true\n\
37
+ enableXsrfProtection = false\n\
38
+ enableCORS = false\n\
39
+ maxUploadSize = 200\n\n\
40
+ [browser]\n\
41
+ gatherUsageStats = false\n" > /app/.streamlit/config.toml
42
 
43
+ # کپی کل پروژه (app.py و …)
44
  COPY . .
45
 
46
+ # ---- تنظیم مدل شخصی (یکی را انتخاب کن) ----
47
+ # (A) مسیر محلی baked-in (پوشه را در ./models/TrustOCR کپی کن)
48
  # ENV TRUSTOCR_PATH=/app/models/TrustOCR
49
+ # (B) ریپوی خصوصی HF (توکن را در Secrets ست کن)
50
  # ENV TRUSTOCR_REPO=MohammadReza-Halakoo/TrustOCR
51
  # ENV HUGGINGFACE_HUB_TOKEN=hf_xxx
52
 
53
+ # پورت (روی HF معمولاً PORT ست می‌شود؛ پیش‌فرض 8501)
54
  EXPOSE 8501
55
  HEALTHCHECK CMD curl --fail http://localhost:${PORT:-8501}/_stcore/health || exit 1
56
+
57
+ # اجرای Streamlit (PORT را از محیط می‌گیرد)
58
  ENTRYPOINT ["bash","-lc","streamlit run app.py --server.port=${PORT:-8501} --server.address=0.0.0.0"]