Gunroar commited on
Commit
054807c
·
1 Parent(s): 56538d0
Files changed (2) hide show
  1. Dockerfile +37 -20
  2. main.py +2 -1
Dockerfile CHANGED
@@ -1,39 +1,56 @@
1
- # syntax=docker/dockerfile:1
2
-
3
  FROM python:3.10-slim
4
 
5
- ENV PYTHONDONTWRITEBYTECODE=1 \
 
6
  PYTHONUNBUFFERED=1 \
 
7
  PIP_NO_CACHE_DIR=1 \
8
- HF_HOME=/app/hf-home \
9
- HUGGINGFACE_HUB_CACHE=/app/hf-home \
10
- TRANSFORMERS_CACHE=/app/hf-home/transformers \
11
- TOKENIZERS_PARALLELISM=false \
12
- PORT=8000
13
 
14
- WORKDIR /app
 
15
 
16
- # System deps (for scientific libs and uvicorn)
17
  RUN apt-get update && apt-get install -y --no-install-recommends \
18
  build-essential \
19
  git \
 
 
 
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
- # Ensure Hugging Face cache dirs exist and are writable
23
- RUN mkdir -p /app/hf-home/transformers && chmod -R 777 /app/hf-home
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- # Copy only requirements first for better layer caching
26
- COPY requirements.txt ./
27
 
28
- RUN pip install --upgrade pip && \
29
- pip install -r requirements.txt
30
 
31
- # Copy the rest of the application
32
  COPY . .
33
 
34
- EXPOSE 8000
 
35
 
36
- # Default command: serve FastAPI via uvicorn, binding to ${PORT}
37
- CMD ["sh", "-c", "uvicorn multilingual.multi:app --host 0.0.0.0 --port ${PORT:-8000} --lifespan off --timeout-keep-alive 75"]
38
 
39
 
 
1
+ # Use a lightweight Python base
 
2
  FROM python:3.10-slim
3
 
4
+ # Prevent interactive prompts & speed up Python
5
+ ENV DEBIAN_FRONTEND=noninteractive \
6
  PYTHONUNBUFFERED=1 \
7
+ PYTHONDONTWRITEBYTECODE=1 \
8
  PIP_NO_CACHE_DIR=1 \
9
+ TOKENIZERS_PARALLELISM=false
 
 
 
 
10
 
11
+ # Set work directory
12
+ WORKDIR /code
13
 
14
+ # Install system dependencies
15
  RUN apt-get update && apt-get install -y --no-install-recommends \
16
  build-essential \
17
  git \
18
+ curl \
19
+ libopenblas-dev \
20
+ libomp-dev \
21
  && rm -rf /var/lib/apt/lists/*
22
 
23
+ # Copy requirements first (for Docker caching)
24
+ COPY requirements.txt .
25
+
26
+ # Install Python dependencies
27
+ RUN pip install --no-cache-dir -r requirements.txt
28
+
29
+ # Hugging Face tools
30
+ RUN pip install --no-cache-dir huggingface-hub accelerate
31
+
32
+ # Set Hugging Face cache inside container (persistent, not /tmp)
33
+ ENV HF_HOME=/models/huggingface
34
+ ENV TRANSFORMERS_CACHE=/models/huggingface
35
+ ENV HUGGINGFACE_HUB_CACHE=/models/huggingface
36
+ ENV HF_HUB_CACHE=/models/huggingface
37
+
38
+ # Create cache dir
39
+ RUN mkdir -p /models/huggingface
40
 
41
+ # Pre-download model at build time (NLLB model)
42
+ RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='drrobot9/nllb-ig-yo-ha-finetuned')"
43
 
44
+ # Preload tokenizer (avoid runtime delays)
45
+ RUN python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('drrobot9/nllb-ig-yo-ha-finetuned', use_fast=True)"
46
 
47
+ # Copy project files
48
  COPY . .
49
 
50
+ # Expose FastAPI port
51
+ EXPOSE 7860
52
 
53
+ # Run FastAPI app with uvicorn (2 workers for better concurrency)
54
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]
55
 
56
 
main.py CHANGED
@@ -1,10 +1,11 @@
1
  import os
2
  import uvicorn
 
3
 
4
 
5
  if __name__ == "__main__":
6
  host = os.getenv("HOST", "0.0.0.0")
7
- port = int(os.getenv("PORT", "8000"))
8
  uvicorn.run("multilingual.multi:app", host=host, port=port, reload=False)
9
 
10
 
 
1
  import os
2
  import uvicorn
3
+ from multilingual.multi import app
4
 
5
 
6
  if __name__ == "__main__":
7
  host = os.getenv("HOST", "0.0.0.0")
8
+ port = int(os.getenv("PORT", "7860"))
9
  uvicorn.run("multilingual.multi:app", host=host, port=port, reload=False)
10
 
11