Kemas M. Aryadary Rasyad commited on
Commit
6afc17d
Β·
1 Parent(s): 1f3b428

git add dockerfile and new model

Browse files
Files changed (3) hide show
  1. Dockerfile +27 -0
  2. api.py +1 -1
  3. requirements.txt +4 -2
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1. Gunakan image Python yang ringan sebagai dasar
2
+ FROM python:3.10-slim
3
+
4
+ # 2. Atur direktori kerja di dalam kontainer Docker
5
+ WORKDIR /app
6
+
7
+ # 3. Install dependencies sistem yang diperlukan untuk OpenCV / Pillow jika dibutuhkan
8
+ RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ libgl1-mesa-glx \
11
+ libglib2.0-0 \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # 4. Salin file requirements.txt terlebih dahulu (untuk memanfaatkan cache Docker)
15
+ COPY requirements.txt .
16
+
17
+ # 5. Install semua library Python, pastikan menggunakan torch versi CPU agar ringan
18
+ RUN pip install --no-cache-dir -r requirements.txt
19
+
20
+ # 6. Salin semua file dari project lokal ke dalam kontainer Docker
21
+ COPY . .
22
+
23
+ # 7. Berikan akses read/write ke folder kerja (wajib untuk Hugging Face Spaces Docker)
24
+ RUN chmod -R 777 /app
25
+
26
+ # 8. Jalankan FastAPI menggunakan Uvicorn di port 7860 (Port default Hugging Face)
27
+ CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
api.py CHANGED
@@ -39,7 +39,7 @@ logger = logging.getLogger(__name__)
39
 
40
  # ── 1. LOGIKA DOWNLOAD MODEL OTOMATIS (Ditaruh paling atas agar kelar sebelum startup) ──
41
  MODEL_DIR = os.path.join(BASE_DIR, "models")
42
- MODEL_PATH = os.path.join(MODEL_DIR, "best_models.pth")
43
 
44
  def download_model():
45
  if not os.path.exists(MODEL_DIR):
 
39
 
40
  # ── 1. LOGIKA DOWNLOAD MODEL OTOMATIS (Ditaruh paling atas agar kelar sebelum startup) ──
41
  MODEL_DIR = os.path.join(BASE_DIR, "models")
42
+ MODEL_PATH = os.path.join(MODEL_DIR, "best_models_fx.pth")
43
 
44
  def download_model():
45
  if not os.path.exists(MODEL_DIR):
requirements.txt CHANGED
@@ -1,5 +1,7 @@
1
- torch --index-url https://download.pytorch.org/whl/cpu
2
- torchvision --index-url https://download.pytorch.org/whl/cpu
 
 
3
  Pillow>=9.0.0
4
  scikit-learn>=1.0.0
5
  matplotlib>=3.5.0
 
1
+ --index-url https://download.pytorch.org/whl/cpu
2
+
3
+ torch
4
+ torchvision
5
  Pillow>=9.0.0
6
  scikit-learn>=1.0.0
7
  matplotlib>=3.5.0