Spaces:
Sleeping
Sleeping
Upload Dockerfile
Browse files- Dockerfile +52 -0
Dockerfile
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Optimized Dockerfile for Hugging Face Spaces
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Install system dependencies
|
| 7 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
+
build-essential \
|
| 9 |
+
gcc \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Create cache directories with proper permissions
|
| 13 |
+
RUN mkdir -p /tmp/transformers_cache /tmp/huggingface /tmp/torch && \
|
| 14 |
+
chmod -R 777 /tmp/transformers_cache /tmp/huggingface /tmp/torch
|
| 15 |
+
|
| 16 |
+
# Copy requirements and install Python dependencies
|
| 17 |
+
COPY requirements.txt .
|
| 18 |
+
|
| 19 |
+
# Install dependencies in stages for better caching
|
| 20 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 21 |
+
pip install --no-cache-dir \
|
| 22 |
+
fastapi==0.104.0 \
|
| 23 |
+
uvicorn[standard]==0.24.0 \
|
| 24 |
+
pydantic==2.5.0 \
|
| 25 |
+
python-multipart==0.0.6 \
|
| 26 |
+
python-dotenv==1.0.0 \
|
| 27 |
+
requests==2.31.0 \
|
| 28 |
+
googletrans==4.0.0rc1 \
|
| 29 |
+
langdetect==1.0.9 && \
|
| 30 |
+
pip install --no-cache-dir \
|
| 31 |
+
numpy==1.24.0 \
|
| 32 |
+
pandas==2.0.0 \
|
| 33 |
+
scikit-learn==1.3.0 && \
|
| 34 |
+
pip install --no-cache-dir \
|
| 35 |
+
torch==2.0.0 \
|
| 36 |
+
transformers==4.35.0 \
|
| 37 |
+
sentence-transformers==2.2.0
|
| 38 |
+
|
| 39 |
+
# Copy application code
|
| 40 |
+
COPY . .
|
| 41 |
+
|
| 42 |
+
# Expose port (Hugging Face Spaces uses 7860 by default)
|
| 43 |
+
EXPOSE 7860
|
| 44 |
+
|
| 45 |
+
# Set environment variables for cache directories
|
| 46 |
+
ENV PORT=7860
|
| 47 |
+
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
|
| 48 |
+
ENV HF_HOME=/tmp/huggingface
|
| 49 |
+
ENV TORCH_HOME=/tmp/torch
|
| 50 |
+
|
| 51 |
+
# Start the application
|
| 52 |
+
CMD ["python", "app.py"]
|