Spaces:
Runtime error
Runtime error
File size: 1,924 Bytes
2bbccc4 | 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 | 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}")
|