black44 commited on
Commit
2068bbe
·
verified ·
1 Parent(s): 3496f0f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +41 -41
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- # Use Python 3.10 with slim image
2
  FROM python:3.10-slim
3
 
4
  # Set environment variables
@@ -7,52 +7,52 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
7
  HF_HOME=/app/.cache \
8
  TRANSFORMERS_VERBOSITY=error
9
 
10
- # Create directories with proper permissions
11
  WORKDIR /app
12
- RUN mkdir -p /app/.cache /app/models && \
13
  chmod -R 777 /app/.cache /app/models
14
 
15
- # Install system dependencies (INCLUDING SSL CERTS)
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
  libsndfile1 ffmpeg ca-certificates && \
18
  rm -rf /var/lib/apt/lists/*
19
 
20
- # Install Python dependencies
21
  COPY requirements.txt .
22
- RUN pip install --no-cache-dir -U pip && \
23
- pip install --no-cache-dir -r requirements.txt
24
-
25
- # Pre-download TTS model (WITH ERROR HANDLING)
26
- RUN python -c "try: \
27
- from transformers import AutoTokenizer, AutoProcessor, BarkModel; \
28
- model_name = 'suno/bark-small'; \
29
- print(f'Downloading {model_name}...'); \
30
- tokenizer = AutoTokenizer.from_pretrained(model_name); \
31
- processor = AutoProcessor.from_pretrained(model_name); \
32
- model = BarkModel.from_pretrained(model_name); \
33
- tokenizer.save_pretrained('/app/models/suno-bark'); \
34
- processor.save_pretrained('/app/models/suno-bark'); \
35
- model.save_pretrained('/app/models/suno-bark'); \
36
- except Exception as e: \
37
- print(f'ERROR: {str(e)}'); \
38
- exit(1)"
39
-
40
- # Pre-download sentiment model (WITH ERROR HANDLING)
41
- RUN python -c "try: \
42
- from transformers import AutoModelForSequenceClassification, AutoTokenizer; \
43
- model_name = 'cardiffnlp/twitter-xlm-roberta-base-sentiment'; \
44
- print(f'Downloading {model_name}...'); \
45
- tokenizer = AutoTokenizer.from_pretrained(model_name); \
46
- model = AutoModelForSequenceClassification.from_pretrained(model_name); \
47
- tokenizer.save_pretrained('/app/models/sentiment'); \
48
- model.save_pretrained('/app/models/sentiment'); \
49
- except Exception as e: \
50
- print(f'ERROR: {str(e)}'); \
51
- exit(1)"
52
-
53
- # Copy application code
54
- COPY app.py .
55
-
56
- # Expose port and run
57
  EXPOSE 7860
58
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
1
+ # Use Python 3.10 slim image
2
  FROM python:3.10-slim
3
 
4
  # Set environment variables
 
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 \
17
  libsndfile1 ffmpeg ca-certificates && \
18
  rm -rf /var/lib/apt/lists/*
19
 
20
+ # Copy requirements and install Python dependencies
21
  COPY requirements.txt .
22
+ RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt
23
+
24
+ # Download Bark TTS model
25
+ RUN python3 - <<EOF
26
+ try:
27
+ from transformers import AutoTokenizer, AutoProcessor, BarkModel
28
+ model_name = "suno/bark-small"
29
+ print(f"Downloading {model_name}...")
30
+ AutoTokenizer.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
31
+ AutoProcessor.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
32
+ BarkModel.from_pretrained(model_name).save_pretrained("/app/models/suno-bark")
33
+ except Exception as e:
34
+ print("ERROR:", e)
35
+ exit(1)
36
+ EOF
37
+
38
+ # Download sentiment analysis model
39
+ RUN python3 - <<EOF
40
+ try:
41
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
42
+ model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
43
+ print(f"Downloading {model_name}...")
44
+ AutoTokenizer.from_pretrained(model_name).save_pretrained("/app/models/sentiment")
45
+ AutoModelForSequenceClassification.from_pretrained(model_name).save_pretrained("/app/models/sentiment")
46
+ except Exception as e:
47
+ print("ERROR:", e)
48
+ exit(1)
49
+ EOF
50
+
51
+ # Copy application source code
52
+ COPY app ./app
53
+
54
+ # Expose port for Hugging Face Space
 
 
55
  EXPOSE 7860
56
+
57
+ # Launch app using Uvicorn
58
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]