File size: 1,196 Bytes
6a4cec1 | 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 | # Gunakan image Python resmi yang ringan
FROM python:3.10-slim
# Set working directory di dalam container
WORKDIR /app
# Install dependencies sistem yang mungkin dibutuhkan
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Salin file requirements.txt ke dalam container
COPY requirements.txt .
# Install dependencies dari requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Install PyTorch dan Transformers (sudah dipindahkan ke requirements.txt)
# Jika ingin menggunakan versi CPU-only di Spaces gratis, Anda bisa uncomment baris di bawah:
# RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
# Salin seluruh file project ke dalam container
COPY . .
# Berikan akses write ke user non-root (syarat Hugging Face Spaces)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
COPY --chown=user . $HOME/app
# Expose port yang digunakan oleh Hugging Face Spaces
EXPOSE 7860
# Perintah untuk menjalankan aplikasi
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|