File size: 1,380 Bytes
95b4e2c
cffa613
128809c
cffa613
f459109
cffa613
 
128809c
 
 
 
 
cffa613
128809c
 
 
 
 
47e51b3
 
 
 
 
128809c
 
cffa613
f23f09e
128809c
f23f09e
 
128809c
 
cffa613
5c1e402
00c98b1
5c1e402
95b4e2c
 
cffa613
13e379e
95b4e2c
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
FROM python:3.10-slim

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

# Hugging Face Spaces requires running as a non-root user (UID 1000)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# Copy requirements
COPY --chown=user requirements.txt .

# Pre-install problematic dependencies to prevent pip metadata backtracking
RUN pip install --no-cache-dir typing-extensions Jinja2

# Install stable PyTorch cu124
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

# Install remaining requirements and Triton explicitly for Linux cloud environment
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir triton xformers --index-url https://download.pytorch.org/whl/cu124

# Install Unsloth natively to bypass PyPI resolution constraints
RUN pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
# Copy application files
COPY --chown=user . .

# Set PYTHONPATH so Uvicorn can resolve the 'src' module
ENV PYTHONPATH="/home/user/app"

# Expose Hugging Face Spaces port
EXPOSE 7860

# Launch FastAPI app with Uvicorn
CMD ["uvicorn", "src.api.server:app", "--host", "0.0.0.0", "--port", "7860"]