Spaces:
Runtime error
Runtime error
Download app.py from FajarHidaa/HumanPlus: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/spaces/FajarHidaa/HumanPlus/resolve/main/app.py
- Command line
-
hf download hf://spaces/FajarHidaa/HumanPlus/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FajarHidaa/HumanPlus/resolve/main/app.py
1.92 kB
| from transformers import pipeline | |
| # 1. Muat model zero-shot bahasa Indonesia yang ringan (~300MB) | |
| classifier = pipeline( | |
| "zero-shot-classification", | |
| model="MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7" | |
| ) | |
| # 2. Strukturkan data Anda: Sandingkan "Nama Produk" dengan "Link Affiliate Shopee" | |
| katalog_affiliate = [ | |
| { | |
| "nama": "Sepatu Lari Nike Air Running Shoes", | |
| "link": "https://shope.ee" | |
| }, | |
| { | |
| "nama": "Laptop Gaming Asus ROG Strix Ryzen 7", | |
| "link": "https://shope.ee" | |
| }, | |
| { | |
| "nama": "Kopi Arabika Gayo Aceh Premium 250gram", | |
| "link": "https://shope.ee" | |
| }, | |
| { | |
| "nama": "Keyboard Mekanikal Wireless Bluetooth RKG68", | |
| "link": "https://shope.ee" | |
| }, | |
| { | |
| "nama": "Jaket Gunung Outdoor Waterproof Anti Angin", | |
| "link": "https://shope.ee" | |
| } | |
| ] | |
| # Ambil daftar nama produk saja untuk dijadikan label klasifikasi bagi AI | |
| daftar_nama_produk = [produk["nama"] for produk in katalog_affiliate] | |
| # 3. Menerima input teks dari calon pembeli | |
| input_user = "Rekomendasikan keyboard komputer buat ngetik malam hari yang gak berisik dan tanpa kabel" | |
| # 4. Proses pencocokan makna teks secara instan oleh model AI | |
| hasil = classifier(input_user, candidate_labels=daftar_nama_produk) | |
| # 5. Tampilkan hasil rekomendasi teratas lengkap dengan Link Shopee-nya | |
| print(f"Permintaan User: '{input_user}'\n") | |
| print("🎯 Rekomendasi Produk untuk Anda:") | |
| # Mengambil 2 rekomendasi teratas (top_k=2) | |
| for i in range(2): | |
| nama_terpilih = hasil['labels'][i] | |
| skor_kecocokan = hasil['scores'][i] | |
| # Cari link affiliate yang sesuai dengan nama produk terpilih | |
| link_terpilih = next(p["link"] for p in katalog_affiliate if p["nama"] == nama_terpilih) | |
| print(f"\n{i+1}. {nama_terpilih}") | |
| print(f" 🔥 Kecocokan: {skor_kecocokan*100:.1f}%") | |
| print(f" 🛒 Beli di Shopee: {link_terpilih}") | |