yasirabd commited on
Commit
7928fb6
1 Parent(s): d359107
Files changed (3) hide show
  1. app.py +61 -0
  2. new_catalog.csv +283 -0
  3. product_catalog_vec.npy +3 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio
2
+ import numpy as np
3
+ import pandas as pd
4
+ import re
5
+ import fasttext
6
+ from huggingface_hub import hf_hub_download
7
+
8
+ model_path = hf_hub_download(repo_id="facebook/fasttext-id-vectors", filename="model.bin")
9
+ model = fasttext.load_model(model_path)
10
+ new_catalog = pd.read_csv('new_catalog.csv')
11
+ new_prodcatalog_vec = np.load('product_catalog_vec.npy')
12
+
13
+ def preprocess(text):
14
+ # remove units
15
+ regex_f = r'(\d+[.]{0,1}\d*\s*(kg|KG|Kg|ml|ML|Ml|mL|mil|ltr|LTR|liter|lt|Lt|LT|L|l|kilograms|%|gram|Gram|grm|GR|Gr|gr|g|G|wp|Wp|WP|METER|sp|Amper|Ahm|A|Btr|btr|ons|kapsul|cm|inc|cc|SL|sl))'
16
+ text = re.sub(regex_f, "", text)
17
+
18
+ # replace extra characters
19
+ text = text.replace('@', ' ')
20
+ text = text.replace('.', ' ')
21
+ text = text.replace('-', ' ')
22
+ text = text.replace('(', ' ')
23
+ text = text.replace(')', ' ')
24
+ text = text.strip()
25
+
26
+ # lowercase
27
+ text = text.lower()
28
+ return text
29
+
30
+ def extract_features(text):
31
+ return model.get_sentence_vector(text)
32
+
33
+ def cosine_similarity(v1, v2):
34
+ return np.dot(v1,v2) / (np.linalg.norm(v1)*np.linalg.norm(v2))
35
+
36
+ def get_most_similar(target, reference, n=5):
37
+ score = []
38
+ for r in reference:
39
+ if np.count_nonzero(r) == 0: # untuk menghindari score nan
40
+ score.append(0.)
41
+ else:
42
+ score.append(cosine_similarity(target, r))
43
+ # ranking descending
44
+ idx = np.array(score).argsort()[::-1][:n]
45
+ top_score = np.take(score, idx)
46
+ return idx, top_score
47
+
48
+ def predict_catalog(text):
49
+ text = preprocess(text)
50
+ X = extract_features(text)
51
+ idx, top_score = get_most_similar(X, new_prodcatalog_vec)
52
+ catalog = np.take(new_catalog['Product SKU'].values, idx)[0]
53
+ return catalog
54
+
55
+ demo = gradio.Interface(
56
+ fn=predict_catalog,
57
+ inputs=gradio.Textbox(placeholder="Enter a product name here..."),
58
+ outputs="label",
59
+ examples=[["NPK Kujang 30.6.8 @ 25 Kg"]])
60
+
61
+ demo.launch(share=True)
new_catalog.csv ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Product SKU,Product SKU Preprocessed
2
+ Urea Petro,urea petro
3
+ Urea PIM,urea pim
4
+ Urea Nitrea,urea nitrea
5
+ Urea Daun Buah,urea daun buah
6
+ Urea Pusri,urea pusri
7
+ Nitralite,nitralite
8
+ ZA Petro,za petro
9
+ ZA Plus Petro,za plus petro
10
+ ZK Petro,zk petro
11
+ Petro-CAS,petro cas
12
+ SP-36 Petro,sp 36 petro
13
+ Rock Phosphate PETRO,rock phosphate petro
14
+ Phosgreen,phosgreen
15
+ SP-26 Petro,sp 26 petro
16
+ Petro BioFertil,petro biofertil
17
+ Phonska Plus 15-15-15+9S+0.2Zn,phonska plus 15 15 15 9s 0.2zn
18
+ NPK Kebomas 12-12-17+2MgO+0.1Zn+0.2B+0.2Fe,npk kebomas 12 12 17 2mgo 0.1zn 0.2b 0.2fe
19
+ NPK Kebomas 12-6-22+3Mg,npk kebomas 12 6 22 3mg
20
+ NPK Kebomas 15-15-15,npk kebomas 15 15 15
21
+ PETROFERT  16-16-8+13S,petrofert  16 16 8 13s
22
+ Petro Niphos 20-20+13S,petro niphos 20 20 13s
23
+ FERTIGRES  16-20+13S ,fertigres  16 20 13s
24
+ NPK PIM 15-15-15,npk pim 15 15 15
25
+ Nitroku 16-16-16,nitroku 16 16 16
26
+ NITROSKA  15-9-20+1.5MgO+3S ,nitroska  15 9 20 1.5mgo 3s
27
+ NPK Kujang 15-15-15 ,npk kujang 15 15 15
28
+ NPK Kujang 30-6-8,npk kujang 30 6 8
29
+ Polivit-PIM 0-0-12+48S+9MgO,polivit pim 0 0 12 48s 9mgo
30
+ Solution N 28-10-10 + TE,solution n 28 10 10 te
31
+ Pelangi Agro 20-10-10,pelangi agro 20 10 10
32
+ Pelangi Jos 16-16-16 Coating Mikroba,pelangi jos 16 16 16 coating mikroba
33
+ Pelangi 16-16-16,pelangi 16 16 16
34
+ Pelangi 15-15-15,pelangi 15 15 15
35
+ NPK Pusri 15-15-15 ,npk pusri 15 15 15
36
+ Pelangi 20-10-18,pelangi 20 10 18
37
+ Pelangi 12-12-17-2,pelangi 12 12 17 2
38
+ NPK Pelangi 13-6-27-4,npk pelangi 13 6 27 4
39
+ Petro Nitrat 16-16-16,petro nitrat 16 16 16
40
+ Jeranti 18-10-14+2S+TE,jeranti 18 10 14 2s te
41
+ NPK Pusri 16-16-16,npk pusri 16 16 16
42
+ NPK Pusri 13-6-27-4Mg+0.65B,npk pusri 13 6 27 4mg 0.65b
43
+ NPK Petro Ningrat 12-11-20,npk petro ningrat 12 11 20
44
+ Kapur Pertanian Kebomas,kapur pertanian kebomas
45
+ MerokeZA,merokeza
46
+ MerokeROCK,merokerock
47
+ MerokeTSP,meroketsp
48
+ MerokeKKB 0-0-40-0.8B,merokekkb 0 0 40 0.8b
49
+ Suburkali Butir 0-0-30+17S+10MgO,suburkali butir 0 0 30 17s 10mgo
50
+ MerokeSOP KALI 0-0-52+18S,merokesop kali 0 0 52 18s
51
+ MerokeMOP,merokemop
52
+ KARATE PLUS BORONI 15.5-0-0+0.3S+26CaO,karate plus boroni 15.5 0 0 0.3s 26cao
53
+ Mutiara PARTNER 13-13-24,mutiara partner 13 13 24
54
+ Mutiara 16-16-16,mutiara 16 16 16
55
+ Mutiara PROFESSIONAL 9-25-25,mutiara professional 9 25 25
56
+ Mutiara SPRINTER 20-10-10,mutiara sprinter 20 10 10
57
+ MerokeCPN NK 15-15+TE,merokecpn nk 15 15 te
58
+ MerokeMAP 12-61-0,merokemap 12 61 0
59
+ MerokeMKP 0-52-34,merokemkp 0 52 34
60
+ Meroke Flex-G 8-9-39+3MgO,meroke flex g 8 9 39 3mgo
61
+ SS (AMMOPHOS) 16-20-0+12S,ss (ammophos) 16 20 0 12s
62
+ Mutiara GROWER 15-09-20+TE,mutiara grower 15 09 20 te
63
+ Mahkota ZA,mahkota za
64
+ RP Peru,rp peru
65
+ RP Mesir,rp mesir
66
+ Triple Super Phospate (TSP),triple super phospate (tsp)
67
+ Mahkota Kieserite,mahkota kieserite
68
+ Borat,borat
69
+ Mahkota MOP (KCL Canada),mahkota mop (kcl canada)
70
+ Mahkota NP 16-20-12S,mahkota np 16 20 12s
71
+ Mahkota 15-15-6-4,mahkota 15 15 6 4
72
+ Mahkota 12-6-22-3+TE,mahkota 12 6 22 3 te
73
+ Mahkota 12-12-17-2+TE,mahkota 12 12 17 2 te
74
+ Mahkota 13-6-27-4+0.5B,mahkota 13 6 27 4 0.5b
75
+ Mahkota 13-8-27-4+0.65B,mahkota 13 8 27 4 0.65b
76
+ Mahkota 15-15-15,mahkota 15 15 15
77
+ Mahkota 16-16-16,mahkota 16 16 16
78
+ Urecote,urecote
79
+ ZA Pak Tani,za pak tani
80
+ Fertiphos,fertiphos
81
+ Phosgro,phosgro
82
+ Fertiphos Sawit,fertiphos sawit
83
+ Magnesium Sulfate,magnesium sulfate
84
+ Fertikali,fertikali
85
+ Saprodap 16-20+12S,saprodap 16 20 12s
86
+ Pak Tani 15-15-15+TE,pak tani 15 15 15 te
87
+ Pak Tani Holland 15-15-15,pak tani holland 15 15 15
88
+ Pak Tani 16-16-16 Merah,pak tani 16 16 16 merah
89
+ Pak Tani 16-16-16 Biru,pak tani 16 16 16 biru
90
+ Pak Tani Sawit 15-15-6-4,pak tani sawit 15 15 6 4
91
+ Pak Tani Sawit 12-12-17-2,pak tani sawit 12 12 17 2
92
+ Pak Tani Sawit 13-6-27-4+0.65B,pak tani sawit 13 6 27 4 0.65b
93
+ Pak Tani Sawit 13-8-27-4+0.5B,pak tani sawit 13 8 27 4 0.5b
94
+ Pak Tani Sawit 7-6-35+B+Cu+Zn,pak tani sawit 7 6 35 b cu zn
95
+ Magnum 15-10-22-2Mg-3.8S,magnum 15 10 22 2mg 3.8s
96
+ Pak Tani Padi 21-14-7+2MgO+2S+TE,pak tani padi 21 14 7 2mgo 2s te
97
+ Pak Tani Fertila 13-6-27-4Mg+0.65B+TE,pak tani fertila 13 6 27 4mg 0.65b te
98
+ Pak Tani Fertila 18-6-14+5S,pak tani fertila 18 6 14 5s
99
+ Pak Tani Fertilla 18-8-10+3MgO+TE,pak tani fertilla 18 8 10 3mgo te
100
+ Pak Tani Fertila 21-14-7+4MgO+TE,pak tani fertila 21 14 7 4mgo te
101
+ Pak Tani Fertila 20-10-12+TE,pak tani fertila 20 10 12 te
102
+ Pak Tani Fertila 28-6-13+3MgO+TE,pak tani fertila 28 6 13 3mgo te
103
+ Pak Tani Fertila 8-15-19,pak tani fertila 8 15 19
104
+ Pak Tani Singkong 15-15-15,pak tani singkong 15 15 15
105
+ Pak Tani 12-12-17-2,pak tani 12 12 17 2
106
+ Pak Tani Sawit 12-6-22-3+TE,pak tani sawit 12 6 22 3 te
107
+ Pak Tani 9-15-6,pak tani 9 15 6
108
+ Pak Tani Fertila Qrop 12-6-24,pak tani fertila qrop 12 6 24
109
+ MKP PAK TANI 0-52-32,mkp pak tani 0 52 32
110
+ CPN PAK TANI 15-0-15,cpn pak tani 15 0 15
111
+ ULTRADAP 12-60-0,ultradap 12 60 0
112
+ NEO KRISTALON 12-12-36,neo kristalon 12 12 36
113
+ NEO KRISTALON 18-18-18-0.8Mg-2S+0.02Mn+0.036Zn+0.02B,neo kristalon 18 18 18 0.8mg 2s 0.02mn 0.036zn 0.02b
114
+ FERTILA 6-18-28-0.6Mg-5S+0.1B+0.01Zn+0.01Cu,fertila 6 18 28 0.6mg 5s 0.1b 0.01zn 0.01cu
115
+ FERTILA 12-6-24-0.75Mg-1.5CaO-5.6s,fertila 12 6 24 0.75mg 1.5cao 5.6s
116
+ FERTILA 0-16-17,fertila 0 16 17
117
+ PN PAK TANI 13-0-46+0.55Cl,pn pak tani 13 0 46 0.55cl
118
+ YaraVera,yaravera
119
+ Ammonium Sulfate,ammonium sulfate
120
+ YaraVita TRI-PHOLATE 0-0-0-70Mn+50Zn+25Fe+20B+20Cu+1Mo,yaravita tri pholate 0 0 0 70mn 50zn 25fe 20b 20cu 1mo
121
+ YaraLiva TROPICOTE 15.5-0-0+19Ca,yaraliva tropicote 15.5 0 0 19ca
122
+ YaraTera CALCINIT 15-0-0+26CaO,yaratera calcinit 15 0 0 26cao
123
+ YaraTera KRISTA K 13.7-0-46.3,yaratera krista k 13.7 0 46.3
124
+ YaraTera KRISTA MAP 12-61-0,yaratera krista map 12 61 0
125
+ YaraMila PALMAE 13-11-21+2MgO+0.2B,yaramila palmae 13 11 21 2mgo 0.2b
126
+ YaraLiva NITRABOR 15.5-0-0+25.6CaO+0.3B,yaraliva nitrabor 15.5 0 0 25.6cao 0.3b
127
+ YaraMila WINNER 15-09-20+1.3MgO+3.4S+TE,yaramila winner 15 09 20 1.3mgo 3.4s te
128
+ YaraMila UNIK 16-16-16,yaramila unik 16 16 16
129
+ YaraMila FASTER 25-7-7,yaramila faster 25 7 7
130
+ YARAMILA COMPLEX 12-11-18-3Mg-8S+0.02Zn+0.03Mn-2.56Ca+0.22Fe,yaramila complex 12 11 18 3mg 8s 0.02zn 0.03mn 2.56ca 0.22fe
131
+ YaraTera KRISTA MKP 0-52-34,yaratera krista mkp 0 52 34
132
+ Vrea,vrea
133
+ Nitroplus (ZA),nitroplus (za)
134
+ MK FOS 0-52-34,mk fos 0 52 34
135
+ HSP Astiva,hsp astiva
136
+ KSP,ksp
137
+ CAP TAWON 12-12-17-2Mg,cap tawon 12 12 17 2mg
138
+ CAP TAWON 15-15-15,cap tawon 15 15 15
139
+ CAP TAWON 15-15-6-4,cap tawon 15 15 6 4
140
+ CAP TAWON 16-16-16,cap tawon 16 16 16
141
+ CAP TAWON 18-12-6,cap tawon 18 12 6
142
+ CAP TAWON 19-9-19,cap tawon 19 9 19
143
+ HXAS,hxas
144
+ HX-MROPH,hx mroph
145
+ HX-MKP 0-50-35,hx mkp 0 50 35
146
+ HX-DAP 18-46-0,hx dap 18 46 0
147
+ DGW TSP,dgw tsp
148
+ DGW KNO3,dgw kno3
149
+ COCKHEAD 12-12-17-2Mg,cockhead 12 12 17 2mg
150
+ COCKHEAD 12-6-22-3Mg,cockhead 12 6 22 3mg
151
+ COCKHEAD 13-6-27-4Mg+0.65B,cockhead 13 6 27 4mg 0.65b
152
+ COCKHEAD 15-15-15,cockhead 15 15 15
153
+ COCKHEAD 15-15-6-4Mg,cockhead 15 15 6 4mg
154
+ COCKHEAD 16-16-16,cockhead 16 16 16
155
+ COCKHEAD 7-6-34,cockhead 7 6 34
156
+ COMPACTION DGW 15-15-15+TE,compaction dgw 15 15 15 te
157
+ BOOSTER DGW 12-6-22-3+TE,booster dgw 12 6 22 3 te
158
+ GOLD DGW 16-10-18,gold dgw 16 10 18
159
+ COCKHEAD 13-8-27-4+TE,cockhead 13 8 27 4 te
160
+ DGW 16-16-16+TE,dgw 16 16 16 te
161
+ ENTEC 13-10-20,entec 13 10 20
162
+ NITROPHOSKA 13-10-20,nitrophoska 13 10 20
163
+ ENTEC 20-10-10,entec 20 10 10
164
+ NITROPHOSKA PLUS 12-12-17-2,nitrophoska plus 12 12 17 2
165
+ NITROPHOSKA PERFECT 15-5-20,nitrophoska perfect 15 5 20
166
+ CANTIK CALCINIT,cantik calcinit
167
+ NITROPHOSKA 15-15-15,nitrophoska 15 15 15
168
+ Brucite,brucite
169
+ EMCOTE 13-11-11-7Ca-2Mg-6S+TE(0.08Cu+0.5B),emcote 13 11 11 7ca 2mg 6s te(0.08cu 0.5b)
170
+ EMCOTE 13-6-27-2+TE,emcote 13 6 27 2 te
171
+ MESTI-PATENHIJO 15-10-20+TE,mesti patenhijo 15 10 20 te
172
+ MESTIFOSKA 15-15-15+TE,mestifoska 15 15 15 te
173
+ EMCOTE 15-15-6-4+TE,emcote 15 15 6 4 te
174
+ MESTIFOS 15-20-0+12S,mestifos 15 20 0 12s
175
+ MESTI-PATENBIRU 16-16-16+TE,mesti patenbiru 16 16 16 te
176
+ MESTI-BOMBER 19-9-19+TE,mesti bomber 19 9 19 te
177
+ EMCOTE 20-6-14,emcote 20 6 14
178
+ MESTI-KP 0-52-34,mesti kp 0 52 34
179
+ Mesti-ZA,mesti za
180
+ Mesti-TSP,mesti tsp
181
+ Mesti-Rock,mesti rock
182
+ Mestikali,mestikali
183
+ Mestical,mestical
184
+ Mesti-GAS,mesti gas
185
+ Mestac,mestac
186
+ MestiKisrit,mestikisrit
187
+ Borate Evermax,borate evermax
188
+ KCL MAHKOTA,kcl mahkota
189
+ KCL,kcl
190
+ MINYAK KAYU PUTIH,minyak kayu putih
191
+ KERING,kering
192
+ PRIMA KUAT,prima kuat
193
+ BULDOK,buldok
194
+ ABACEL,abacel
195
+ NITREA,nitrea
196
+ SPONTAN,spontan
197
+ STARBAN,starban
198
+ GRAMOXONE,gramoxone
199
+ INDAMIN,indamin
200
+ CHLORMITE,chlormite
201
+ LINDOMIN,lindomin
202
+ AMISTARTOP,amistartop
203
+ BROADPLUS,broadplus
204
+ SUPREMO,supremo
205
+ SIDAFOS,sidafos
206
+ METINDO,metindo
207
+ ROUNDUP,roundup
208
+ REGENT,regent
209
+ MANUVER,manuver
210
+ SIDATAN XR,sidatan xr
211
+ DACONIL,daconil
212
+ TEBALO,tebalo
213
+ FOLICUR,folicur
214
+ MIPCINTA,mipcinta
215
+ DANGKE,dangke
216
+ AGUS,agus
217
+ ROUND UP,round up
218
+ NAGA,naga
219
+ AQUA,aqua
220
+ KNO PUTIH,kno putih
221
+ EMACEL,emacel
222
+ BENTAN,bentan
223
+ ATONIK,atonik
224
+ GRAMAXONE,gramaxone
225
+ TOPBAN,topban
226
+ ANTRACOL,antracol
227
+ MARSHAL,marshal
228
+ PHONSKA PLUS,phonska plus
229
+ STADIUM,stadium
230
+ MUSI,musi
231
+ SUMO,sumo
232
+ AVIDOR,avidor
233
+ ARJUNA,arjuna
234
+ PAMUNGKAS,pamungkas
235
+ DEMOLISH,demolish
236
+ BABLAS,bablas
237
+ BERAS,beras
238
+ METSULINDO PLUS,metsulindo plus
239
+ DITHANE,dithane
240
+ DECIS,decis
241
+ SEE TOP,see top
242
+ FURADAN,furadan
243
+ GANDASIL B,gandasil b
244
+ KANON,kanon
245
+ ENDURE,endure
246
+ PLENUM,plenum
247
+ GAS,gas
248
+ REGEN,regen
249
+ SIDAMETRIN,sidametrin
250
+ KEJORA,kejora
251
+ ALIKA,alika
252
+ ZIFLO,ziflo
253
+ ZA NS,za ns
254
+ DITHANE M 45,dithane m 45
255
+ RAMBO,rambo
256
+ BABLASS,bablass
257
+ BELT,belt
258
+ GANDASIL BUAH,gandasil buah
259
+ NK,nk
260
+ HOPPER,hopper
261
+ ABOLISI,abolisi
262
+ BENTAN BIRU,bentan biru
263
+ SCORE 250 EC,score 250 ec
264
+ PRIMA LIMA,prima lima
265
+ ZA,za
266
+ MATADOR,matador
267
+ CBA 6,cba 6
268
+ DMA 6,dma 6
269
+ GEMPUR,gempur
270
+ TRISULA,trisula
271
+ DMA,dma
272
+ MKP PAK TANI,mkp pak tani
273
+ ARES,ares
274
+ ELANG,elang
275
+ KSP TAWON,ksp tawon
276
+ UREA PRILL,urea prill
277
+ SIDAGREEN,sidagreen
278
+ SP,sp
279
+ SPGRO,spgro
280
+ MEROKE,meroke
281
+ KNO3,kno3
282
+ UREA PRIL,urea pril
283
+ ROGER,roger
product_catalog_vec.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a5b0f79682f532a218ba18af27dc9f46d17f5bf7cab16fc2a830a0c1de7e387
3
+ size 338528