Spaces:
Sleeping
Sleeping
Create Dockerfile
Browse files- Dockerfile +30 -0
Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use lightweight Python base image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies (for PyTorch and git)
|
| 8 |
+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
| 9 |
+
|
| 10 |
+
# Copy requirements and install
|
| 11 |
+
COPY requirements.txt .
|
| 12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
+
|
| 14 |
+
# Copy application code
|
| 15 |
+
COPY . .
|
| 16 |
+
|
| 17 |
+
# ✅ Hugging Face cache directory (use /tmp, writable in Spaces)
|
| 18 |
+
ENV HF_HOME=/tmp
|
| 19 |
+
|
| 20 |
+
# Pre-download model into /tmp to avoid cold start
|
| 21 |
+
RUN python -c "from transformers import AutoTokenizer, AutoModelForCausalLM; \
|
| 22 |
+
model_id='rabiyulfahim/qa_python_gpt2'; \
|
| 23 |
+
AutoTokenizer.from_pretrained(model_id, cache_dir='/tmp'); \
|
| 24 |
+
AutoModelForCausalLM.from_pretrained(model_id, cache_dir='/tmp')"
|
| 25 |
+
|
| 26 |
+
# Expose FastAPI port
|
| 27 |
+
EXPOSE 8000
|
| 28 |
+
|
| 29 |
+
# Run FastAPI with Uvicorn
|
| 30 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|