esteele commited on
Commit
b29b162
·
1 Parent(s): 1f4dab4

add permissions to Dockerfile

Browse files
Files changed (2) hide show
  1. Dockerfile +16 -2
  2. app/services/ai_service.py +5 -6
Dockerfile CHANGED
@@ -2,12 +2,26 @@ FROM ubuntu:latest
2
  LABEL authors="Carla"
3
  FROM python:3.13
4
 
5
- WORKDIR /code
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  COPY requirements.txt .
8
  RUN pip install --no-cache-dir -r requirements.txt
9
 
10
- COPY . .
 
 
11
 
12
  # Expose FastAPI on port 7860 (required for Spaces)
13
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
2
  LABEL authors="Carla"
3
  FROM python:3.13
4
 
5
+ # Set up a new user named "user" with user ID 1000
6
+ RUN useradd -m -u 1000 user
7
+
8
+ # Switch to the "user" user
9
+ USER user
10
+
11
+ # Set home to the user's home directory
12
+ ENV HOME=/home/user \
13
+ PATH=/home/user/.local/bin:$PATH
14
+
15
+ # Set the working directory to the user's home directory
16
+ WORKDIR $HOME/code
17
+ #WORKDIR /code
18
 
19
  COPY requirements.txt .
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
23
+ COPY --chown=user . $HOME/code
24
+ #COPY . .
25
 
26
  # Expose FastAPI on port 7860 (required for Spaces)
27
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app/services/ai_service.py CHANGED
@@ -1,25 +1,24 @@
1
  import glob
2
  import os
3
 
4
- from huggingface_hub import try_to_load_from_cache
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
6
 
7
  # Load GPT-2 small (text generation)
8
  # -----------------------------
9
  GPT2_MODEL_NAME = "distilgpt2"
10
- # CACHE_DIR = "./data/hf_cache"
11
- # os.makedirs(CACHE_DIR, exist_ok=True)
12
 
13
 
14
- for lock_file in glob.glob(os.path.join(try_to_load_from_cache('funny-meme-generator', 'cache_dir'), "*.lock")):
15
  try:
16
  os.remove(lock_file)
17
  print(f"Removed lock file: {lock_file}")
18
  except Exception as e:
19
  print(f"Could not remove {lock_file}: {e}")
20
 
21
- gpt2_tokenizer = AutoTokenizer.from_pretrained(GPT2_MODEL_NAME, cache_dir=try_to_load_from_cache('funny-meme-generator', 'cache_dir'))
22
- gpt2_model = AutoModelForCausalLM.from_pretrained(GPT2_MODEL_NAME, cache_dir=try_to_load_from_cache('funny-meme-generator', 'cache_dir'))
23
 
24
  # tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
25
  # model = AutoModelWithLMHead.from_pretrained(MODEL_NAME)
 
1
  import glob
2
  import os
3
 
 
4
  from transformers import AutoTokenizer, AutoModelForCausalLM
5
 
6
  # Load GPT-2 small (text generation)
7
  # -----------------------------
8
  GPT2_MODEL_NAME = "distilgpt2"
9
+ CACHE_DIR = "./data/hf_cache"
10
+ os.makedirs(CACHE_DIR, exist_ok=True)
11
 
12
 
13
+ for lock_file in glob.glob(os.path.join(CACHE_DIR, "*.lock")):
14
  try:
15
  os.remove(lock_file)
16
  print(f"Removed lock file: {lock_file}")
17
  except Exception as e:
18
  print(f"Could not remove {lock_file}: {e}")
19
 
20
+ gpt2_tokenizer = AutoTokenizer.from_pretrained(GPT2_MODEL_NAME, cache_dir=CACHE_DIR)
21
+ gpt2_model = AutoModelForCausalLM.from_pretrained(GPT2_MODEL_NAME, cache_dir=CACHE_DIR)
22
 
23
  # tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
24
  # model = AutoModelWithLMHead.from_pretrained(MODEL_NAME)