Spaces:
Runtime error

humanizer-engine / Dockerfile
faseehsandhu's picture
add frontend and docker deployment for hf spaces
c327c7a
Raw History Blame Contribute Delete
1.48 kB
# ---- Hugging Face Spaces Docker deployment ----
# Optimised for CPU-only inference (Qwen2.5-0.5B + spaCy)
FROM python:3.11-slim
# System dependencies: Java (required by LanguageTool)
RUN apt-get update && apt-get install -y --no-install-recommends \
default-jre-headless \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Install CPU-only PyTorch first (skips ~2 GB CUDA libraries)
RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
# Install remaining Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Download spaCy language model
RUN python -m spacy download en_core_web_sm
# Set HuggingFace cache inside the app directory (accessible to non-root user)
ENV HF_HOME=/app/.cache/huggingface
# Pre-download Qwen2.5-0.5B so startup doesn't block on a 1 GB download
RUN python -c "\
from transformers import AutoTokenizer, AutoModelForCausalLM; \
AutoTokenizer.from_pretrained('Qwen/Qwen2.5-0.5B'); \
AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-0.5B')"
# Pre-download LanguageTool data (Java archive)
RUN python -c "import language_tool_python; lt = language_tool_python.LanguageTool('en-US'); lt.close()"
# Copy application code
COPY . .
# HF Spaces runs containers as user 1000
RUN useradd -m -u 1000 user && chown -R user:user /app
USER user
# HF Spaces expects port 7860
ENV PORT=7860
EXPOSE 7860
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]