gary-boon commited on
Commit
a3e1f56
·
1 Parent(s): 2c0fd9b

Fix HuggingFace Spaces cache permission error

Browse files

- Set TRANSFORMERS_CACHE, HF_HOME, and HUGGINGFACE_HUB_CACHE to /tmp directories
- Create cache directories with proper permissions in Dockerfile
- Configure environment variables in app.py for HF Spaces
- Use CPU for HF Spaces free tier

Files changed (2) hide show
  1. Dockerfile +9 -0
  2. app.py +6 -1
Dockerfile CHANGED
@@ -8,6 +8,15 @@ RUN apt-get update && apt-get install -y \
8
 
9
  WORKDIR /app
10
 
 
 
 
 
 
 
 
 
 
11
  # Copy and install Python requirements
12
  COPY requirements.txt .
13
  RUN pip install --no-cache-dir -r requirements.txt
 
8
 
9
  WORKDIR /app
10
 
11
+ # Set environment variables for Hugging Face cache
12
+ ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
13
+ ENV HF_HOME=/tmp/hf_home
14
+ ENV HUGGINGFACE_HUB_CACHE=/tmp/huggingface_hub
15
+
16
+ # Create cache directories with proper permissions
17
+ RUN mkdir -p /tmp/transformers_cache /tmp/hf_home /tmp/huggingface_hub && \
18
+ chmod -R 777 /tmp/transformers_cache /tmp/hf_home /tmp/huggingface_hub
19
+
20
  # Copy and install Python requirements
21
  COPY requirements.txt .
22
  RUN pip install --no-cache-dir -r requirements.txt
app.py CHANGED
@@ -24,9 +24,14 @@ if os.getenv("SPACE_ID"):
24
  # Running on HuggingFace Spaces
25
  logger.info(f"Running on HuggingFace Spaces: {os.getenv('SPACE_ID')}")
26
 
 
 
 
 
 
27
  # Set production environment variables
28
  os.environ["ENVIRONMENT"] = "production"
29
- os.environ["MODEL_DEVICE"] = os.getenv("MODEL_DEVICE", "cuda")
30
 
31
  # Enable CORS for the Space URL
32
  space_host = os.getenv("SPACE_HOST", "")
 
24
  # Running on HuggingFace Spaces
25
  logger.info(f"Running on HuggingFace Spaces: {os.getenv('SPACE_ID')}")
26
 
27
+ # Set cache directories for HuggingFace Spaces
28
+ os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers_cache"
29
+ os.environ["HF_HOME"] = "/tmp/hf_home"
30
+ os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface_hub"
31
+
32
  # Set production environment variables
33
  os.environ["ENVIRONMENT"] = "production"
34
+ os.environ["MODEL_DEVICE"] = os.getenv("MODEL_DEVICE", "cpu") # Use CPU for HF Spaces free tier
35
 
36
  # Enable CORS for the Space URL
37
  space_host = os.getenv("SPACE_HOST", "")