File size: 1,687 Bytes
07f753d
92b5340
 
 
 
 
4eeb5bc
c6dd11e
 
 
 
 
 
 
 
69e8f52
 
07f753d
 
d89c043
 
4eeb5bc
5dcac49
 
8593270
5dcac49
 
8593270
92b5340
 
 
 
 
 
 
 
 
 
8ebe686
07f753d
92b5340
4eeb5bc
69e8f52
5dcac49
8593270
778db15
07f753d
 
69e8f52
8593270
 
07f753d
c3b8ebb
48a6d9c
5dcac49
 
95871f8
5dcac49
 
69e8f52
07f753d
 
69e8f52
b21b232
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Dockerfile
#FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04

ARG DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1

RUN apt-get update && apt-get install --no-install-recommends -y \
  build-essential \
  python3.9 \
  python3-pip \
  git \
  ffmpeg \
  && apt-get clean && rm -rf /var/lib/apt/lists/*

# Set environment variables to prevent Python from writing pyc files to disk
# and to force unbuffered output (useful for Docker)
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV HF_HOME "app/cache"
ENV TRANSFORMERS_CACHE "app/cache"

### Set up user with permissions
# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Switch to the "user" user
USER user
# Set home to the user's home directory
ENV HOME=/home/user \
	PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=$HOME/app \
	PYTHONUNBUFFERED=1 \
	GRADIO_ALLOW_FLAGGING=never \
	GRADIO_NUM_PORTS=1 \
	GRADIO_SERVER_NAME=0.0.0.0 \
	GRADIO_THEME=huggingface \
	SYSTEM=spaces

# Set the working directory in the container
WORKDIR $HOME/app

# Upgrade pip to the latest version and install Python dependencies
COPY --chown=user requirements.txt .

#RUN chown -R user:user /app
RUN pip install --upgrade pip && pip install -r requirements.txt

# Copy the FastAPI application code and other necessary files into the container
COPY --chown=user:user ./app .
COPY --chown=user:user .env .

RUN ls

### Update permissions for the app
USER root
RUN chmod 777 .
USER user

# Expose port 7860 for the application
EXPOSE 7860

# Command to run the FastAPI application using uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]