Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +7 -4
Dockerfile
CHANGED
@@ -10,7 +10,7 @@ ENV PYTHONUNBUFFERED=1 \
|
|
10 |
# Set working directory
|
11 |
WORKDIR /app
|
12 |
|
13 |
-
# Copy required files
|
14 |
COPY requirements.txt .
|
15 |
COPY main.py .
|
16 |
|
@@ -19,16 +19,19 @@ RUN python -m venv /app/venv && \
|
|
19 |
/app/venv/bin/pip install --no-cache-dir --upgrade pip && \
|
20 |
/app/venv/bin/pip install --no-cache-dir -r requirements.txt
|
21 |
|
22 |
-
|
23 |
# Ensure the model cache directory exists
|
24 |
RUN mkdir -p $HF_HOME
|
25 |
|
|
|
|
|
|
|
|
|
26 |
# Pre-download models (handle errors gracefully)
|
27 |
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
28 |
-
pipeline('sentiment-analysis', model='tabularisai/multilingual-sentiment-analysis')" || echo
|
29 |
|
30 |
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
31 |
-
pipeline('sentiment-analysis', model='siebert/sentiment-roberta-large-english')" || echo
|
32 |
|
33 |
# Expose port for FastAPI
|
34 |
EXPOSE 7860
|
|
|
10 |
# Set working directory
|
11 |
WORKDIR /app
|
12 |
|
13 |
+
# Copy the required files
|
14 |
COPY requirements.txt .
|
15 |
COPY main.py .
|
16 |
|
|
|
19 |
/app/venv/bin/pip install --no-cache-dir --upgrade pip && \
|
20 |
/app/venv/bin/pip install --no-cache-dir -r requirements.txt
|
21 |
|
|
|
22 |
# Ensure the model cache directory exists
|
23 |
RUN mkdir -p $HF_HOME
|
24 |
|
25 |
+
# Add Hugging Face token as an environment variable in the container (this will be injected by Hugging Face Spaces' secrets management)
|
26 |
+
ARG HF_TOKEN
|
27 |
+
ENV HF_TOKEN=${HF_TOKEN}
|
28 |
+
|
29 |
# Pre-download models (handle errors gracefully)
|
30 |
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
31 |
+
pipeline('sentiment-analysis', model='tabularisai/multilingual-sentiment-analysis', use_auth_token='$HF_TOKEN')" || echo 'Failed to download model 1'
|
32 |
|
33 |
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
34 |
+
pipeline('sentiment-analysis', model='siebert/sentiment-roberta-large-english', use_auth_token='$HF_TOKEN')" || echo 'Failed to download model 2'
|
35 |
|
36 |
# Expose port for FastAPI
|
37 |
EXPOSE 7860
|