hjianganthony commited on
Commit
6db931d
·
1 Parent(s): 784927b

Upload Gradio config

Browse files
data/brand_belong_category_dict.json ADDED
The diff for this file is too large to render. See raw diff
 
data/offer_retailer.csv ADDED
@@ -0,0 +1,386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ OFFER,RETAILER,BRAND
2
+ Spend $50 on a Full-Priced new Club Membership,SAMS CLUB,SAMS CLUB
3
+ "Beyond Meat® Plant-Based products, spend $25",,BEYOND MEAT
4
+ Good Humor Viennetta Frozen Vanilla Cake,,GOOD HUMOR
5
+ "Butterball, select varieties, spend $10 at Dillons Food Store",DILLONS FOOD STORE,BUTTERBALL
6
+ "GATORADE® Fast Twitch®, 12-ounce 12 pack, at Amazon Storefront*",AMAZON,GATORADE
7
+ Emmy's Organics® Cookies OR Brownie Snaps,,EMMYS POP UP
8
+ "Dr Pepper®, Regular OR Zero Sugar Strawberries and Cream 12 pack, at select retailers",UNITED SUPERMARKETS,DR PEPPER
9
+ "Arnold, Brownberry, Oroweat® Small Slice bread, at Walmart",WALMART,ARNOLD BROWNBERRY OROWEAT
10
+ Barilla® Pesto Sauce,,BARILLA
11
+ "Any General Mills™ products, buy 2
12
+ Good Rewards Members Only",,ANNIES HOMEGROWN GROCERY
13
+ Egglife Egg White Wraps at Aldi,ALDI,EGGLIFE
14
+ Spend $20 at Zaxby's,ZAXBYS,ZAXBYS
15
+ Spend $10 at Subway,SUBWAY,SUBWAY
16
+ "DOVE® Chocolate, select sizes, buy 1",,DOVE CHOCOLATE
17
+ Hellmann's® OR Best Foods® Garlic Aioli OR Spicy Mayonnaise,,HELLMANNS BEST FOODS
18
+ "M&M'S®, select sizes, buy 1",,M&MS
19
+ "GATORLYTE® OR GATORADE™ Fit Single Serve Bottle, select varieties, buy 2",,GATORADE
20
+ "Beyond Steak™ Plant-Based seared tips, 10 ounce at Target",TARGET,BEYOND MEAT
21
+ Red Gold Tomato Ketchup,,RED GOLD
22
+ Gillette Venus ® for Pubic Hair & Skin spend $20,,GILLETTE VENUS
23
+ Spend $140 at Shaws,SHAWS,SHAWS
24
+ "L'Oréal Paris Hair color, select varieties, spend $19 at Target",TARGET,LOREAL PARIS HAIR COLOR
25
+ Simply Spiked™ Lemonade 12 pack+,,SIMPLY SPIKED
26
+ "Gorton's, at select retailers",SHOP RITE,GORTONS
27
+ Shop 2 times at ACME,ACME,ACME
28
+ "Butterball, select varieties, spend $10 at Ralphs",RALPHS,BUTTERBALL
29
+ "Beyond Steak™ Plant-Based seared tips, 10 ounce, buy 2 at H-E-B",H-E-B,BEYOND MEAT
30
+ "Butterball, select varieties, Spend $10 at Ruler Foods",RULER FOODS,BUTTERBALL
31
+ Spend $20 at KFC,KFC,KFC
32
+ Spend $15 at Nekter,NEKTER JUICE BAR,NEKTER
33
+ Order online at Zaxbys.com,ZAXBYS,ZAXBYS
34
+ "Butterball, select varieties, spend $10 at King Soopers",KING SOOPERS,BUTTERBALL
35
+ Order from Casey's app or Caseys.com,CASEYS GENERAL STORE,CASEYS GENERAL STORE
36
+ "Tru-Ray® Premium Construction Paper, spend $10",,TRURAY
37
+ "Flonase Allergy Relief, at Walmart",WALMART,FLONASE
38
+ Spend $25 at KFC,KFC,KFC
39
+ "Gorton's Air Fried Butterfly Shrimp, at Walmart",WALMART,GORTONS
40
+ "CESAR® Wet Dog Food, spend $20",,CESAR
41
+ "TWIX®, select sizes",,TWIX
42
+ "M&M'S® chocolate candies, select varieties",,M&MS
43
+ "Hidden Valley® Ranch Salad Dressing OR Secret Sauce, select varieties",,HIDDEN VALLEY RANCH
44
+ Spend $210 at Randalls,RANDALLS,RANDALLS
45
+ "Cooked Perfect® Meatballs, at Walmart",WALMART,COOKED PERFECT
46
+ Spend $25 at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
47
+ "Perfect Keto Barista Blend Collagen & MCTs, online at Amazon",AMAZON,PERFECT KETO
48
+ "Creativity Street®, spend $10",,CREATIVITY STREET
49
+ "Crunchmaster® Crackers, spend $4",,CRUNCHMASTER
50
+ "Tyson Products, select varieties, spend $20 at Sam's Club",SAMS CLUB,BALL PARK FRANK
51
+ "L'Oréal Paris Makeup, spend $35 at Target",TARGET,LOREAL PARIS COSMETICS
52
+ Spend $25 at Subway,SUBWAY,SUBWAY
53
+ Any Vons receipt,VONS,VONS
54
+ "Chosen Foods® Mayo, select varieties",,CHOSEN FOODS
55
+ "L'Oréal Paris Men Expert hair color, spend $19 at Walmart",WALMART,LOREAL PARIS HAIR COLOR
56
+ Spend $185 at Shaws,SHAWS,SHAWS
57
+ Spend $150 at Vons,VONS,VONS
58
+ "Wine from TheBarrelRoom.com, spend $30",GALLO.COM,ALAMOS
59
+ "General Mills™ products, select brands, spend $35",,ANNIES HOMEGROWN GROCERY
60
+ "PepsiCo® Beverage, 7.5-ounce 10 pack, select varieties, at Amazon Storefront*",AMAZON,PEPSI
61
+ "Sara Lee® bread, select varieties, buy 2 at Walmart®",WALMART,SARA LEE
62
+ "Sara Lee® or Alfaros® Artesano bread, buy 5",,ALFAROS
63
+ "Bai® Antioxidant, 6 pack, buy 2 at Walmart",WALMART,BAI
64
+ Spend $5 in-store at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
65
+ "Reese's Chocolate Cones, 8 count at GIANT OR MARTIN’S",MARTINS FOODS,KLONDIKE
66
+ Spend $25 at Fresh Thyme Market,FRESH THYME MARKET,FRESH THYME MARKET
67
+ Any Albertsons receipt,ALBERTSONS,ALBERTSONS
68
+ Shop 2 times at Albertsons,ALBERTSONS,ALBERTSONS
69
+ Select beverages AND prepared food items at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
70
+ QUEEN V® The VIP & The Wingwoman Soft Touch Silicone Vibrator at Walmart,WALMART,QUEEN V
71
+ "Back to the Roots Grow Seed Starting Pots OR Germination Trays, at Walmart or Target",TARGET,BACK TO THE ROOTS
72
+ "Dove Hand Wash, select varieties, buy 2 at Target",TARGET,DOVE
73
+ "Frutero Ice Cream, 1 pint",,FRUTERO
74
+ Red Gold Tomato Juice,,RED GOLD
75
+ "Bio-Oil® Skincare Oil OR Gel, select varieties",,BIO OIL
76
+ Spend $65 at Albertsons,ALBERTSONS,ALBERTSONS
77
+ "Welch's®Fruit Snacks, select varieties, buy 2",,WELCHS FRUIT SNACKS
78
+ Talenti Mini Bars,,TALENTI
79
+ Visit OR order online from Casey's 7 times,CASEYS GENERAL STORE,CASEYS GENERAL STORE
80
+ "Simply Spiked™ Signature Peach 12-pack or larger, buy 2",,SIMPLY SPIKED
81
+ "Molson Coors®, select varieties, 12 pack+",,COORS LIGHT
82
+ "Welch's® Zero Sugar Fruity Bites, 6 pack+, online at Amazon",AMAZON,WELCHS FRUIT SNACKS
83
+ "PepsiCo® Variety Pack, select varieties, at Amazon Storefront*",AMAZON,PEPSI
84
+ Spend $100 at Vons,VONS,VONS
85
+ Spend $15 at Subway,SUBWAY,SUBWAY
86
+ Spend $35 at Fresh Thyme Market,FRESH THYME,FRESH THYME MARKET
87
+ Sign up for The Club Card or The Club+ Card full-priced membership* (New Members Only),BJS WHOLESALE,BJS WHOLESALE
88
+ "Marinela® sweet baked goods, buy 2",,MARINELA
89
+ "Back to the Roots Soils, select varieties and sizes, at Walmart",WALMART,BACK TO THE ROOTS
90
+ "Any General Mills™ products, spend $60",,ANNIES HOMEGROWN
91
+ "Welch's® Fruit Snacks, select varieties, 6 count+, buy 3",,WELCHS FRUIT SNACKS
92
+ Spend $90 at Tom Thumb,TOM THUMB,TOM THUMB
93
+ Spend $5 on single-serve prepared food items at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
94
+ "Coors Light®, Miller Lite® OR VIZZY™ 12 pack+",,VIZZY
95
+ "Cooked Perfect® Meatballs, Homestyle OR Turkey, at Walmart",WALMART,COOKED PERFECT
96
+ 12 Pack OR 2 Liter AND Whole Pizza Pie at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
97
+ "General Mills™ products, select brands, spend $7 at Convenience Stores",,ANNIES HOMEGROWN GROCERY
98
+ Gillette Venus ® for Pubic Hair & Skin,,GILLETTE VENUS
99
+ "Barilla® Pasta, select varieties, buy 2",,BARILLA
100
+ Little Bites® Spend $10 at Walmart®,WALMART,ENTENMANNS
101
+ Envy Apples pre-packed bags,,ENVY
102
+ Shop 2 times at Tom Thumb,TOM THUMB,TOM THUMB
103
+ "Ben & Jerry's Frozen Creme Brulee Non Dairy Dessert, 16 ounce",,BEN AND JERRYS
104
+ "Purex® laundry detergent, select varieties, at Walmart",WALMART,PUREX
105
+ Whole Pizza at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
106
+ Shop 2 times at Safeway,SAFEWAY,SAFEWAY
107
+ "Any General Mills™ products, spend $30",,ANNIES HOMEGROWN
108
+ "Ben & Jerry's® Doggie Desserts, 4 count",,BEN AND JERRYS
109
+ Sol® 6 pack+,,SOL CERVEZA
110
+ "George's Farmers Market Chicken Wings, at Sam's Club",SAMS CLUB,GEORGES FARMERS MARKET
111
+ "Michael Angelo's® OR Rao's® Frozen Entrees, spend $10",,RAO'S
112
+ "Sargento Sliced Cheese, spend $25",,SARGENTO
113
+ "Sargento Sliced Cheese, spend $12",,SARGENTO
114
+ Country Crock® Plant Based Butter at Walmart,WALMART,COUNTRY CROCK PLANT BUTTER
115
+ "Perfect Keto Beauty + Sleep Collagen, online at Amazon",AMAZON,PERFECT KETO
116
+ "DOVE® chocolate, select varieties",,DOVE CHOCOLATE
117
+ Simply Spiked™ 12 pack+,,SIMPLY SPIKED
118
+ "Perfect Keto Bars, online at Amazon",AMAZON,PERFECT KETO
119
+ "Gillette Venus ® for Pubic Hair & Skin, spend $20",,GILLETTE VENUS
120
+ AleveX™ at Walmart,WALMART,ALEVE
121
+ "Envy Apples, pre-packed bags",,ENVY
122
+ "Ben & Jerry's Frozen Sugar Cookie Dough Chunks, 8 ounce",,BEN AND JERRYS
123
+ "L’Oréal Paris Men Expert hair color, spend $9 at Walmart",WALMART,LOREAL PARIS HAIR COLOR
124
+ "Reese's Peanut Butter Bar, 6 count, at GIANT OR MARTIN’S",THE GIANT CO,GOOD HUMOR
125
+ "Magnum Non-Dairy Hazelnut Crunch Ice Cream Bars, 3 count",,MAGNUM ICE CREAM
126
+ "Butterball, select varieties, spend $10 at Fred Meyer",FRED MEYER,BUTTERBALL
127
+ "Thomas'® Bagel Thins®, buy 2",,THOMAS
128
+ Spend $60 at TGI Friday's,TGI FRIDAYS,TGI FRIDAYS
129
+ "Artesano® buns, buy 2 at Walmart®",WALMART,SARA LEE ARTESANO
130
+ "STARBURST®, select sizes, buy 1",,STARBURST
131
+ Fresh Step® Outstretch® Cat Litter,,FRESH STEP
132
+ "Sara Lee® or Alfaros® Artesano bread, spend $8",,ALFAROS
133
+ "Back to the Roots Dry Plant Food, 5 pounds, at The Home Depot",THE HOME DEPOT,BACK TO THE ROOTS
134
+ "Burt's Bees Sensitive Lotions and Creams, select varieties, at Walmart",WALMART,BURTS BEES
135
+ "Durex® Massage & Play 2 in 1 Pleasure Gel, select varieties, at Walmart or Target",TARGET,DUREX
136
+ "Coors Light®, Miller Lite® OR VIZZY™ 12 packs+, buy 4",,VIZZY
137
+ LIFE SAVERS®,,LIFESAVERS
138
+ "Butterball, select varieties, spend $10 at Kroger",KROGER,BUTTERBALL
139
+ "RESPAWN® by 5® GUM, at Walmart",WALMART,5 GUM
140
+ "Back to the Roots Garden Soil, 1 cubic foot, at Lowe's Home Improvement",LOWES HOME IMPROVEMENT,BACK TO THE ROOTS
141
+ "SiO® Beauty Patches, online at Siobeauty.com",SIOBEAUTY.COM,SIO BEAUTY
142
+ Wesson® Oil Products,,WESSON
143
+ "Bubbies Pickles, Sauerkraut, and Condiments at Whole Foods or Sprouts",SPROUTS FARMERS MARKET,BUBBIES
144
+ Michael Angelo's® Sauce at Walmart,WALMART,MICHAEL ANGELO'S
145
+ Spend $155 at Pavilions,PAVILIONS,PAVILIONS
146
+ CESAR® Wet Dog Food Singles,,CESAR
147
+ Spend $90 at ACME,ACME,ACME
148
+ "Hidden Valley® Ranch Seasoning Mix Packet, 1 count",,HIDDEN VALLEY RANCH
149
+ "Sargento® products, select varieties",,SARGENTO
150
+ "Welch's® Fruit Snacks, 250 count, online at Amazon",AMAZON,WELCHS FRUIT SNACKS
151
+ "Ben & Jerry's®, select varieties",,BEN AND JERRYS
152
+ Simply Spiked™ Signature Peach 12 pack+,,SIMPLY SPIKED
153
+ "Beech-Nut snacks, select varieties",,BEECHNUT
154
+ "Sargento® products, select varieties, buy 3",,SARGENTO
155
+ Spend $250 at ACME,ACME,ACME
156
+ Wings OR Cheesy Breadsticks at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
157
+ "Butterball, select varieties, spend $10 at Smith's",SMITHS,BUTTERBALL
158
+ "Perfect Keto Collagen Peptides, online at Amazon",AMAZON,PERFECT KETO
159
+ "Perfect Keto MCT Oil Powder, online at Amazon",AMAZON,PERFECT KETO
160
+ Hellmann's® OR Best Foods® AND Sargento® Cheese Slices,,HELLMANNS BEST FOODS
161
+ Brita® Pitcher AND Filter,,BRITA
162
+ Spend $90 at Star Market,STAR MARKET,STAR MARKET
163
+ "SNICKERS®, select sizes, buy 1",,SNICKERS
164
+ "Kodiak® products, select varieties, spend $10",,KODIAK CAKES FLAPJACK & WAFFLE MIX
165
+ Bays® English Muffins,,BAYS
166
+ "Super Coffee, 12 ounce single serve, buy 3",,SUPER COFFEE
167
+ "Sara Lee® bread select varieties, buy 2",WALMART,SARA LEE
168
+ GOYA® Coconut Water,,GOYA
169
+ Spend $35 at TGI Friday's,TGI FRIDAYS,TGI FRIDAYS
170
+ Spend $110 at Randalls,RANDALLS FOOD MARKETS,RANDALLS
171
+ "Reese's Chocolate Cones, 8 count at GIANT OR MARTIN’S",GIANT FOOD,KLONDIKE
172
+ Whole Pizza Pie at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
173
+ Shop 2 times at Star Market,STAR MARKET,STAR MARKET
174
+ "Hidden Valley® Ranch Seasoning, select varieties",,HIDDEN VALLEY RANCH
175
+ "General Mills™ products, select varieties, spend $12",,ANNIES HOMEGROWN GROCERY
176
+ Blue Apron Meal Kits,BLUE APRON,BLUE APRON
177
+ "Aleve® products, select varieties, 80 count+ at Walmart",WALMART,ALEVE
178
+ "Welch's® Juicefuls® Juicy Fruit Snacks, 14 count, at Target",TARGET,WELCHS FRUIT SNACKS
179
+ "Welch's® Fruit Snacks, select varieties, 6 count+, buy 2",,WELCHS FRUIT SNACKS
180
+ "Sign up for McAlister's Deli Rewards, tap for details",MCALISTERS DELI,MCALISTERS DELI
181
+ "Arbos Cheese Dip, 12 ounce, buy at Central Market",CENTRAL MARKET,ARBOS
182
+ L'Oréal Paris Excellence Hair Color at Target,TARGET,LOREAL PARIS HAIR COLOR
183
+ "Kradle, select varieties, spend $20 at Walmart",WALMART,KRADLE
184
+ Frozen OR Fountain Drink at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
185
+ "Arnold, Brownberry, Oroweat® Keto bread, buy 2",,ARNOLD BROWNBERRY OROWEAT
186
+ Shop 2 times at Shaw's,SHAWS,SHAWS
187
+ "Welch's®Fruit Snacks, spend $8",,WELCHS FRUIT SNACKS
188
+ "Children's Astepro® Allergy, 22 count at Dollar General",DOLLAR GENERAL STORE,ASTEPRO
189
+ Spend $10 in-store at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
190
+ "Fresh bakery item, select varieties, at Casey's",CASEYS GENERAL STORE,CASEYS GENERAL STORE
191
+ "SNICKERS® chocolate candy bar, select varieties",,SNICKERS
192
+ Rao's® Frozen Pizza,,RAO'S
193
+ "GATORADE® Fast Twitch®, 12-ounce single serve, buy 2 at Kroger",FRED MEYER,GATORADE
194
+ "Bimbo® sweet baked goods, buy 2",,BIMBO
195
+ Any Shaw's receipt,SHAWS,SHAWS
196
+ "Gorton's, at select retailers",STOP & SHOP,GORTONS
197
+ "Butterball, select varieties, spend $10 at Food 4 Less",FOOD4LESS,BUTTERBALL
198
+ NatuChips® Plantain Chips,,NATUCHIPS
199
+ "Beech-Nut pouches, buy 8",,BEECHNUT
200
+ Spend $45 at Zaxby's,ZAXBYS,ZAXBYS
201
+ "Back to the Roots Raised Bed Gardening Kit with Soil, Seeds and Plant Food, at Target",TARGET,BACK TO THE ROOTS
202
+ "Ben & Jerry's®, select varieties, spend $12",,BEN AND JERRYS
203
+ Any ACME receipt,ACME,ACME
204
+ Spend $220 at Tom Thumb,TOM THUMB,TOM THUMB
205
+ "Promised Land Dairy Milk, 52-ounce",,PROMISED LAND DAIRY
206
+ "Welch's® Fruit 'n Yogurt® Snacks, 18 count, at Walmart",WALMART,WELCHS FRUIT SNACKS
207
+ Hidden Valley® Ranch Seasoning Shaker,,HIDDEN VALLEY RANCH
208
+ "CORE® Hydration, select varieties, at Walmart",WALMART,CORE HYDRATION
209
+ When you join Costco as a Gold Star Member* (New Members Only),COSTCO,COSTCO
210
+ Whole pizza at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
211
+ Spend $40 at Farmer Boys,FARMER BOYS,FARMER BOYS
212
+ "Colgate® Toothpaste AND Colgate® Toothbrush, select varieties at Walmart or Target",TARGET,COLGATE TOOTHBRUSHES
213
+ "L'Oréal Paris Hair color, select varieties, spend $25 at Target",TARGET,LOREAL PARIS HAIR COLOR
214
+ "TWIX®, select varieties",,TWIX
215
+ Spend $15 at KFC,KFC,KFC
216
+ Spend $275 at Vons,VONS,VONS
217
+ "EXTRA®, select varieties",,EXTRA
218
+ "Ben & Jerry's® Doggie Desserts, 4 ounce, buy 2",,BEN AND JERRYS
219
+ "Klondike Cones, spend $10 at Walmart ",WALMART,KLONDIKE
220
+ "Reese's Peanut Butter Bar, 6 count, at GIANT OR MARTIN’S",MARTINS FOODS,GOOD HUMOR
221
+ "Beyond Steak™ Plant-Based seared tips, 10 ounce at H-E-B",H-E-B,BEYOND MEAT
222
+ "Kradle, select products, online at Chewy.com",CHEWY,KRADLE
223
+ Spend $120 at Star Market,STAR MARKET,STAR MARKET
224
+ Shop 2 times at Vons,VONS,VONS
225
+ Wonderworks™ Keto* Friendly Cereal,,WONDERWORKS
226
+ "MTN DEW® Kickstart, 16-ounce 12 count, select varieties, at Amazon Storefront*",AMAZON,MOUNTAIN DEW
227
+ When you join Costco as an Executive Member* (New Members Only),COSTCO,COSTCO
228
+ "Adult Astepro® Allergy, 22 count at Dollar General",DOLLAR GENERAL STORE,ASTEPRO
229
+ Shop 2 times at Pavilions,PAVILIONS,PAVILIONS
230
+ "SKITTLES®, select varieties",,SKITTLES
231
+ "Stubborn Soda OR Bundaberg Ginger Beer, select varieties, at Amazon Storefront*",AMAZON,STUBBORN SODA
232
+ "BallPark® buns, buy 2",,BALL PARK POP UPS
233
+ 12 Pack OR 2 Liter AND Whole Pizza at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
234
+ Spend $220 at Star Market,STAR MARKET,STAR MARKET
235
+ Frozen OR Fountain Drink at Casey's ,CASEYS GENERAL STORE,CASEYS GENERAL STORE
236
+ Spend $45 at TGI Friday's,TGI FRIDAYS,TGI FRIDAYS
237
+ Visit OR order online from Casey's 3 times,CASEYS GENERAL STORE,CASEYS GENERAL STORE
238
+ Spend $210 at Randalls,RANDALLS FOOD MARKETS,RANDALLS
239
+ Visit OR order online from Casey's 5 times,CASEYS GENERAL STORE,CASEYS GENERAL STORE
240
+ Any Tom Thumb receipt,TOM THUMB,TOM THUMB
241
+ "Butterball, select varieties, spend $10 at Fry's Food Store",FRYS FOOD STORE,BUTTERBALL
242
+ "ORBIT®, select sizes, buy 1",,ORBIT
243
+ 12 pack OR 2 liter AND Whole Pizza at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
244
+ "Molson Coors®, select varieties, 12 Pack+, buy 2",,TOPO CHICO HARD SELTZER
245
+ "Thomas'®, select varieties, spend $10",,THOMAS
246
+ "Beyond Steak™ Plant-Based seared tips, 10 ounce, buy 2 at Target",TARGET,BEYOND MEAT
247
+ Whole Pizza at Casey's ,CASEYS GENERAL STORE,CASEYS GENERAL STORE
248
+ "EXTRA®, select sizes",,EXTRA
249
+ Gorton's at select retailers,STOP & SHOP,GORTONS
250
+ Brita® Standard OR Elite Filters,,BRITA
251
+ Spend $300 at Shaws,SHAWS,SHAWS
252
+ Spend $50 at Fresh Thyme Market,FRESH THYME MARKET,FRESH THYME MARKET
253
+ "Starry™ Lemon Lime Soda multipacks, at Kroger",DILLONS GROCERY,STARRY
254
+ "Barilla® pasta, select varieties, buy 3",,BARILLA
255
+ "Fresh Bakery Products at Casey's, select varieties",CASEYS GENERAL STORE,CASEYS GENERAL STORE
256
+ "Coors Light®, Miller Lite® OR VIZZY™ 12 packs+, buy 2",,VIZZY
257
+ "Kradle, select varieties, online at Amazon",AMAZON,KRADLE
258
+ "Starry™ Lemon Lime Soda, 7.5-ounce 10 pack, at Amazon Storefront*",AMAZON,STARRY
259
+ "EVOLVE® Plant-Based Protein Shake, 4 count, select varieties, at Whole Foods",WHOLE FOODS MARKET,EVOLVE
260
+ "Burt's Bee's® Facial Wipes, select varieties, 30 count at Walmart",WALMART,BURTS BEES
261
+ "Aleve® products AND AleveX™, select varieties, at Walmart",WALMART,ALEVE
262
+ "Beyond Meat® Plant-Based products, spend $15",,BEYOND MEAT
263
+ "GOYA® Adobo Seasoning, 8 ounce+",,GOYA
264
+ "Tyson Products, select varieties, spend $15 at Walmart",WALMART,AIDELLS
265
+ Spend $210 at Safeway,SAFEWAY,SAFEWAY
266
+ Klondike Cones at Walmart ,WALMART,KLONDIKE
267
+ Spend $110 at Albertsons,ALBERTSONS,ALBERTSONS
268
+ "Bubbies Pickles, Sauerkraut, OR Condiments at Whole Foods or Sprouts",SPROUTS FARMERS MARKET,BUBBIES
269
+ "Sara Lee® or Alfaros® Artesano bread, buy 2",,ALFAROS
270
+ "Beyond Meat® Plant-Based products, spend $20",,BEYOND MEAT
271
+ Spend $10 on Casey's branded packaged products,CASEYS GENERAL STORE,CASEYS GENERAL STORE
272
+ Any Randalls receipt,RANDALLS FOOD MARKETS,RANDALLS
273
+ "Arber, at Target",TARGET,ARBER
274
+ "Häagen-Dazs®, 28 ounce, at GROCERY* stores",,HAAGEN DAZS
275
+ Spend $130 at ACME,ACME,ACME
276
+ "Spend $110 on a Full-Priced new Plus Membership and receive an ADDITIONAL 10,000 points",SAMS CLUB,SAMS CLUB
277
+ "Butterball, select varieties, spend $10 at QFC",QFC,BUTTERBALL
278
+ Spend $100 at Pavilions,PAVILIONS,PAVILIONS
279
+ "Glad® Trash Bags, 4 OR 8 Gallon",,GLAD
280
+ Tostitos® Toppers™,,TOSTITOS
281
+ :ratio™ KETO* Friendly Cereal OR Granola,,RATIO
282
+ "Burt's Bees® products, select varieties, at Walmart",WALMART,BURTS BEES
283
+ "Bio-Oil® products, select varieties",,BIO OIL
284
+ "André® California, Champagne OR Sparkling Wines, 750mL bottle",,ANDRE
285
+ Spend $20 at Farmer Boys,FARMER BOYS,FARMER BOYS
286
+ "Any General Mills™ products, spend $50",,ANNIES HOMEGROWN
287
+ Chosen Foods® Dressings,,CHOSEN FOODS
288
+ Spend $30 at Dickey's Barbecue Pit,DICKEYS BARBECUE PIT,DICKEYS BARBECUE PIT
289
+ Degree for Men OR Women Dry Spray,,DEGREE
290
+ "Coors Light®, Miller Lite® OR VIZZY™ 12 packs+, buy 3",,VIZZY
291
+ Back to the Roots Microgreens Grow Kit OR Seed Refill at Walmart,WALMART,BACK TO THE ROOTS
292
+ Spend $40 at KFC,KFC,KFC
293
+ "Bai® Antioxidant, 6 pack, at Walmart",WALMART,BAI
294
+ Spend $20 at Dickey's Barbecue Pit,DICKEYS BARBECUE PIT,DICKEYS BARBECUE PIT
295
+ Spend $25 at TGI Friday's,TGI FRIDAYS,TGI FRIDAYS
296
+ "L'Oréal Paris Hair color, select varieties, spend $9 at Target",TARGET,LOREAL PARIS HAIR COLOR
297
+ "Sargento Sliced Cheese, spend $18",,SARGENTO
298
+ "SKITTLES®, select sizes",,SKITTLES
299
+ "LIFESAVERS®, any size, buy 1",,LIFESAVERS
300
+ "L'Oréal Paris Makeup, spend $30 at Target",TARGET,LOREAL PARIS COSMETICS
301
+ Spend $115 at Tom Thumb,TOM THUMB,TOM THUMB
302
+ Any Randalls receipt,RANDALLS,RANDALLS
303
+ Spend $75 at Randalls,RANDALLS,RANDALLS
304
+ Shop 2 times at Randalls,RANDALLS FOOD MARKETS,RANDALLS
305
+ "GATORADE® Fast Twitch®, 12-ounce single serve",,GATORADE
306
+ Spend $10 at Nekter,NEKTER JUICE BAR,NEKTER
307
+ "Brownie Brittle® Snacks, select varieties, buy 2",,BROWNIE BRITTLE
308
+ Cheerios™ Oat Crunch Berry Cereal,,CHEERIOS
309
+ Glad® ForceFlex Max Strength Trash Bags,,GLAD
310
+ "GATORADE® Fast Twitch®, 12-ounce single serve, at Kroger",DILLONS GROCERY,GATORADE
311
+ Spend $10 at CVS,CVS,CVS
312
+ "OxiClean™ Laundry Stain Removers, select varieties at Walmart",WALMART,OXICLEAN
313
+ Country Crock® Plant Based Cream at Walmart,WALMART,COUNTRY CROCK PLANT BUTTER
314
+ 2 Pack OR 2 Liter AND Whole Pizza at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
315
+ Arnold® Grains Almighty,,ARNOLD BROWNBERRY OROWEAT
316
+ "Snuggle® Liquid Fabric Softener, at Walmart",WALMART,SNUGGLE
317
+ "Hidden Valley® Ranch Night Seasoning Mix, 1 count",,HIDDEN VALLEY RANCH
318
+ "Kradle, select varieties, at Pet Supplies Plus",PET SUPPLIES PLUS,KRADLE
319
+ "Back to the Roots Soils, select varieties and sizes, at Lowes",LOWES HOME IMPROVEMENT,BACK TO THE ROOTS
320
+ "Butterball, select varieties, spend $10 at Mariano's",MARIANOS,BUTTERBALL
321
+ "CORE® Hydration, select varieties, buy 2 at Walmart",WALMART,CORE HYDRATION
322
+ Spend $40 at Dickey's Barbecue Pit,DICKEYS BARBECUE PIT,DICKEYS BARBECUE PIT
323
+ "General Mills™ snacks, select brands, spend $10",,BUGLES
324
+ "Back to the Roots Soils, select varieties, at Walmart or Lowes",LOWES HOME IMPROVEMENT,BACK TO THE ROOTS
325
+ "Barilla® pasta, select varieties, buy 4",,BARILLA
326
+ "GATORLYTE® OR GATORADE™ Fit Single Serve Bottle, select varieties",,GATORADE
327
+ "Burt's Bees® Sensitive Lotions and Creams, select varieties, at Walmart",WALMART,BURTS BEES
328
+ "Arber, at Walmart",WALMART,ARBER
329
+ "Coors Light®, Miller Lite® OR VIZZY™ 12 packs+, buy 5",,VIZZY
330
+ Any Pavilions receipt,PAVILIONS,PAVILIONS
331
+ Back to the Roots Grow Kits at Walmart or The Home Depot,WALMART,BACK TO THE ROOTS
332
+ Any Safeway receipt,SAFEWAY,SAFEWAY
333
+ "Welch's® Fruit Snacks, select varieties, 6 count+",,WELCHS FRUIT SNACKS
334
+ Back to the Roots Grow Hydroponic Grow Kit OR Refill Bundle at Walmart,WALMART,BACK TO THE ROOTS
335
+ "Ben & Jerry's Wake & No Bake Cookie Dough Ice Cream, 16 ounce",,BEN AND JERRYS
336
+ "ORBIT®, select varieties",,ORBIT
337
+ "GATORADE® Fast Twitch®, 12-ounce single serve, buy 2 at Kroger",FOOD4LESS,GATORADE
338
+ "Butterball, select varieties, spend $10 at Pick 'n Save OR Metro Market",PICK N SAVE,BUTTERBALL
339
+ Hellmann's | Best Foods Vegan Dressing or Spread,,HELLMANNS BEST FOODS
340
+ "Rao's®, Pasta OR Sauce, spend $10",,RAO'S
341
+ L'Oreal Paris True Match Foundation at Target,TARGET,LOREAL PARIS COSMETICS
342
+ "Sara Lee® or Alfaros® Artesano bread, spend $20",,ALFAROS
343
+ Spend $220 at Albertsons,ALBERTSONS,ALBERTSONS
344
+ "Perfect Keto Super Reds, online at Amazon",AMAZON,PERFECT KETO
345
+ The Rustik Oven® bread,,RUSTIK OVEN
346
+ Gorton's at select retailers,WALMART,GORTONS
347
+ "Back to the Roots Seeds, at Walmart",WALMART,BACK TO THE ROOTS
348
+ Nature Valley™ Protein Granola,,NATURE VALLEY
349
+ Brita® Pitcher OR Dispenser,,BRITA
350
+ Spend $30 at CVS,CVS,CVS
351
+ "Back to the Roots Organic Kits and Planters, at Target",TARGET,BACK TO THE ROOTS
352
+ "Sir Kensington's® Condiments, buy 2",,SIR KENSINGTONS
353
+ "Perfect Keto Exogenous Ketones Powder, online at Amazon",AMAZON,PERFECT KETO
354
+ Select Beverages AND Prepared Food Item at Casey's,CASEYS GENERAL STORE,CASEYS GENERAL STORE
355
+ "Back to the Roots Potting Mix, 1 cubic foot, at Lowe's Home Improvement",LOWES HOME IMPROVEMENT,BACK TO THE ROOTS
356
+ "Barilla® pasta, select varieties, buy 2",,BARILLA
357
+ Any Star Market receipt,STAR MARKET,STAR MARKET
358
+ "Squirrel, The Bedside Perch, online at Amazon",AMAZON,SQUIRREL
359
+ "Fresh Bakery items, select varieties, at Casey's",CASEYS GENERAL STORE,CASEYS GENERAL STORE
360
+ Ben & Jerry's® Churray For Churros™ Ice Cream,,BEN AND JERRYS
361
+ Sir Kensington's® Condiments,,SIR KENSINGTONS
362
+ "Dove Hand Wash, select varieties at Target",TARGET,DOVE
363
+ Spend $15 at Burger King,BURGER KING,BURGER KING
364
+ Cameron’s Coffee EcoPods,,CAMERON'S COFFEE
365
+ L'Oréal Paris True Match Foundation at Target,TARGET,LOREAL PARIS COSMETICS
366
+ "Sara Lee® Delightful bread, buy 2",,SARA LEE
367
+ "Welch's® Juicefuls® Juicy Fruit Snacks, buy 2",,WELCHS FRUIT SNACKS
368
+ Spend $35 at Subway,SUBWAY,SUBWAY
369
+ "Dixon® Safety Carpenter Pencil, 10 count, at Lowe’s®",LOWES HOME IMPROVEMENT,DIXON
370
+ Spend $115 at Safeway,SAFEWAY,SAFEWAY
371
+ "Breyers Reese's Ice Cream, select varieties, at GIANT OR MARTIN’S",MARTINS FOODS,BREYERS
372
+ Shop 2 times at Randalls,RANDALLS,RANDALLS
373
+ "Jack Link's®, select varieties",,JACK LINKS
374
+ "Persil® ProClean®, select varieties, at Walmart",WALMART,PERSIL
375
+ "Back to the Roots Organic 3-In-1 Seed Starting Mix 12 quart, at Walmart or Target",TARGET,BACK TO THE ROOTS
376
+ "STARBURST®, select varieties",,STARBURST
377
+ "Super Coffee, 12 ounce single serve",,SUPER COFFEE
378
+ Spend $90 at Safeway,SAFEWAY,SAFEWAY
379
+ Spend $5 on brisket mac & cheese sandwich OR other single-serve prepared food item,CASEYS GENERAL STORE,CASEYS GENERAL STORE
380
+ Spend $50 at Chewy.com,CHEWY,CHEWY
381
+ Simply Organic Seasoning Mixes OR Spices,,SIMPLY ORGANIC
382
+ Spend $10 at KFC,KFC,KFC
383
+ Sargento Product,,SARGENTO
384
+ Thomas'® Bagel Thins,,THOMAS
385
+ Spend $270 at Pavilions,PAVILIONS,PAVILIONS
386
+ "Back to the Roots Soils, select varieties, at Walmart",WALMART,BACK TO THE ROOTS
data/offered_brands.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4d562168ec2efa207d65d6dc88d9c3c07cb7ffc106906cd66d0370173cf7289
3
+ size 1345
data/product_upper_category_dict.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"ALCOHOL": ["Beer", "Malt Beverages", "Hard Seltzers, Sodas, Waters, Lemonades & Teas", "Hard Ciders", "Wine", "Spirits"], "ANIMALS & PET SUPPLIES": ["Dog Supplies"], "BABY & TODDLER": ["Baby Bathing", "Potty Training", "Baby Safety", "Diapering", "Baby Health"], "BEAUTY": ["Cosmetic Tools", "Makeup", "Nail Care", "Body Fragrances"], "BEVERAGES": ["Coffee", "Meal Replacement Beverages", "Vegetable Juices", "Drink Mixes", "Tea", "Energy Drinks", "Water", "Fruit Juices", "Carbonated Soft Drinks"], "CANDY": ["Gum"], "DAIRY": ["Cream", "Dairy Alternatives", "Dairy", "Yogurt", "Milk", "Cheese", "Butter & Margarine", "Eggs", "Refrigerated Doughs"], "DELI & BAKERY": ["Leafy Salads", "Deli Counter", "Bakery", "Prepared Meals"], "FROZEN": ["Frozen Fruits", "Frozen Desserts", "Frozen Sides", "Frozen Meals", "Frozen", "Frozen Vegetables", "Ice", "Frozen Breads & Doughs", "Frozen Pizza & Pizza Snacks", "Frozen Breakfast", "Frozen Plant-Based Meat", "Frozen Appetizers"], "FROZEN MEAT": ["Frozen Turkey", "Frozen Chicken", "Frozen Beef", "Frozen Seafood"], "HEALTH & WELLNESS": ["Feminine Hygeine", "Sexual Health", "Foot Care", "Deodorant & Antiperspirant", "Skin Care", "Oral Care", "Eye Care", "First Aid", "Hair Care", "Hair Removal", "Adult Incontinence", "Bath & Body", "Medicines & Treatments"], "HOME & GARDEN": ["Decor"], "HOUSEHOLD SUPPLIES": ["Household Cleaning Supplies", "Household Supplies", "Pest Control", "Food Storage", "Laundry Supplies"], "MATURE": ["Tobacco Products", "Mature"], "MEAT & SEAFOOD": ["Plant-Based Meat"], "ORAL CARE": ["Toothpaste"], "PANTRY": ["Cooking & Baking", "Packaged Seafood", "Nut Butters & Jam", "Cereal, Granola, & Toaster Pastries", "Condiments", "Packaged Meals & Sides", "Soup & Broth", "Bread", "Sauces & Marinades", "Packaged Fruit & Applesauce", "Pickled Goods", "Dressings", "Packaged Meat", "Pasta & Noodles", "Packaged Vegetables", "Rice & Grains"], "PASTA & NOODLES": ["Dry Pasta", "Fresh Pasta"], "PASTA SAUCE": ["Red Pasta Sauce", "Alfredo & White Pasta Sauce", "Pesto Sauce"], "PUFFED SNACKS": ["Popcorn"], "SNACKS": ["Candy", "Pretzels", "Snack Mixes", "Dips & Salsa", "Crackers", "Dessert Toppings", "Puffed Snacks", "Jerky & Dried Meat", "Chips", "Nuts & Seeds", "Cookies", "Trail Mix", "Fruit & Vegetable Snacks", "Snack Cakes", "Pudding & Gelatin"], "SPIRITS": ["Rum", "Vodka"], "SPORTS DRINKS & ENHANCED WATERS": ["Sports Drinks"]}
gradio_deploy.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ import pickle, json
6
+ from src.utils import *
7
+
8
+ ##### Start #####
9
+
10
+ # load operation data
11
+ path1 = "data/brand_belong_category_dict.json"
12
+ path2 = "data/product_upper_category_dict.json"
13
+ path3 = "data/offered_brands.pkl"
14
+ path4 = "data/offer_retailer.csv"
15
+
16
+ with open(path1, 'r') as f:
17
+ brand_belong_category_dict = json.load(f)
18
+
19
+ with open(path2, 'rb') as f:
20
+ category_dict = json.load(f)
21
+
22
+ with open(path3, 'rb') as f:
23
+ offered_brands = pickle.load(f)
24
+
25
+ df_offers_brand_retailer = pd.read_csv(path4)
26
+
27
+ examples = [
28
+ ["Simply Spiked Lemonade 12 pack at Walmart"],
29
+ ["Back to the Roots Garden Soil, 1 cubic foot, at Lowe's Home Improvement"],
30
+ ["Costco Member subscription"],
31
+ ["Apple watch coupon at Best Buy"],
32
+ ["A giraffe at Lincoln Park Zoo"]
33
+ ]
34
+
35
+ def main(sentence: str, score_type: str, threshold_cosine: float, threshold_jaccard: float):
36
+ threshold = threshold_cosine if score_type == "cosine" else threshold_jaccard
37
+ results = search_offers(sentence, df_offers_brand_retailer, category_dict, brand_belong_category_dict, score_type, threshold)
38
+ message, processed_results = process_output(results)
39
+ return message, processed_results
40
+
41
+ def process_output(output):
42
+ """Function to process the output"""
43
+ if output is None or output.empty:
44
+ return "We couldn't find your results, please try our examples or search again", None
45
+ else:
46
+ return "We found some great offers!", output
47
+
48
+ iface = gr.Interface(
49
+ fn=main,
50
+ inputs=[
51
+ gr.Textbox(lines=1, placeholder="Type here..."),
52
+ gr.Dropdown(choices=["cosine", "jaccard"], label="Score Type"),
53
+ gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Cosine Similarity"),
54
+ gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Jaccard Similarity")
55
+ ],
56
+ outputs=[gr.Textbox(placeholder="Message..."), gr.Dataframe()],
57
+ examples=examples,
58
+ live=False,
59
+ )
60
+
61
+ if __name__ == "__main__":
62
+ iface.launch()
src/.DS_Store ADDED
Binary file (6.15 kB). View file
 
