devcom33 commited on
Commit
35e86bd
·
1 Parent(s): 093c950

Updated FastAPI code

Browse files
Files changed (2) hide show
  1. Dockerfile +6 -6
  2. app.py +0 -8
Dockerfile CHANGED
@@ -13,19 +13,19 @@ WORKDIR /app
13
  # Create a non-root user with a dedicated home directory
14
  RUN addgroup --system app && adduser --system --group --home /home/app app
15
 
16
- # Create cache directories and set ownership
17
  RUN mkdir -p /tmp/huggingface /tmp/matplotlib
18
  RUN chown -R app:app /tmp/huggingface /tmp/matplotlib
19
 
20
- # Copy source code and set ownership
21
  COPY . .
22
  RUN chown -R app:app /app
23
 
24
  # Switch to the non-root user
25
  USER app
26
 
27
- # Set environment variables
28
- # 1. Add user's local bin to the PATH for executables (like uvicorn)
29
  # 2. Add user's site-packages to PYTHONPATH for module imports
30
  ENV PATH="/home/app/.local/bin:${PATH}"
31
  ENV PYTHONPATH="/home/app/.local/lib/python3.10/site-packages"
@@ -34,14 +34,14 @@ ENV HF_HUB_CACHE=/tmp/huggingface
34
  ENV TRANSFORMERS_CACHE=/tmp/huggingface
35
  ENV MPLCONFIGDIR=/tmp/matplotlib
36
 
37
- # Now, run pip install as the 'app' user.
38
  # Pip will correctly install packages to /home/app/.local
39
  RUN pip install --upgrade pip
40
  RUN pip install --no-cache-dir torch torchvision torchaudio
41
  RUN pip install --no-cache-dir git+https://github.com/pyannote/pyannote-audio.git
42
  RUN pip install --no-cache-dir -r requirements.txt
43
 
44
- # Expose FastAPI port
45
  EXPOSE 7860
46
 
47
  # Run the FastAPI app
 
13
  # Create a non-root user with a dedicated home directory
14
  RUN addgroup --system app && adduser --system --group --home /home/app app
15
 
16
+ # Create cache directories and set ownership to the 'app' user
17
  RUN mkdir -p /tmp/huggingface /tmp/matplotlib
18
  RUN chown -R app:app /tmp/huggingface /tmp/matplotlib
19
 
20
+ # Copy source code and set its ownership
21
  COPY . .
22
  RUN chown -R app:app /app
23
 
24
  # Switch to the non-root user
25
  USER app
26
 
27
+ # Set environment variables so the system can find executables and modules
28
+ # 1. Add user's local bin to PATH for executables (like uvicorn)
29
  # 2. Add user's site-packages to PYTHONPATH for module imports
30
  ENV PATH="/home/app/.local/bin:${PATH}"
31
  ENV PYTHONPATH="/home/app/.local/lib/python3.10/site-packages"
 
34
  ENV TRANSFORMERS_CACHE=/tmp/huggingface
35
  ENV MPLCONFIGDIR=/tmp/matplotlib
36
 
37
+ # Run pip install as the 'app' user.
38
  # Pip will correctly install packages to /home/app/.local
39
  RUN pip install --upgrade pip
40
  RUN pip install --no-cache-dir torch torchvision torchaudio
41
  RUN pip install --no-cache-dir git+https://github.com/pyannote/pyannote-audio.git
42
  RUN pip install --no-cache-dir -r requirements.txt
43
 
44
+ # Expose the application port
45
  EXPOSE 7860
46
 
47
  # Run the FastAPI app
app.py CHANGED
@@ -16,14 +16,6 @@ from google.api_core import exceptions as api_core_exceptions
16
 
17
  logger = logging.getLogger(__name__)
18
 
19
- os.environ["HF_HOME"] = "/tmp/huggingface"
20
- os.environ["HF_HUB_CACHE"] = "/tmp/huggingface"
21
- os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
22
- os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
23
-
24
- os.makedirs("/tmp/huggingface", exist_ok=True)
25
- os.makedirs("/tmp/matplotlib", exist_ok=True)
26
-
27
  app = FastAPI(
28
  title="Transcription and Summarization API",
29
  description="API using Faster-Whisper, spaCy, and Hugging Face Transformers",
 
16
 
17
  logger = logging.getLogger(__name__)
18
 
 
 
 
 
 
 
 
 
19
  app = FastAPI(
20
  title="Transcription and Summarization API",
21
  description="API using Faster-Whisper, spaCy, and Hugging Face Transformers",