do-devs commited on
Commit
4388489
·
1 Parent(s): 6a0680d
Files changed (2) hide show
  1. Dockerfile +11 -11
  2. app/main.py +8 -2
Dockerfile CHANGED
@@ -1,17 +1,13 @@
1
  # Use an official lightweight Python base image
2
- FROM python:3.10-slim
3
 
4
- # Set working directory
5
  WORKDIR /app
6
 
7
- # Environment variables for Hugging Face cache
8
- ENV HF_HOME=/app/cache
9
- ENV TRANSFORMERS_CACHE=/app/cache
10
-
11
  # Copy requirements first (for caching layers)
12
  COPY requirements.txt .
13
 
14
- # Install system dependencies
15
  RUN apt-get update && apt-get install -y \
16
  build-essential \
17
  python3-dev \
@@ -25,11 +21,15 @@ RUN pip install --no-cache-dir -r requirements.txt
25
  # Copy the rest of the app
26
  COPY . .
27
 
28
- # Create cache directory with correct permissions
29
- RUN mkdir -p /app/cache && chmod -R 777 /app/cache
 
 
 
 
30
 
31
- # Expose HF Spaces default port
32
  EXPOSE 7860
33
 
34
- # Run FastAPI app with uvicorn
35
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # Use an official lightweight Python base image
2
+ FROM python:3.10
3
 
4
+ # Set working directory inside container
5
  WORKDIR /app
6
 
 
 
 
 
7
  # Copy requirements first (for caching layers)
8
  COPY requirements.txt .
9
 
10
+ # Install system dependencies (for lxml, spacy, etc.)
11
  RUN apt-get update && apt-get install -y \
12
  build-essential \
13
  python3-dev \
 
21
  # Copy the rest of the app
22
  COPY . .
23
 
24
+ # --- Hugging Face cache fix ---
25
+ # Make a dedicated cache directory with proper permissions
26
+ RUN mkdir -p /app/hf_cache && chmod -R 777 /app/hf_cache
27
+ ENV HF_HOME=/app/hf_cache
28
+ ENV TRANSFORMERS_CACHE=/app/hf_cache
29
+ ENV HF_DATASETS_CACHE=/app/hf_cache
30
 
31
+ # Expose port (HF Spaces expects 7860 usually)
32
  EXPOSE 7860
33
 
34
+ # Run your FastAPI app via python module
35
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app/main.py CHANGED
@@ -2,8 +2,14 @@
2
  import logging
3
  import os
4
 
5
- os.environ["HF_HOME"] = "./.cache"
6
- os.environ["TRANSFORMERS_CACHE"] = "./.cache"
 
 
 
 
 
 
7
 
8
  logging.basicConfig(
9
  level=logging.INFO,
 
2
  import logging
3
  import os
4
 
5
+ # Use absolute path inside container
6
+ cache_dir = "/app/cache"
7
+
8
+ os.environ["HF_HOME"] = cache_dir
9
+ os.environ["TRANSFORMERS_CACHE"] = cache_dir
10
+
11
+ # Make sure the directory exists
12
+ os.makedirs(cache_dir, exist_ok=True)
13
 
14
  logging.basicConfig(
15
  level=logging.INFO,