File size: 1,557 Bytes
22bd293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Phi-4-mini-instruct HuggingFace Space Deployment
# Best 4B model for agentic work with tool calling support
# Exposes OpenAI-compatible API on port 7860

FROM python:3.11-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV MODEL_REPO=unsloth/Phi-4-mini-instruct-GGUF
ENV MODEL_FILE=Phi-4-mini-instruct-Q4_K_M.gguf
ENV N_CTX=8192
ENV N_THREADS=2
ENV HOST=0.0.0.0
ENV PORT=7860

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy the startup script
COPY script.sh /app/script.sh
RUN chmod +x /app/script.sh

# Install Python dependencies with pre-built wheels for HF Spaces
RUN pip install --no-cache-dir \
    llama-cpp-python \
    --extra-index-url https://huggingface.co/Luigi/llama-cpp-python-wheels-hf-spaces-free-cpu/resolve/main/

# Install additional dependencies for API server
RUN pip install --no-cache-dir \
    fastapi \
    uvicorn \
    huggingface-hub \
    pydantic

# Pre-download the model during build (optional - comment out if build times out)
# RUN python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='$MODEL_REPO', filename='$MODEL_FILE', local_dir='/app/models')"

# Expose port 7860 (required for HuggingFace Spaces)
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Run the startup script
CMD ["/app/script.sh"]