meme-self-harm-detection-model / DEPLOYMENT_GUIDE.md
elsaelisa09's picture
Upload 6 files
f9b5720 verified

A newer version of the Gradio SDK is available: 6.13.0

Upgrade

πŸš€ Panduan Deploy Model ke Hugging Face Spaces

Dokumen ini berisi langkah-langkah lengkap untuk deploy model Anda ke Hugging Face Spaces menggunakan Gradio.

πŸ“‹ Persiapan

1. Buat Akun Hugging Face

2. Buat Access Token

3. Install Git LFS (Large File Storage)

Git LFS diperlukan untuk upload file model yang besar.

Windows:

# Download dari https://git-lfs.github.com/
# Atau gunakan chocolatey:
choco install git-lfs

# Setelah install:
git lfs install

Verifikasi instalasi:

git lfs version

πŸ“¦ File yang Sudah Disiapkan

Di folder deploy-hf/ sudah tersedia semua file yang diperlukan:

  1. app.py - Aplikasi Gradio dengan antarmuka web
  2. requirements.txt - Dependencies untuk Hugging Face Spaces
  3. README.md - Dokumentasi untuk Space Anda
  4. .gitattributes - Konfigurasi Git LFS untuk file model

Yang masih perlu ditambahkan:

  • bestmodel_ArsitekturA_Bd.pth - File model dari folder output/

🎯 Langkah-Langkah Deploy

Opsi 1: Deploy via Web Interface (Mudah - Direkomendasikan) ⭐

Step 1: Buat New Space

  1. Login ke Hugging Face
  2. Klik profile Anda β†’ "New Space"
  3. Isi informasi:
    • Space name: self-harm-detection (atau nama lain)
    • License: MIT
    • Select SDK: Gradio
    • Visibility: Public atau Private
  4. Klik "Create Space"

Step 2: Upload File via Web

  1. Di halaman Space Anda, klik tab "Files"
  2. Klik "Add file" β†’ "Upload files"
  3. Upload file berikut satu per satu:
    • app.py (dari folder deploy-hf)
    • requirements.txt (dari folder deploy-hf)
    • README.md (dari folder deploy-hf)
    • .gitattributes (dari folder deploy-hf)
    • bestmodel_ArsitekturA_Bd.pth (dari folder output)
  4. Commit semua file

Step 3: Tunggu Build

  • Space akan otomatis build aplikasi Anda
  • Lihat progress di tab "Logs"
  • Proses build biasanya 3-5 menit
  • Setelah selesai, aplikasi akan otomatis running!

Opsi 2: Deploy via Git (Advanced)

Step 1: Clone Space Repository

# Ganti USERNAME dan SPACE_NAME dengan milik Anda
git clone https://huggingface.co/spaces/USERNAME/SPACE_NAME
cd SPACE_NAME

Step 2: Copy File ke Repository

# Dari direktori space, copy file yang diperlukan
# Sesuaikan path berikut dengan lokasi folder thesis Anda

# Copy semua file dari deploy-hf
Copy-Item "C:\Users\elsae\Downloads\thesis-elsa-main\thesis-elsa-main\ars1-id\deploy-hf\*" -Destination "." -Recurse

# Copy model file dari output
Copy-Item "C:\Users\elsae\Downloads\thesis-elsa-main\thesis-elsa-main\ars1-id\output\bestmodel_ArsitekturA_Bd.pth" -Destination "."

Step 3: Setup Git LFS untuk Model File

# Track file .pth dengan Git LFS
git lfs track "*.pth"

# Add .gitattributes (sudah ada dari copy)
git add .gitattributes

Step 4: Commit dan Push

# Add semua file
git add .

# Commit
git commit -m "Initial commit: Add multimodal self-harm detection model"

# Push ke Hugging Face
git push

Jika diminta username dan password:

  • Username: username Hugging Face Anda
  • Password: gunakan Access Token yang sudah dibuat (bukan password akun)

πŸ”§ Troubleshooting

Error: "File too large"

Pastikan Git LFS sudah terinstall dan file .pth sudah di-track:

git lfs track "*.pth"
git add .gitattributes
git add bestmodel_ArsitekturA_Bd.pth
git commit -m "Track model with LFS"
git push

Error: "Module not found"

Periksa requirements.txt, pastikan semua dependencies tercantum.

Space tidak running

  1. Cek tab "Logs" untuk error messages
  2. Pastikan file app.py ada di root directory
  3. Pastikan bestmodel_ArsitekturA_Bd.pth ada di root directory
  4. Periksa apakah ada typo di nama file

Model loading error

Jika ada error saat load model, pastikan:

  • File model ada dan tidak corrupt
  • Architecture di app.py match dengan model yang di-train

🎨 Kustomisasi

Mengubah Title dan Description

Edit file README.md:

---
title: Nama Space Anda
emoji: πŸ”
colorFrom: blue
colorTo: purple
---

Menambahkan Contoh

Edit app.py, tambahkan di bagian Gradio interface:

gr.Examples(
    examples=[
        ["example1.jpg", "Example text 1"],
        ["example2.jpg", "Example text 2"],
    ],
    inputs=[image_input, text_input]
)

Mengubah Theme

Edit app.py, tambahkan parameter theme:

with gr.Blocks(theme=gr.themes.Soft(), title="...") as demo:

πŸ“Š Monitoring

Melihat Logs

  • Kunjungi halaman Space Anda
  • Klik tab "Logs"
  • Lihat real-time logs aplikasi

Analytics

  • Tab "Analytics" menampilkan:
    • Jumlah visitors
    • Jumlah predictions
    • Usage statistics

πŸ”’ Privacy & Security

Private Space

Jika Space Anda private:

  • Hanya Anda yang bisa akses
  • Bisa share dengan specific users

Public Space

  • Siapa saja bisa akses
  • Baik untuk demo dan portfolio
  • Catatan: Pastikan tidak ada data sensitif!

πŸ“± Sharing

Setelah deploy berhasil, share link Space Anda:

https://huggingface.co/spaces/USERNAME/SPACE_NAME

Anda juga bisa embed Space ke website:

<iframe
  src="https://USERNAME-SPACE_NAME.hf.space"
  width="850"
  height="450"
></iframe>

βœ… Checklist Akhir

  • Akun Hugging Face sudah dibuat
  • Access token sudah dibuat (jika pakai Git)
  • Git LFS sudah terinstall (jika pakai Git)
  • Space sudah dibuat di Hugging Face
  • File app.py sudah diupload
  • File requirements.txt sudah diupload
  • File README.md sudah diupload
  • File .gitattributes sudah diupload
  • File bestmodel_ArsitekturA_Bd.pth sudah diupload
  • Space berhasil build tanpa error
  • Aplikasi bisa diakses dan berfungsi
  • Test dengan contoh input

πŸŽ‰ Selamat!

Jika semua langkah di atas selesai, model Anda sudah berhasil di-deploy!

Next Steps:

  1. Test aplikasi dengan berbagai input
  2. Share link dengan dosen pembimbing
  3. Tambahkan link di dokumentasi thesis
  4. Buat screenshot untuk laporan

πŸ“š Referensi


Catatan: Jika ada pertanyaan atau masalah, silakan cek documentation atau tanya di Hugging Face forums!