Spaces:
Build error
A newer version of the Gradio SDK is available: 6.13.0
π 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
- Kunjungi https://huggingface.co/join
- Daftar atau login dengan akun yang sudah ada
2. Buat Access Token
- Buka https://huggingface.co/settings/tokens
- Klik "New token"
- Beri nama token (misal: "spaces-deployment")
- Pilih role "Write"
- Copy token tersebut (simpan dengan aman!)
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:
- app.py - Aplikasi Gradio dengan antarmuka web
- requirements.txt - Dependencies untuk Hugging Face Spaces
- README.md - Dokumentasi untuk Space Anda
- .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
- Login ke Hugging Face
- Klik profile Anda β "New Space"
- Isi informasi:
- Space name:
self-harm-detection(atau nama lain) - License: MIT
- Select SDK: Gradio
- Visibility: Public atau Private
- Space name:
- Klik "Create Space"
Step 2: Upload File via Web
- Di halaman Space Anda, klik tab "Files"
- Klik "Add file" β "Upload files"
- 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)
- 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
- Cek tab "Logs" untuk error messages
- Pastikan file
app.pyada di root directory - Pastikan
bestmodel_ArsitekturA_Bd.pthada di root directory - 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.pysudah diupload - File
requirements.txtsudah diupload - File
README.mdsudah diupload - File
.gitattributessudah diupload - File
bestmodel_ArsitekturA_Bd.pthsudah 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:
- Test aplikasi dengan berbagai input
- Share link dengan dosen pembimbing
- Tambahkan link di dokumentasi thesis
- Buat screenshot untuk laporan
π Referensi
Catatan: Jika ada pertanyaan atau masalah, silakan cek documentation atau tanya di Hugging Face forums!