Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +22 -14
Dockerfile
CHANGED
@@ -1,28 +1,36 @@
|
|
1 |
-
# Use Python base image
|
2 |
-
FROM python:3.9
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Set working directory
|
5 |
WORKDIR /app
|
6 |
|
7 |
-
# Copy files
|
8 |
COPY requirements.txt .
|
9 |
COPY main.py .
|
10 |
|
11 |
-
# Install dependencies
|
12 |
-
RUN
|
13 |
-
|
14 |
-
|
15 |
-
ENV HF_HOME="/tmp/huggingface"
|
16 |
|
17 |
-
# Ensure the directory exists
|
18 |
RUN mkdir -p $HF_HOME
|
19 |
|
20 |
-
# Pre-download
|
21 |
-
RUN python -c "from transformers import pipeline;
|
22 |
-
|
|
|
|
|
|
|
23 |
|
24 |
# Expose port for FastAPI
|
25 |
EXPOSE 7860
|
26 |
|
27 |
-
# Run FastAPI server
|
28 |
-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
# Use a stable Python base image
|
2 |
+
FROM python:3.9-slim
|
3 |
+
|
4 |
+
# Set environment variables
|
5 |
+
ENV PYTHONUNBUFFERED=1 \
|
6 |
+
LANG=C.UTF-8 \
|
7 |
+
HF_HOME="/app/huggingface_cache" \
|
8 |
+
HUGGINGFACE_HUB_CACHE="/app/huggingface_cache"
|
9 |
|
10 |
# Set working directory
|
11 |
WORKDIR /app
|
12 |
|
13 |
+
# Copy required files
|
14 |
COPY requirements.txt .
|
15 |
COPY main.py .
|
16 |
|
17 |
+
# Install dependencies using a virtual environment
|
18 |
+
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 |
+
# Ensure the model cache directory exists
|
23 |
RUN mkdir -p $HF_HOME
|
24 |
|
25 |
+
# Pre-download models (handle errors gracefully)
|
26 |
+
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
27 |
+
pipeline('sentiment-analysis', model='tabularisai/multilingual-sentiment-analysis')" || echo "Failed to download model 1"
|
28 |
+
|
29 |
+
RUN /app/venv/bin/python -c "from transformers import pipeline; \
|
30 |
+
pipeline('sentiment-analysis', model='siebert/sentiment-roberta-large-english')" || echo "Failed to download model 2"
|
31 |
|
32 |
# Expose port for FastAPI
|
33 |
EXPOSE 7860
|
34 |
|
35 |
+
# Run FastAPI server using virtual environment
|
36 |
+
CMD ["/app/venv/bin/uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|