src/utils.py ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # helper functions
2
+ from typing import List, Dict, Tuple
3
+ import re
4
+ from sklearn.feature_extraction.text import CountVectorizer
5
+ from sklearn.metrics.pairwise import cosine_similarity
6
+ import pandas as pd
7
+ import numpy as np
8
+
9
+ from IPython.display import clear_output
10
+
11
+ import spacy
12
+ from spacy.tokens import DocBin
13
+ from spacy.training import offsets_to_biluo_tags
14
+ import en_fetch_ner_spacy_tsf
15
+ nlp = en_fetch_ner_spacy_tsf.load()
16
+ clear_output()
17
+
18
+ import nltk
19
+ nltk.download('stopwords')
20
+
21
+ from nltk.corpus import stopwords
22
+ stop_words = set(stopwords.words('english'))
23
+ additional_stop_words = {'pack'}
24
+ stop_words.update(additional_stop_words)
25
+ clear_output()
26
+
27
+
28
+ def single_text_cleaner(text: str, remove_stopwords: bool=False, upper_case: bool = False, remove_punctuation: bool=True) -> str:
29
+ """Clean one single text input. By default it will convert text to lower case"""
30
+ if upper_case:
31
+ text = text.upper()
32
+ else:
33
+ text = text.lower()
34
+ if remove_punctuation:
35
+ text = re.sub(r'[^a-z\s]', '', text)
36
+ if remove_stopwords:
37
+ words = text.split()
38
+ words = [word for word in words if word not in stop_words]
39
+ text = ' '.join(words)
40
+ return text
41
+
42
+ def list_text_cleaner(texts: List[str], upper_case: bool = False, remove_stopwords: bool = False, remove_punctuation: bool=True) -> List[str]:
43
+ """Takes in a list of strings and returns a list of cleaned strings without stop words.
44
+ Current tasks:
45
+ - remove non-alphabetical characters
46
+ - converting to lower cases
47
+ - remove stop words (optional)"""
48
+ cleaned_texts = [single_text_cleaner(text, remove_stopwords, upper_case, remove_punctuation) for text in texts]
49
+ return cleaned_texts
50
+
51
+ def match_product_category(s1: list[str], s2: list[str]) -> str:
52
+ """Find if items of a list is in one list of product categories"""
53
+ return next((p for c in s1 for p in s2 if c in p), None) # this will stop after finding first match, which saves time
54
+
55
+ def find_category(search_input: str, search_dict: Dict) -> str:
56
+ """Find the category of a search input based on a dictionary of categories
57
+ Args:
58
+ - search_input: a string
59
+ - search_dict: a dictionary of product categories
60
+ """
61
+ search_list = list_text_cleaner(re.split(r'[,\s]+', search_input), remove_stopwords=True)
62
+ search_list = [c for c in search_list if len(c)>0] # sometimes there are empty strings
63
+ matched_category = False
64
+ for k, v in search_dict.items():
65
+ v = list_text_cleaner(v, remove_punctuation=False)
66
+ search_results = match_product_category(search_list, v)
67
+ if search_results is not None:
68
+ matched_category = True
69
+ return k, search_results
70
+ else:
71
+ # print(f'Function find_category: No category {k} has matched for input: {search_input}')
72
+ continue
73
+ if not matched_category:
74
+ print(f'Function find_category: No category has matched for input: {search_input}')
75
+ return None
76
+
77
+
78
+ def check_entity(search_input) -> bool:
79
+ """Takes in a search input and checks if it contains any entities"""
80
+ doc = nlp(search_input)
81
+ if len(doc.ents) > 0:
82
+ return doc
83
+ else:
84
+ return False
85
+
86
+ def get_cosine_sim(input_text: str, texts: List[str]) -> pd.DataFrame:
87
+ """Calculate the cosine similarity of the input text against a list of texts
88
+ Takes in:
89
+ - input_text: a string
90
+ - texts: a list of strings
91
+ Returns a dataframe with two columns: Sentence Text and Cosine Similarity Score
92
+ """
93
+ input_text_cleaned = list_text_cleaner([input_text], remove_stopwords=True)[0]
94
+ cleaned_texts = list_text_cleaner(texts, remove_stopwords=True)
95
+ all_texts = [input_text_cleaned] + cleaned_texts
96
+ vectors = get_vectors(*all_texts)
97
+ sim_matrix = cosine_similarity(vectors)
98
+ # Get the similarity scores of the input_text against all other texts
99
+ sim_scores = sim_matrix[0, 1:]
100
+ data = {'OFFER': texts, 'Cosine Similarity Score': sim_scores}
101
+ df = pd.DataFrame(data)
102
+ df = df.sort_values(by='Cosine Similarity Score', ascending=False).reset_index(drop=True)
103
+ return df
104
+
105
+ def get_vectors(*strs: str) -> np.ndarray:
106
+ text = list(strs)
107
+ vectorizer = CountVectorizer()
108
+ vectorizer.fit(text)
109
+ return vectorizer.transform(text).toarray()
110
+
111
+ def jaccard_similarity(s1: List[str], s2: List[str]) -> float:
112
+ """Takes in two lists and returns the Jaccard similarity score (3 digits)"""
113
+ intersection = set(s1).intersection(set(s2))
114
+ n = len(intersection)
115
+ score = round(n / (len(s1) + len(s2) - n), 3)
116
+ return score
117
+
118
+ def get_jaccard_sim(input_text: str, texts: List[str]) -> pd.DataFrame:
119
+ """Calculate the Jaccard similarity of the input text against a list of texts
120
+ Takes in:
121
+ - input_text: a string
122
+ - texts: a list of strings
123
+ Returns a dataframe with two columns: Sentence Text and Jaccard Similarity Score
124
+ """
125
+ cleaned_input_text = list_text_cleaner([input_text], remove_stopwords=True)[0].split()
126
+ cleaned_texts = list_text_cleaner(texts, remove_stopwords=True)
127
+
128
+ jaccard_scores = [jaccard_similarity(cleaned_input_text, text.split()) for text in cleaned_texts]
129
+
130
+ data = {'OFFER': texts, 'Jaccard Similarity Score': jaccard_scores}
131
+ df = pd.DataFrame(data)
132
+ # sort based on the similarity score
133
+ df = df.sort_values(by='Jaccard Similarity Score', ascending=False).reset_index(drop=True)
134
+ return df
135
+
136
+ def find_column(df: pd.DataFrame, keyword: str) -> str:
137
+ """Function to find the first column containing a specific keyword. Note that we assume there will only be one score at most for a similarity score dataframe"""
138
+ cols = [col for col in df.columns if keyword.lower() in col.lower()]
139
+ return cols[0] if cols else None
140
+
141
+ def extract_similar_offers(data: pd.DataFrame, threshold: float = 0.0) -> pd.DataFrame:
142
+ """Takes in the results from get_cosine_sim() and get_jaccard_sim(); returns a dataframe of similar offers with scores > threshold"""
143
+ score = find_column(data, 'score')
144
+ similar_offers = data[data[score] >= threshold]
145
+ similar_offers[score] = similar_offers[score].apply(lambda x: round(x, 3)) # round to 3 digits
146
+ return similar_offers
147
+
148
+ def category_to_brand(category: str, offered_brands: List, brand_belong_category_dict: Dict) -> List[str]:
149
+ """Use case: when a user searches for a category, we return a list of brands in that category"""
150
+ # checks if the category is in the dictionary keys
151
+ if category.upper() in brand_belong_category_dict.keys():
152
+ search_brands = brand_belong_category_dict[category.upper()] # becase all keys are in upper case
153
+ result = list(set(search_brands) & set(offered_brands))
154
+ print(f"Function category_to_brand | Found {category} in offered brand")
155
+ return result
156
+ else:
157
+ print(f"Function category_to_brand | No offered brand is found in {category}")
158
+ return None
159
+
160
+ class CatchErros(Exception):
161
+ class ParamsInputError(Exception):
162
+ pass
163
+ class SearchFailedError(Exception):
164
+ pass
165
+ class UnknownError(Exception):
166
+ pass
167
+
168
+
169
+ def offer_finder_by_category(search_input: str, search_category_tuple: Tuple, category_dict: Dict, offered_brands: List,
170
+ brand_belong_category_dict: Dict, score: str, threshold: float = 0.0) -> pd.DataFrame:
171
+ """Find offers based on a category identified from search input.
172
+ Args:
173
+ - search_input: a string
174
+ - search_category_tuple: a tuple of (upper_category, product_category)
175
+ - category_dict: a dictionary of categories. Keys are upper categories and values are lists of product categories
176
+ - offered_brands: a dataframe of offers (OFFER, BRAND, RETAILER) that are avaialble in our database
177
+ - brand_belong_category_dict: a dictionary of brands and the categories they belong to
178
+ - score: a string of either 'cosine' or 'jaccard'
179
+ - threshold: a float between 0 and 1
180
+
181
+ Returns a dataframe of similar offers, ordered by highest score
182
+ """
183
+ # we assume people just search one category at a time
184
+ # search_category_tuple = find_category(search_input, category_dict)
185
+ product_category, upper_category = search_category_tuple[1], search_category_tuple[0] # ('Alcohol', 'beer')
186
+ print(f'Function offer_finder_by_category | Found items:\n- Search input: {search_input}\n- Product category: {product_category}\n- Upper category: {upper_category}')
187
+ potential_brands = category_to_brand(product_category, offered_brands, brand_belong_category_dict)
188
+ if potential_brands is not None:
189
+ potential_offers = offers[offers['BRAND'].isin(potential_brands)]['OFFER'].tolist()
190
+ if score == 'cosine':
191
+ cos_sim_score = get_cosine_sim(search_input, potential_offers)
192
+ output = extract_similar_offers(cos_sim_score, threshold)
193
+ elif score == 'jaccard':
194
+ jaccard_sim_score = get_jaccard_sim(search_input, potential_offers)
195
+ output = extract_similar_offers(jaccard_sim_score, threshold)
196
+ elif score not in ['cosine', 'jaccard']:
197
+ raise ValueError(f'Please enter a valid score: cosine or jaccard; Not {score}')
198
+ else: # this means something else is worng
199
+ raise UnknownError(f'Something must be broken. Please try again.')
200
+ return output
201
+ else:
202
+ potential_product_categories = category_dict[upper_category]
203
+ msg = f'{product_category} is not found. Do you wanna take a look at these similar offers in {upper_category}?\n We have: {potential_product_categories}' # we can still calculate similarity but this is computationally expensive
204
+ print(msg)
205
+ return None
206
+
207
+ def offer_finder_by_entity(search_input: str, entities: Tuple, offers_data: pd.DataFrame, score: str, threshold: float=0.0) -> pd.DataFrame:
208
+ """Find offers based on entities identified from search input.
209
+ Args:
210
+ - search_input: a string
211
+ - entities: a tuple of entities
212
+ - offers_data: a dataframe of offers (OFFER, BRAND, RETAILER) that are avaialble in our database
213
+ - score: a string of either 'cosine' or 'jaccard'
214
+ - threshold: a float between 0 and 1
215
+
216
+ Returns a dataframe of similar offers, ordered by highest score
217
+ """
218
+ collects = [] # collect all the results if there are more than one entity
219
+ for ent in entities:
220
+ ent_name, ent_label = ent.text, ent.label_
221
+ print(f'Function offer_finder_by_entity | Found entity: {ent_name} with label: {ent_label}')
222
+ # filter offers by entity
223
+ df_tmp = offers_data[offers_data[ent_label.upper()] == ent_name.upper()]
224
+ if df_tmp.shape[0] > 0:
225
+ print(f'Function offer_finder_by_entity | Found {df_tmp.shape[0]} offer(s) for the brand/retailer: {ent_name}')
226
+ potential_offers = df_tmp['OFFER'].drop_duplicates().tolist()
227
+ if score == 'cosine':
228
+ cos_sim_score = get_cosine_sim(search_input, potential_offers)
229
+ output = extract_similar_offers(cos_sim_score, threshold)
230
+ elif score == 'jaccard':
231
+ jaccard_sim_score = get_jaccard_sim(search_input, potential_offers)
232
+ output = extract_similar_offers(jaccard_sim_score, threshold)
233
+ elif score not in ['cosine', 'jaccard']:
234
+ raise ValueError(f'Please enter a valid score: cosine or jaccard; Not {score}')
235
+ else: # this means something else is worng
236
+ raise UnknownError(f'Something must be broken. Please try again.')
237
+ collects.append(output)
238
+ else:
239
+ print(f'Function offer_finder_by_entity | No offer is found for the brand/retailer: {ent_name}')
240
+
241
+ if len(collects) > 0:
242
+ final_output = pd.concat(collects, ignore_index=True)# they should be using the same similarity score
243
+ score = find_column(collects[0], 'score')
244
+ final_output = final_output.sort_values(by=score, ascending=False).reset_index(drop=True) # sort final_output by score
245
+ return final_output
246
+ elif len(collects) == 1:
247
+ return collects[0]
248
+ else:
249
+ print('###'*5 + 'FINAL SEARCH RESULTS' + '###'*5)
250
+ print('Function offer_finder_by_entity | No offer is found for any of the entities.')
251
+ return None
252
+
253
+
254
+ def search_offers(search_input: str, offers: pd.DataFrame, category_dict: Dict, brand_belong_category_dict: Dict, score: str, score_threshold: float = 0.0):
255
+ """Main function. Takes in a serach_input and decide whether it can find entities or not. Then excecute the appropriate functions
256
+ Inputs:
257
+ - search_input: a string that a user enters
258
+ - offers: a dataframe of offers (OFFER, BRAND, RETAILER) that are avaialble in our database
259
+ - category_dict: a dictionary of categories. Keys are upper categories and values are lists of product categories
260
+ - brand_belong_category_dict: a dictionary of brands and the categories they belong to
261
+ - score: a string of either 'cosine' or 'jaccard'
262
+ - score_threshold: a float between 0 and 1
263
+
264
+ Returns a dataframe of similar offers, ordered by highest score
265
+ """
266
+ print(f'Function main | Search input: {search_input}')
267
+ check_ent = check_entity(search_input)
268
+ if not check_entity(search_input): # no entities found
269
+ # check category
270
+ cat_check = find_category(search_input, category_dict)
271
+ if cat_check is None:
272
+ raise SearchFailedError('No brand/retailer/category is found. Please try again.')
273
+ else:
274
+ # we assume people just search one category at a time
275
+ cat_tuple = cat_check # ('Alcohol', 'beer')
276
+ search_results = offer_finder_by_category(search_input, cat_tuple, category_dict, offers, brand_belong_category_dict, score, score_threshold)
277
+ return search_results
278
+ else:
279
+ entities = check_ent.ents # entities will be a tuple anyways
280
+ print(f'Found {len(entities)} entity object(s) in the search input.')
281
+ search_results = offer_finder_by_entity(search_input, entities, offers, score, score_threshold)
282
+ return search_results
283
+