black44 commited on
Commit
b8e2812
·
verified ·
1 Parent(s): 71579f2

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -26
Dockerfile CHANGED
@@ -4,13 +4,19 @@ FROM python:3.10-slim
4
  # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1 \
6
  PYTHONUNBUFFERED=1 \
7
- HF_HOME=/app/.cache \
 
8
  TRANSFORMERS_VERBOSITY=error
9
 
10
- # Set working directory and create necessary folders
 
 
 
11
  WORKDIR /app
12
- RUN mkdir -p /app/.cache /app/models/suno-bark /app/models/sentiment && \
13
- chmod -R 777 /app/.cache /app/models
 
 
14
 
15
  # Install OS dependencies
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -25,40 +31,35 @@ RUN pip install --no-cache-dir --root-user-action=ignore -U pip && \
25
  "protobuf" && \
26
  pip install --no-cache-dir --root-user-action=ignore -r requirements.txt
27
 
28
- RUN apt-get update && apt-get install -y libsndfile1
29
  RUN pip install soundfile
30
 
 
 
 
31
  # Download Bark TTS model
32
  RUN python3 - <<EOF
33
- try:
34
- from transformers import AutoTokenizer, AutoProcessor, BarkModel
35
- model_name = "suno/bark-small"
36
- print(f"Downloading {model_name}...")
37
- AutoTokenizer.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
38
- AutoProcessor.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
39
- BarkModel.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
40
- except Exception as e:
41
- print("ERROR:", e)
42
- exit(1)
43
  EOF
44
 
45
  # Download sentiment analysis model
46
  RUN python3 - <<EOF
47
- try:
48
- from transformers import AutoModelForSequenceClassification, AutoTokenizer
49
- model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
50
- print(f"Downloading {model_name}...")
51
- AutoTokenizer.from_pretrained(model_name).save_pretrained("/app/models/sentiment")
52
- AutoModelForSequenceClassification.from_pretrained(model_name).save_pretrained("/app/models/sentiment")
53
- except Exception as e:
54
- print("ERROR:", e)
55
- exit(1)
56
  EOF
57
 
58
  # Copy application source code
59
- COPY app.py .
60
 
61
- # Expose port for the application
62
  EXPOSE 7860
63
 
64
  # Launch app using Uvicorn
 
4
  # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1 \
6
  PYTHONUNBUFFERED=1 \
7
+ HF_HOME=/home/user/.cache/huggingface \
8
+ TRANSFORMERS_CACHE=/home/user/.cache/huggingface/transformers \
9
  TRANSFORMERS_VERBOSITY=error
10
 
11
+ # Create a non-root user
12
+ RUN useradd -m -u 1000 user
13
+
14
+ # Set working directory
15
  WORKDIR /app
16
+
17
+ # Create necessary folders with proper permissions
18
+ RUN mkdir -p /home/user/.cache/huggingface /app/models/suno-bark /app/models/sentiment && \
19
+ chmod -R 777 /home/user/.cache /app/models
20
 
21
  # Install OS dependencies
22
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
31
  "protobuf" && \
32
  pip install --no-cache-dir --root-user-action=ignore -r requirements.txt
33
 
34
+ # Ensure soundfile is installed
35
  RUN pip install soundfile
36
 
37
+ # Set user to non-root for Hugging Face compatibility
38
+ USER user
39
+
40
  # Download Bark TTS model
41
  RUN python3 - <<EOF
42
+ from transformers import AutoTokenizer, AutoProcessor, BarkModel
43
+ model_name = "suno/bark-small"
44
+ print(f"Downloading {model_name}...")
45
+ AutoTokenizer.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
46
+ AutoProcessor.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
47
+ BarkModel.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
 
 
 
 
48
  EOF
49
 
50
  # Download sentiment analysis model
51
  RUN python3 - <<EOF
52
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
53
+ model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
54
+ print(f"Downloading {model_name}...")
55
+ AutoTokenizer.from_pretrained(model_name).save_pretrained("/app/models/sentiment")
56
+ AutoModelForSequenceClassification.from_pretrained(model_name).save_pretrained("/app/models/sentiment")
 
 
 
 
57
  EOF
58
 
59
  # Copy application source code
60
+ COPY --chown=user:user app.py .
61
 
62
+ # Expose port
63
  EXPOSE 7860
64
 
65
  # Launch app using Uvicorn