File size: 2,092 Bytes
7ac6163
 
 
 
 
 
5ee5954
 
7ac6163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1db98e
 
7ac6163
 
 
c1db98e
 
 
 
7ac6163
 
 
 
 
 
 
c1db98e
e8c02eb
c1db98e
7ac6163
 
 
 
c1db98e
 
7ac6163
 
c1db98e
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# ============================================
# CrownCode Backend - Hugging Face Spaces
# ============================================
# SDK: Docker | Hardware: CPU Basic (Free)
# ============================================

# Python 3.11 slim imajını kullan
FROM python:3.11-slim

# Çalışma dizini
WORKDIR /app

# Ortam değişkenleri
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    TRANSFORMERS_CACHE=/app/.cache/huggingface \
    HF_HOME=/app/.cache/huggingface \
    TORCH_HOME=/app/.cache/torch

# Sistem bağımlılıkları + FFmpeg
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    libsndfile1 \
    git \
    curl \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Cache dizinleri
RUN mkdir -p /app/.cache/huggingface /app/.cache/torch \
    && chmod -R 777 /app/.cache

# Requirements (önce kopyala - Docker cache için)
COPY requirements.txt .

# PyTorch CPU versiyonu + diğer paketler
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu \
    && pip install --no-cache-dir -r requirements.txt \
    && pip install --no-cache-dir "huggingface-hub>=0.20.0"

# Uygulama kodu
COPY app ./app
COPY startup.py .

# Models dizini — startup.py çalışınca doldurulacak
RUN mkdir -p /app/models

# Hugging Face Spaces için non-root kullanıcı (güvenlik)
RUN useradd -m -u 1000 user \
    && chown -R user:user /app
USER user

ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    AURIS_MODELS_REPO=Rthur2003/auris-models \
    MODELS_DIR=/app/models

# Hugging Face Spaces varsayılan port: 7860
EXPOSE 7860

# Health check — model download ~2-3 dk sürebilir, start-period uzun
HEALTHCHECK --interval=30s --timeout=10s --start-period=180s --retries=5 \
    CMD curl -f http://localhost:7860/api/health || exit 1

# Başlat: önce modelleri indir, sonra API'yi ayağa kaldır
CMD ["sh", "-c", "python startup.py && uvicorn app.main:app --host 0.0.0.0 --port 7860"]