Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- 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=/
|
|
|
8 |
TRANSFORMERS_VERBOSITY=error
|
9 |
|
10 |
-
#
|
|
|
|
|
|
|
11 |
WORKDIR /app
|
12 |
-
|
13 |
-
|
|
|
|
|
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 |
-
|
29 |
RUN pip install soundfile
|
30 |
|
|
|
|
|
|
|
31 |
# Download Bark TTS model
|
32 |
RUN python3 - <<EOF
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
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 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
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
|
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
|