Spaces:
Sleeping
Sleeping
Create Dockerfile
Browse files- Dockerfile +39 -0
Dockerfile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
build-essential \
|
| 10 |
+
git \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Create a non-root user
|
| 14 |
+
RUN useradd -m -u 1000 appuser
|
| 15 |
+
|
| 16 |
+
# Copy requirements first to leverage Docker cache
|
| 17 |
+
COPY requirements.txt .
|
| 18 |
+
|
| 19 |
+
# Install Python dependencies
|
| 20 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
+
|
| 22 |
+
# Create necessary directories and set permissions
|
| 23 |
+
RUN mkdir -p /app/saved_models /app/tokenizer /app/predictions /app/.cache \
|
| 24 |
+
&& chown -R appuser:appuser /app
|
| 25 |
+
|
| 26 |
+
# Switch to non-root user
|
| 27 |
+
USER appuser
|
| 28 |
+
|
| 29 |
+
# Copy the application code
|
| 30 |
+
COPY --chown=appuser:appuser . .
|
| 31 |
+
|
| 32 |
+
# ✅ Pre-download the RoBERTa tokenizer (for offline or cached inference)
|
| 33 |
+
RUN python -c "from transformers import RobertaTokenizer; RobertaTokenizer.from_pretrained('roberta-base', cache_dir='/app/.cache')"
|
| 34 |
+
|
| 35 |
+
# Expose the port the app runs on (7860 for Hugging Face Spaces)
|
| 36 |
+
EXPOSE 7860
|
| 37 |
+
|
| 38 |
+
# Command to run the FastAPI app
|
| 39 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|