Phoenix21 commited on
Commit
0b42132
·
verified ·
1 Parent(s): 23cc740

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -17
Dockerfile CHANGED
@@ -1,33 +1,28 @@
1
- # Use the official Python 3.9 image as a base image
2
  FROM python:3.9-slim
3
 
4
- # Create a new user with UID 1000 and switch to that user
5
- RUN useradd -m -u 1000 user
6
- USER user
7
-
8
- # Set environment variables for Hugging Face cache and Python
9
- ENV PATH="/home/user/.local/bin:$PATH"
10
- ENV TRANSFORMERS_CACHE="/home/user/.cache/huggingface/transformers"
11
- ENV HF_HOME="/home/user/.cache/huggingface"
12
  ENV PYTHONUNBUFFERED=1
 
 
13
 
14
- # Create cache directories
15
- RUN mkdir -p $TRANSFORMERS_CACHE && \
16
- mkdir -p $HF_HOME
17
 
18
- # Set the working directory inside the container
19
  WORKDIR /app
20
 
21
- # Copy the requirements file into the container and install dependencies
22
  COPY --chown=user ./requirements.txt /app/requirements.txt
23
  RUN pip install --no-cache-dir --upgrade pip && \
24
  pip install --no-cache-dir -r /app/requirements.txt
25
 
26
- # Copy all project files into the container
27
  COPY --chown=user . /app
28
 
29
- # Expose the port that FastAPI will listen on (Hugging Face Spaces requires port 7860)
30
  EXPOSE 7860
31
 
32
- # Start the FastAPI app using uvicorn, listening on port 7860
33
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use a lightweight Python 3.9 image
2
  FROM python:3.9-slim
3
 
4
+ # Set environment variables for Python and Hugging Face cache
 
 
 
 
 
 
 
5
  ENV PYTHONUNBUFFERED=1
6
+ ENV TRANSFORMERS_CACHE="/tmp/cache/huggingface/transformers"
7
+ ENV HF_HOME="/tmp/cache/huggingface"
8
 
9
+ # Create a non-root user and switch to it
10
+ RUN useradd -m -u 1000 user
11
+ USER user
12
 
13
+ # Set the working directory
14
  WORKDIR /app
15
 
16
+ # Copy the requirements file and install dependencies
17
  COPY --chown=user ./requirements.txt /app/requirements.txt
18
  RUN pip install --no-cache-dir --upgrade pip && \
19
  pip install --no-cache-dir -r /app/requirements.txt
20
 
21
+ # Copy the rest of the application code
22
  COPY --chown=user . /app
23
 
24
+ # Expose port 7860 (required by Hugging Face Spaces)
25
  EXPOSE 7860
26
 
27
+ # Start the FastAPI app using uvicorn
28
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]