Amish Kushwaha commited on
Commit
312afc1
·
1 Parent(s): 156783f

Fix transformer cache issue - attempt 4

Browse files
Files changed (2) hide show
  1. Dockerfile +4 -3
  2. app.py +0 -6
Dockerfile CHANGED
@@ -1,8 +1,9 @@
1
  # Use Python as the base image
2
  FROM python:3.9
3
 
4
- # Set environment variable for cache to a writable location
5
  ENV HF_HOME=/tmp/hf_home
 
6
 
7
  # Set the working directory
8
  WORKDIR /app
@@ -14,8 +15,8 @@ RUN pip install --no-cache-dir -r requirements.txt
14
  # Copy the FastAPI app
15
  COPY . .
16
 
17
- # Ensure the cache directory is created and writable
18
- RUN mkdir -p /tmp/hf_home
19
 
20
  # Run FastAPI server
21
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # Use Python as the base image
2
  FROM python:3.9
3
 
4
+ # Set environment variables for cache
5
  ENV HF_HOME=/tmp/hf_home
6
+ ENV TRANSFORMERS_CACHE=/tmp/hf_home
7
 
8
  # Set the working directory
9
  WORKDIR /app
 
15
  # Copy the FastAPI app
16
  COPY . .
17
 
18
+ # Ensure the cache directory is created and has proper permissions
19
+ RUN mkdir -p /tmp/hf_home && chmod -R 777 /tmp/hf_home
20
 
21
  # Run FastAPI server
22
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -1,13 +1,7 @@
1
- import os
2
  from fastapi import FastAPI
3
  from pydantic import BaseModel
4
  from transformers import pipeline
5
 
6
- # Set the cache directory to a writable location using HF_HOME
7
- cache_dir = "/tmp/hf_home"
8
- os.environ["HF_HOME"] = cache_dir
9
- os.makedirs(cache_dir, exist_ok=True)
10
-
11
  # Load your Hugging Face model
12
  model = pipeline("text-generation", model="devops-bda/Abap")
13
 
 
 
1
  from fastapi import FastAPI
2
  from pydantic import BaseModel
3
  from transformers import pipeline
4
 
 
 
 
 
 
5
  # Load your Hugging Face model
6
  model = pipeline("text-generation", model="devops-bda/Abap")
7