Antigravity commited on
Commit
34025ae
·
1 Parent(s): ec62919

Optimize Hugging Face deploy: Add HF user permissions & push pre-built React dist

Browse files
Files changed (2) hide show
  1. .gitignore +0 -1
  2. Dockerfile +14 -11
.gitignore CHANGED
@@ -9,4 +9,3 @@ pip_list.txt
9
  *.mp3
10
  dataset/
11
  frontend/node_modules/
12
- frontend/dist/
 
9
  *.mp3
10
  dataset/
11
  frontend/node_modules/
 
Dockerfile CHANGED
@@ -4,7 +4,7 @@ FROM python:3.10-slim
4
  # Set the working directory in the container
5
  WORKDIR /app
6
 
7
- # Install system dependencies + Node.js for React build
8
  RUN apt-get update && apt-get install -y \
9
  build-essential \
10
  libasound2-dev \
@@ -12,9 +12,6 @@ RUN apt-get update && apt-get install -y \
12
  libportaudio2 \
13
  libportaudiocpp0 \
14
  ffmpeg \
15
- curl \
16
- && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
17
- && apt-get install -y nodejs \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
  # Copy the requirements file into the container
@@ -24,17 +21,23 @@ COPY requirements.txt .
24
  RUN pip install --no-cache-dir -r requirements.txt
25
 
26
  # Copy the rest of the application code
 
27
  COPY . .
28
 
29
- # Build the React frontend
30
- WORKDIR /app/frontend
31
- RUN npm install && npm run build
32
-
33
- # Back to app root
34
- WORKDIR /app
35
-
36
  # Expose the port the app runs on (Hugging Face uses 7860)
37
  EXPOSE 7860
38
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  # Command to run the application with increased timeout for model loading
40
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "300", "--workers", "1", "app:app"]
 
4
  # Set the working directory in the container
5
  WORKDIR /app
6
 
7
+ # Install system dependencies
8
  RUN apt-get update && apt-get install -y \
9
  build-essential \
10
  libasound2-dev \
 
12
  libportaudio2 \
13
  libportaudiocpp0 \
14
  ffmpeg \
 
 
 
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
  # Copy the requirements file into the container
 
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
23
  # Copy the rest of the application code
24
+ # (This now includes frontend/dist because we removed it from .gitignore)
25
  COPY . .
26
 
 
 
 
 
 
 
 
27
  # Expose the port the app runs on (Hugging Face uses 7860)
28
  EXPOSE 7860
29
 
30
+ # Hugging Face Spaces requires running as a non-root user
31
+ # Create user and set permissions for writable directories
32
+ RUN useradd -m -u 1000 user
33
+ RUN mkdir -p /app/static/uploads /app/.cache && \
34
+ chmod -R 777 /app
35
+
36
+ # Set environment variables for model caching in a writable directory
37
+ ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
38
+ ENV TORCH_HOME=/app/.cache/torch
39
+
40
+ USER user
41
+
42
  # Command to run the application with increased timeout for model loading
43
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "300", "--workers", "1", "app:app"]