ruchi commited on
Commit
e9b921a
1 Parent(s): ba3a2e0

Add customer needs and sustainability

Browse files
Files changed (4) hide show
  1. app.py +26 -4
  2. money_needs.sqlite → data.sqlite +0 -0
  3. notebook.ipynb +584 -0
  4. utils.py +64 -29
app.py CHANGED
@@ -5,7 +5,7 @@ import google.generativeai as genai
5
  GOOGLE_API_KEY= os.getenv('GEMINI_API_KEY')
6
  genai.configure(api_key=GOOGLE_API_KEY)
7
  model = genai.GenerativeModel(model_name = "gemini-pro")
8
- from utils import findTop3MoneyNeeds, findTop3Topologies
9
 
10
 
11
  # Create a banner using Markdown
@@ -27,8 +27,8 @@ selectedCity = st.selectbox("Please select the City and the Bank Product for You
27
  selectedProduct = st.selectbox("Please select the Product", ["Current", "Mortage", "Credit Card", "Crypto"])
28
  subscriberTakeOut = st.number_input("Please enter your subscriber take out")
29
  moneyNeeds = st.text_area("Describe money needs of your target audience. For example do they spend a lot on education, healthcare, gym, eating out etc.")
30
- #customerExperience = st.text_area("Describe the customer experience needs of your target audience.")
31
- #sutainabilityNeeds = st.text_area("Describe the sutainability needs of your target audience.")
32
 
33
  userProposal = st.text_area("Enter your final Proposition for Select City and Product")
34
  submit_button = st.button("Submit")
@@ -105,14 +105,29 @@ if submit_button:
105
 
106
  topMoneyNeeds, topMoneyNeedsDict = findTop3MoneyNeeds(moneyNeeds)
107
 
 
 
 
 
108
  matchingTopologies, topologyDetails = findTop3Topologies(proposal, demographic)
109
 
110
  response = model.generate_content([pre_prompt.format(proposal)])
 
111
  st.write("As per your money needs your product is mostly targeting the below spending patterns",)
112
 
113
  for idx, need in enumerate(topMoneyNeeds):
114
  st.write("{}. {}".format(idx+1, need))
115
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  st.write("As per your demographic and your proposition here are the three topologies you are targeting",)
118
 
@@ -125,7 +140,14 @@ if submit_button:
125
  sumTopology = 0
126
  for moneyNeed in topMoneyNeedsDict:
127
  sumTopology = sumTopology+int(moneyNeed[topology])
128
- topologySumDict[topology] = sumTopology
 
 
 
 
 
 
 
129
 
130
  for topology in matchingTopologies:
131
  st.write("{}. {}".format(topology, topologySumDict[topology]))
 
5
  GOOGLE_API_KEY= os.getenv('GEMINI_API_KEY')
6
  genai.configure(api_key=GOOGLE_API_KEY)
7
  model = genai.GenerativeModel(model_name = "gemini-pro")
8
+ from utils import findTop3MoneyNeeds, findTop3Topologies, findTop3CustomerExperienceNeeds, findTop3SustainabilityNeeds
9
 
10
 
11
  # Create a banner using Markdown
 
27
  selectedProduct = st.selectbox("Please select the Product", ["Current", "Mortage", "Credit Card", "Crypto"])
28
  subscriberTakeOut = st.number_input("Please enter your subscriber take out")
29
  moneyNeeds = st.text_area("Describe money needs of your target audience. For example do they spend a lot on education, healthcare, gym, eating out etc.")
30
+ customerExperience = st.text_area("Describe the customer experience needs of your target audience.")
31
+ sutainabilityNeeds = st.text_area("Describe the sutainability needs of your target audience.")
32
 
33
  userProposal = st.text_area("Enter your final Proposition for Select City and Product")
34
  submit_button = st.button("Submit")
 
105
 
106
  topMoneyNeeds, topMoneyNeedsDict = findTop3MoneyNeeds(moneyNeeds)
107
 
108
+ topCustomerExp, topCustomerExpDict = findTop3CustomerExperienceNeeds(customerExperience)
109
+
110
+ topSustainabilityNeeds, topSustainabilityNeedsDict = findTop3SustainabilityNeeds(sutainabilityNeeds)
111
+
112
  matchingTopologies, topologyDetails = findTop3Topologies(proposal, demographic)
113
 
114
  response = model.generate_content([pre_prompt.format(proposal)])
115
+
116
  st.write("As per your money needs your product is mostly targeting the below spending patterns",)
117
 
118
  for idx, need in enumerate(topMoneyNeeds):
119
  st.write("{}. {}".format(idx+1, need))
120
 
121
+ st.write("As per your money needs your product is mostly targeting the below spending patterns",)
122
+
123
+ for idx, exp in enumerate(topCustomerExp):
124
+ st.write("{}. {}".format(idx+1, exp))
125
+
126
+ st.write("As per your sustainability needs your product is mostly targeting the below spending patterns",)
127
+
128
+ for idx, need in enumerate(topSustainabilityNeeds):
129
+ st.write("{}. {}".format(idx+1, need))
130
+
131
 
132
  st.write("As per your demographic and your proposition here are the three topologies you are targeting",)
133
 
 
140
  sumTopology = 0
141
  for moneyNeed in topMoneyNeedsDict:
142
  sumTopology = sumTopology+int(moneyNeed[topology])
143
+
144
+ for customerExp in topCustomerExpDict:
145
+ sumTopology = sumTopology+int(customerExp[topology])
146
+
147
+ for sustainabilityNeed in topSustainabilityNeedsDict:
148
+ sumTopology = sumTopology+int(sustainabilityNeed[topology])
149
+
150
+ topologySumDict[topology] = math.floor(sumTopology/3)
151
 
152
  for topology in matchingTopologies:
153
  st.write("{}. {}".format(topology, topologySumDict[topology]))
money_needs.sqlite → data.sqlite RENAMED
Binary files a/money_needs.sqlite and b/data.sqlite differ
 
notebook.ipynb ADDED
@@ -0,0 +1,584 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "metadata": {},
15
+ "source": []
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 3,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "mycsv = pd.read_csv('topologies_desc.csv', encoding = \"ISO-8859-1\")"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "execution_count": 14,
29
+ "metadata": {},
30
+ "outputs": [
31
+ {
32
+ "data": {
33
+ "text/plain": [
34
+ "'Proportion Sample'"
35
+ ]
36
+ },
37
+ "execution_count": 14,
38
+ "metadata": {},
39
+ "output_type": "execute_result"
40
+ }
41
+ ],
42
+ "source": [
43
+ "mycsv[mycsv.columns[0]][0]"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 15,
49
+ "metadata": {},
50
+ "outputs": [
51
+ {
52
+ "data": {
53
+ "text/plain": [
54
+ "'10%'"
55
+ ]
56
+ },
57
+ "execution_count": 15,
58
+ "metadata": {},
59
+ "output_type": "execute_result"
60
+ }
61
+ ],
62
+ "source": [
63
+ "mycsv['Ambitious Strivers'][0]"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 19,
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "mycsv = mycsv.dropna(axis=1, how='all')"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 17,
78
+ "metadata": {},
79
+ "outputs": [
80
+ {
81
+ "data": {
82
+ "text/plain": [
83
+ "['Column1',\n",
84
+ " 'Ambitious Strivers',\n",
85
+ " 'Comfortable Altruistic',\n",
86
+ " 'Retired and liquid',\n",
87
+ " 'Living for Today',\n",
88
+ " 'Struggling Families',\n",
89
+ " 'High Wealth',\n",
90
+ " 'Money Managers',\n",
91
+ " 'Digital Pioneers',\n",
92
+ " 'Ultra High Wealth',\n",
93
+ " 'Unnamed: 10']"
94
+ ]
95
+ },
96
+ "execution_count": 17,
97
+ "metadata": {},
98
+ "output_type": "execute_result"
99
+ }
100
+ ],
101
+ "source": [
102
+ "list(mycsv.columns).drop()"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": 22,
108
+ "metadata": {},
109
+ "outputs": [
110
+ {
111
+ "data": {
112
+ "text/plain": [
113
+ "['Column1',\n",
114
+ " 'Ambitious Strivers',\n",
115
+ " 'Comfortable Altruistic',\n",
116
+ " 'Retired and liquid',\n",
117
+ " 'Living for Today',\n",
118
+ " 'Struggling Families',\n",
119
+ " 'High Wealth',\n",
120
+ " 'Money Managers',\n",
121
+ " 'Digital Pioneers',\n",
122
+ " 'Ultra High Wealth']"
123
+ ]
124
+ },
125
+ "execution_count": 22,
126
+ "metadata": {},
127
+ "output_type": "execute_result"
128
+ }
129
+ ],
130
+ "source": [
131
+ "list(mycsv.columns)"
132
+ ]
133
+ },
134
+ {
135
+ "cell_type": "code",
136
+ "execution_count": 23,
137
+ "metadata": {},
138
+ "outputs": [
139
+ {
140
+ "data": {
141
+ "text/plain": [
142
+ "0 Proportion Sample\n",
143
+ "1 Description\n",
144
+ "2 Household Income\n",
145
+ "3 dropout %\n",
146
+ "4 Propensity to Buy\n",
147
+ "Name: Column1, dtype: object"
148
+ ]
149
+ },
150
+ "execution_count": 23,
151
+ "metadata": {},
152
+ "output_type": "execute_result"
153
+ }
154
+ ],
155
+ "source": [
156
+ "mycsv['Column1']"
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": 24,
162
+ "metadata": {},
163
+ "outputs": [],
164
+ "source": [
165
+ "df1 = mycsv.loc[:, mycsv.columns != 'Column1']"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 25,
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "data": {
175
+ "text/html": [
176
+ "<div>\n",
177
+ "<style scoped>\n",
178
+ " .dataframe tbody tr th:only-of-type {\n",
179
+ " vertical-align: middle;\n",
180
+ " }\n",
181
+ "\n",
182
+ " .dataframe tbody tr th {\n",
183
+ " vertical-align: top;\n",
184
+ " }\n",
185
+ "\n",
186
+ " .dataframe thead th {\n",
187
+ " text-align: right;\n",
188
+ " }\n",
189
+ "</style>\n",
190
+ "<table border=\"1\" class=\"dataframe\">\n",
191
+ " <thead>\n",
192
+ " <tr style=\"text-align: right;\">\n",
193
+ " <th></th>\n",
194
+ " <th>Ambitious Strivers</th>\n",
195
+ " <th>Comfortable Altruistic</th>\n",
196
+ " <th>Retired and liquid</th>\n",
197
+ " <th>Living for Today</th>\n",
198
+ " <th>Struggling Families</th>\n",
199
+ " <th>High Wealth</th>\n",
200
+ " <th>Money Managers</th>\n",
201
+ " <th>Digital Pioneers</th>\n",
202
+ " <th>Ultra High Wealth</th>\n",
203
+ " </tr>\n",
204
+ " </thead>\n",
205
+ " <tbody>\n",
206
+ " <tr>\n",
207
+ " <th>0</th>\n",
208
+ " <td>10%</td>\n",
209
+ " <td>10%</td>\n",
210
+ " <td>18%</td>\n",
211
+ " <td>17%</td>\n",
212
+ " <td>18%</td>\n",
213
+ " <td>8%</td>\n",
214
+ " <td>11%</td>\n",
215
+ " <td>6%</td>\n",
216
+ " <td>2%</td>\n",
217
+ " </tr>\n",
218
+ " <tr>\n",
219
+ " <th>1</th>\n",
220
+ " <td>Young ambitous professionals, mostly men, work...</td>\n",
221
+ " <td>More to life than money; socially responsible;...</td>\n",
222
+ " <td>Over 55, active pensioners, treat themselve to...</td>\n",
223
+ " <td>Between 18 and 34 years old, independant, acce...</td>\n",
224
+ " <td>Between the ages of 21 and 40 years old. In ma...</td>\n",
225
+ " <td>Over 40 years old, independent, city dweling, ...</td>\n",
226
+ " <td>Couples who enjoy managing their money, active...</td>\n",
227
+ " <td>22- 35, Love exploring new ways to make money ...</td>\n",
228
+ " <td>Extremely high net worth from inheritied money...</td>\n",
229
+ " </tr>\n",
230
+ " <tr>\n",
231
+ " <th>2</th>\n",
232
+ " <td>£42K</td>\n",
233
+ " <td>£64k</td>\n",
234
+ " <td>£55K</td>\n",
235
+ " <td>£24k</td>\n",
236
+ " <td>£32K</td>\n",
237
+ " <td>150k</td>\n",
238
+ " <td>£55k</td>\n",
239
+ " <td>£32K</td>\n",
240
+ " <td>£750K+</td>\n",
241
+ " </tr>\n",
242
+ " <tr>\n",
243
+ " <th>3</th>\n",
244
+ " <td>NaN</td>\n",
245
+ " <td>2%</td>\n",
246
+ " <td>NaN</td>\n",
247
+ " <td>NaN</td>\n",
248
+ " <td>NaN</td>\n",
249
+ " <td>NaN</td>\n",
250
+ " <td>NaN</td>\n",
251
+ " <td>NaN</td>\n",
252
+ " <td>10%</td>\n",
253
+ " </tr>\n",
254
+ " <tr>\n",
255
+ " <th>4</th>\n",
256
+ " <td>1.4</td>\n",
257
+ " <td>1.2</td>\n",
258
+ " <td>0.7</td>\n",
259
+ " <td>0.5</td>\n",
260
+ " <td>0.5</td>\n",
261
+ " <td>0.9</td>\n",
262
+ " <td>0.4</td>\n",
263
+ " <td>1.2</td>\n",
264
+ " <td>0.8</td>\n",
265
+ " </tr>\n",
266
+ " </tbody>\n",
267
+ "</table>\n",
268
+ "</div>"
269
+ ],
270
+ "text/plain": [
271
+ " Ambitious Strivers \n",
272
+ "0 10% \\\n",
273
+ "1 Young ambitous professionals, mostly men, work... \n",
274
+ "2 £42K \n",
275
+ "3 NaN \n",
276
+ "4 1.4 \n",
277
+ "\n",
278
+ " Comfortable Altruistic \n",
279
+ "0 10% \\\n",
280
+ "1 More to life than money; socially responsible;... \n",
281
+ "2 £64k \n",
282
+ "3 2% \n",
283
+ "4 1.2 \n",
284
+ "\n",
285
+ " Retired and liquid \n",
286
+ "0 18% \\\n",
287
+ "1 Over 55, active pensioners, treat themselve to... \n",
288
+ "2 £55K \n",
289
+ "3 NaN \n",
290
+ "4 0.7 \n",
291
+ "\n",
292
+ " Living for Today \n",
293
+ "0 17% \\\n",
294
+ "1 Between 18 and 34 years old, independant, acce... \n",
295
+ "2 £24k \n",
296
+ "3 NaN \n",
297
+ "4 0.5 \n",
298
+ "\n",
299
+ " Struggling Families \n",
300
+ "0 18% \\\n",
301
+ "1 Between the ages of 21 and 40 years old. In ma... \n",
302
+ "2 £32K \n",
303
+ "3 NaN \n",
304
+ "4 0.5 \n",
305
+ "\n",
306
+ " High Wealth \n",
307
+ "0 8% \\\n",
308
+ "1 Over 40 years old, independent, city dweling, ... \n",
309
+ "2 150k \n",
310
+ "3 NaN \n",
311
+ "4 0.9 \n",
312
+ "\n",
313
+ " Money Managers \n",
314
+ "0 11% \\\n",
315
+ "1 Couples who enjoy managing their money, active... \n",
316
+ "2 £55k \n",
317
+ "3 NaN \n",
318
+ "4 0.4 \n",
319
+ "\n",
320
+ " Digital Pioneers \n",
321
+ "0 6% \\\n",
322
+ "1 22- 35, Love exploring new ways to make money ... \n",
323
+ "2 £32K \n",
324
+ "3 NaN \n",
325
+ "4 1.2 \n",
326
+ "\n",
327
+ " Ultra High Wealth \n",
328
+ "0 2% \n",
329
+ "1 Extremely high net worth from inheritied money... \n",
330
+ "2 £750K+ \n",
331
+ "3 10% \n",
332
+ "4 0.8 "
333
+ ]
334
+ },
335
+ "execution_count": 25,
336
+ "metadata": {},
337
+ "output_type": "execute_result"
338
+ }
339
+ ],
340
+ "source": [
341
+ "df1"
342
+ ]
343
+ },
344
+ {
345
+ "cell_type": "code",
346
+ "execution_count": 29,
347
+ "metadata": {},
348
+ "outputs": [],
349
+ "source": [
350
+ "list(mycsv.columns).remove('Column1')"
351
+ ]
352
+ },
353
+ {
354
+ "cell_type": "code",
355
+ "execution_count": 30,
356
+ "metadata": {},
357
+ "outputs": [
358
+ {
359
+ "data": {
360
+ "text/html": [
361
+ "<div>\n",
362
+ "<style scoped>\n",
363
+ " .dataframe tbody tr th:only-of-type {\n",
364
+ " vertical-align: middle;\n",
365
+ " }\n",
366
+ "\n",
367
+ " .dataframe tbody tr th {\n",
368
+ " vertical-align: top;\n",
369
+ " }\n",
370
+ "\n",
371
+ " .dataframe thead th {\n",
372
+ " text-align: right;\n",
373
+ " }\n",
374
+ "</style>\n",
375
+ "<table border=\"1\" class=\"dataframe\">\n",
376
+ " <thead>\n",
377
+ " <tr style=\"text-align: right;\">\n",
378
+ " <th></th>\n",
379
+ " <th>Column1</th>\n",
380
+ " <th>Ambitious Strivers</th>\n",
381
+ " <th>Comfortable Altruistic</th>\n",
382
+ " <th>Retired and liquid</th>\n",
383
+ " <th>Living for Today</th>\n",
384
+ " <th>Struggling Families</th>\n",
385
+ " <th>High Wealth</th>\n",
386
+ " <th>Money Managers</th>\n",
387
+ " <th>Digital Pioneers</th>\n",
388
+ " <th>Ultra High Wealth</th>\n",
389
+ " </tr>\n",
390
+ " </thead>\n",
391
+ " <tbody>\n",
392
+ " <tr>\n",
393
+ " <th>0</th>\n",
394
+ " <td>Proportion Sample</td>\n",
395
+ " <td>10%</td>\n",
396
+ " <td>10%</td>\n",
397
+ " <td>18%</td>\n",
398
+ " <td>17%</td>\n",
399
+ " <td>18%</td>\n",
400
+ " <td>8%</td>\n",
401
+ " <td>11%</td>\n",
402
+ " <td>6%</td>\n",
403
+ " <td>2%</td>\n",
404
+ " </tr>\n",
405
+ " <tr>\n",
406
+ " <th>1</th>\n",
407
+ " <td>Description</td>\n",
408
+ " <td>Young ambitous professionals, mostly men, work...</td>\n",
409
+ " <td>More to life than money; socially responsible;...</td>\n",
410
+ " <td>Over 55, active pensioners, treat themselve to...</td>\n",
411
+ " <td>Between 18 and 34 years old, independant, acce...</td>\n",
412
+ " <td>Between the ages of 21 and 40 years old. In ma...</td>\n",
413
+ " <td>Over 40 years old, independent, city dweling, ...</td>\n",
414
+ " <td>Couples who enjoy managing their money, active...</td>\n",
415
+ " <td>22- 35, Love exploring new ways to make money ...</td>\n",
416
+ " <td>Extremely high net worth from inheritied money...</td>\n",
417
+ " </tr>\n",
418
+ " <tr>\n",
419
+ " <th>2</th>\n",
420
+ " <td>Household Income</td>\n",
421
+ " <td>£42K</td>\n",
422
+ " <td>£64k</td>\n",
423
+ " <td>£55K</td>\n",
424
+ " <td>£24k</td>\n",
425
+ " <td>£32K</td>\n",
426
+ " <td>150k</td>\n",
427
+ " <td>£55k</td>\n",
428
+ " <td>£32K</td>\n",
429
+ " <td>£750K+</td>\n",
430
+ " </tr>\n",
431
+ " <tr>\n",
432
+ " <th>3</th>\n",
433
+ " <td>dropout %</td>\n",
434
+ " <td>NaN</td>\n",
435
+ " <td>2%</td>\n",
436
+ " <td>NaN</td>\n",
437
+ " <td>NaN</td>\n",
438
+ " <td>NaN</td>\n",
439
+ " <td>NaN</td>\n",
440
+ " <td>NaN</td>\n",
441
+ " <td>NaN</td>\n",
442
+ " <td>10%</td>\n",
443
+ " </tr>\n",
444
+ " <tr>\n",
445
+ " <th>4</th>\n",
446
+ " <td>Propensity to Buy</td>\n",
447
+ " <td>1.4</td>\n",
448
+ " <td>1.2</td>\n",
449
+ " <td>0.7</td>\n",
450
+ " <td>0.5</td>\n",
451
+ " <td>0.5</td>\n",
452
+ " <td>0.9</td>\n",
453
+ " <td>0.4</td>\n",
454
+ " <td>1.2</td>\n",
455
+ " <td>0.8</td>\n",
456
+ " </tr>\n",
457
+ " </tbody>\n",
458
+ "</table>\n",
459
+ "</div>"
460
+ ],
461
+ "text/plain": [
462
+ " Column1 Ambitious Strivers \n",
463
+ "0 Proportion Sample 10% \\\n",
464
+ "1 Description Young ambitous professionals, mostly men, work... \n",
465
+ "2 Household Income £42K \n",
466
+ "3 dropout % NaN \n",
467
+ "4 Propensity to Buy 1.4 \n",
468
+ "\n",
469
+ " Comfortable Altruistic \n",
470
+ "0 10% \\\n",
471
+ "1 More to life than money; socially responsible;... \n",
472
+ "2 £64k \n",
473
+ "3 2% \n",
474
+ "4 1.2 \n",
475
+ "\n",
476
+ " Retired and liquid \n",
477
+ "0 18% \\\n",
478
+ "1 Over 55, active pensioners, treat themselve to... \n",
479
+ "2 £55K \n",
480
+ "3 NaN \n",
481
+ "4 0.7 \n",
482
+ "\n",
483
+ " Living for Today \n",
484
+ "0 17% \\\n",
485
+ "1 Between 18 and 34 years old, independant, acce... \n",
486
+ "2 £24k \n",
487
+ "3 NaN \n",
488
+ "4 0.5 \n",
489
+ "\n",
490
+ " Struggling Families \n",
491
+ "0 18% \\\n",
492
+ "1 Between the ages of 21 and 40 years old. In ma... \n",
493
+ "2 £32K \n",
494
+ "3 NaN \n",
495
+ "4 0.5 \n",
496
+ "\n",
497
+ " High Wealth \n",
498
+ "0 8% \\\n",
499
+ "1 Over 40 years old, independent, city dweling, ... \n",
500
+ "2 150k \n",
501
+ "3 NaN \n",
502
+ "4 0.9 \n",
503
+ "\n",
504
+ " Money Managers \n",
505
+ "0 11% \\\n",
506
+ "1 Couples who enjoy managing their money, active... \n",
507
+ "2 £55k \n",
508
+ "3 NaN \n",
509
+ "4 0.4 \n",
510
+ "\n",
511
+ " Digital Pioneers \n",
512
+ "0 6% \\\n",
513
+ "1 22- 35, Love exploring new ways to make money ... \n",
514
+ "2 £32K \n",
515
+ "3 NaN \n",
516
+ "4 1.2 \n",
517
+ "\n",
518
+ " Ultra High Wealth \n",
519
+ "0 2% \n",
520
+ "1 Extremely high net worth from inheritied money... \n",
521
+ "2 £750K+ \n",
522
+ "3 10% \n",
523
+ "4 0.8 "
524
+ ]
525
+ },
526
+ "execution_count": 30,
527
+ "metadata": {},
528
+ "output_type": "execute_result"
529
+ }
530
+ ],
531
+ "source": [
532
+ "mycsv"
533
+ ]
534
+ },
535
+ {
536
+ "cell_type": "code",
537
+ "execution_count": 36,
538
+ "metadata": {},
539
+ "outputs": [
540
+ {
541
+ "data": {
542
+ "text/plain": [
543
+ "'Young ambitous professionals, mostly men, work hard play attitude, competitive with peers and treat themselves to expensive things, Independent, enjoy using the internet, searching for the best deal, not always brand loyal, look for the best solution case by case, want to be recognised for their achievements'"
544
+ ]
545
+ },
546
+ "execution_count": 36,
547
+ "metadata": {},
548
+ "output_type": "execute_result"
549
+ }
550
+ ],
551
+ "source": [
552
+ "mycsv['Ambitious Strivers'][pd.Index(mycsv['Column1']).get_loc('Description')]"
553
+ ]
554
+ },
555
+ {
556
+ "cell_type": "code",
557
+ "execution_count": null,
558
+ "metadata": {},
559
+ "outputs": [],
560
+ "source": []
561
+ }
562
+ ],
563
+ "metadata": {
564
+ "kernelspec": {
565
+ "display_name": "Python 3",
566
+ "language": "python",
567
+ "name": "python3"
568
+ },
569
+ "language_info": {
570
+ "codemirror_mode": {
571
+ "name": "ipython",
572
+ "version": 3
573
+ },
574
+ "file_extension": ".py",
575
+ "mimetype": "text/x-python",
576
+ "name": "python",
577
+ "nbconvert_exporter": "python",
578
+ "pygments_lexer": "ipython3",
579
+ "version": "3.10.11"
580
+ }
581
+ },
582
+ "nbformat": 4,
583
+ "nbformat_minor": 2
584
+ }
utils.py CHANGED
@@ -20,7 +20,9 @@ def load_json_from_string(json_string):
20
  def concatenate_keys(keys):
21
  concatenated_string = ""
22
  for i, d in enumerate(keys, start=1):
23
- concatenated_string += f"{d} "
 
 
24
  return concatenated_string.strip()
25
 
26
  def transform_to_dict_of_dicts(columns, rows):
@@ -29,7 +31,7 @@ def transform_to_dict_of_dicts(columns, rows):
29
 
30
  # Iterate over each row
31
  for row in rows:
32
- print(dict(row))
33
  # The first element of the row is the key for the outer dictionary
34
  outer_key = row[0].strip()
35
 
@@ -55,7 +57,7 @@ def transform_topologies_to_dict(columns, rows):
55
 
56
  # Iterate over each row
57
  for row in rows:
58
- print(dict(row))
59
  # The first element of the row is the key for the outer dictionary
60
  outer_key = row[0].strip()
61
 
@@ -75,39 +77,69 @@ def transform_topologies_to_dict(columns, rows):
75
  return result
76
 
77
  def findTop3MoneyNeeds(proposition):
78
- moneyNeeds, rows = fetch_db_rows_as_dicts('money_needs.sqlite', 'money_needs')
79
  moneyNeedsDict = transform_to_dict_of_dicts(moneyNeeds, rows)
80
- print(list(moneyNeedsDict.keys()))
81
  needs = findTop3Needs(proposition, list(moneyNeedsDict.keys()))
82
  needDictIndexes = []
83
  for need in needs:
84
  needDictIndexes.append(moneyNeedsDict[need])
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  print(needDictIndexes)
87
  return needs, needDictIndexes
88
 
89
 
90
- def findTop3Needs(proposition, moneyNeeds):
91
 
92
- moneyNeedsString = concatenate_keys(moneyNeeds)
93
 
94
- prompt = '''You have these listed needs of customers
95
  {}
96
 
97
  Now given a proposition
98
  "{}"
99
 
100
- Find the best 3 strings out of the list which matches this proposition. Return output strictly only in json under a list called matches
101
  '''
102
 
103
- moneyNeedsPrompt = prompt.format(moneyNeedsString, proposition)
104
- response = model.generate_content([moneyNeedsPrompt])
 
105
  output = response.text
106
  output = output.replace('```json', '')
107
  output = output.replace('```', '')
108
  obj = load_json_from_string(output)
109
  print(obj)
110
- return obj['matches']
 
 
111
 
112
 
113
  def findTop3Topologies(proposition, demographic):
@@ -156,36 +188,39 @@ def findTop3Topologies(proposition, demographic):
156
  return obj['matches'], topologyDetails
157
 
158
 
159
- def findTop3Needs(proposition, moneyNeeds):
160
 
161
- moneyNeedsString = concatenate_keys(moneyNeeds)
 
162
 
163
- prompt = '''You have these listed needs of customers
164
- {}
165
 
166
- Now given a proposition
167
- "{}"
168
 
169
- Find the best 3 strings out of the list which matches this proposition. Return output strictly only in json under a list called matches
170
- '''
171
 
172
- moneyNeedsPrompt = prompt.format(moneyNeedsString, proposition)
173
- response = model.generate_content([moneyNeedsPrompt])
174
- output = response.text
175
- output = output.replace('```json', '')
176
- output = output.replace('```', '')
177
- obj = load_json_from_string(output)
178
- print(obj)
179
- return obj['matches']
180
 
181
 
182
  # findTop3Topologies('We have a product for family people giving them discounts and low interest loans for home appliances. They can pay us back in small instalments over the course of 4 years',
183
  # 'CharlesTown city people are young families people mostly with a population of 20000. Out of this 65% are between the age of 30-45. Most of them have kids aged between 0-15')
184
 
185
- findTop3MoneyNeeds('We have a product for family people giving them discounts and low interest loans for home appliances. They can pay us back in small instalments over the course of 4 years')
186
 
187
  #We provide a credit card which gives 10% discount on purchasing home appliances and also provides low interest rates based loans
188
 
 
 
189
  # subscriber take out
190
 
191
  # 250 and below with a negative factor of 2.0
 
20
  def concatenate_keys(keys):
21
  concatenated_string = ""
22
  for i, d in enumerate(keys, start=1):
23
+ concatenated_string += f"{i}. {d}"
24
+ print('##########################')
25
+ print(concatenated_string.strip())
26
  return concatenated_string.strip()
27
 
28
  def transform_to_dict_of_dicts(columns, rows):
 
31
 
32
  # Iterate over each row
33
  for row in rows:
34
+ #print(dict(row))
35
  # The first element of the row is the key for the outer dictionary
36
  outer_key = row[0].strip()
37
 
 
57
 
58
  # Iterate over each row
59
  for row in rows:
60
+ #print(dict(row))
61
  # The first element of the row is the key for the outer dictionary
62
  outer_key = row[0].strip()
63
 
 
77
  return result
78
 
79
  def findTop3MoneyNeeds(proposition):
80
+ moneyNeeds, rows = fetch_db_rows_as_dicts('data.sqlite', 'money_needs')
81
  moneyNeedsDict = transform_to_dict_of_dicts(moneyNeeds, rows)
82
+ #print(list(moneyNeedsDict.keys()))
83
  needs = findTop3Needs(proposition, list(moneyNeedsDict.keys()))
84
  needDictIndexes = []
85
  for need in needs:
86
  needDictIndexes.append(moneyNeedsDict[need])
87
 
88
+ #print(needDictIndexes)
89
+ return needs, needDictIndexes
90
+
91
+ def findTop3CustomerExperienceNeeds(proposition):
92
+ moneyNeeds, rows = fetch_db_rows_as_dicts('data.sqlite', 'customer_exp')
93
+ moneyNeedsDict = transform_to_dict_of_dicts(moneyNeeds, rows)
94
+ #print(list(moneyNeedsDict.keys()))
95
+ needs = findTop3Needs(proposition, list(moneyNeedsDict.keys()))
96
+ needDictIndexes = []
97
+ for need in needs:
98
+ needDictIndexes.append(moneyNeedsDict[need])
99
+
100
+ #print(needDictIndexes)
101
+ return needs, needDictIndexes
102
+
103
+
104
+ def findTop3SustainabilityNeeds(proposition):
105
+ print(" Proposition sustain = {}".format(proposition))
106
+ allNeeds, rows = fetch_db_rows_as_dicts('data.sqlite', 'sustainability')
107
+ needsDict = transform_to_dict_of_dicts(allNeeds, rows)
108
+
109
+ needs = findTop3Needs(proposition, list(needsDict.keys()))
110
+ needDictIndexes = []
111
+ print(list(needsDict.keys()))
112
+ for need in needs:
113
+ needDictIndexes.append(needsDict[need])
114
+
115
  print(needDictIndexes)
116
  return needs, needDictIndexes
117
 
118
 
119
+ def findTop3Needs(proposition, needs):
120
 
121
+ needsString = concatenate_keys(needs)
122
 
123
+ prompt = '''You have this comma separated listed needs of customers
124
  {}
125
 
126
  Now given a proposition
127
  "{}"
128
 
129
+ Find the best 3 strings out of the above numbered list which best matches this proposition. Return in output only the number next to the matching string strictly only in json under a list called matches
130
  '''
131
 
132
+ needsPrompt = prompt.format(needsString, proposition)
133
+ print(needsPrompt)
134
+ response = model.generate_content([needsPrompt])
135
  output = response.text
136
  output = output.replace('```json', '')
137
  output = output.replace('```', '')
138
  obj = load_json_from_string(output)
139
  print(obj)
140
+
141
+ needsIndexes = [needs[int(idx)-1] for idx in obj['matches']]
142
+ return needsIndexes #obj['matches']
143
 
144
 
145
  def findTop3Topologies(proposition, demographic):
 
188
  return obj['matches'], topologyDetails
189
 
190
 
191
+ # def findTop3Needs(proposition, moneyNeeds):
192
 
193
+ # moneyNeedsString = concatenate_keys(moneyNeeds)
194
+ # print(moneyNeedsString)
195
 
196
+ # prompt = '''You have these listed needs of customers
197
+ # {}
198
 
199
+ # Now given a proposition
200
+ # "{}"
201
 
202
+ # Find the best 3 strings out of the list which matches this proposition. Return output strictly only in json under a list called matches
203
+ # '''
204
 
205
+ # moneyNeedsPrompt = prompt.format(moneyNeedsString, proposition)
206
+ # response = model.generate_content([moneyNeedsPrompt])
207
+ # output = response.text
208
+ # output = output.replace('```json', '')
209
+ # output = output.replace('```', '')
210
+ # obj = load_json_from_string(output)
211
+ # print(obj)
212
+ # return obj['matches']
213
 
214
 
215
  # findTop3Topologies('We have a product for family people giving them discounts and low interest loans for home appliances. They can pay us back in small instalments over the course of 4 years',
216
  # 'CharlesTown city people are young families people mostly with a population of 20000. Out of this 65% are between the age of 30-45. Most of them have kids aged between 0-15')
217
 
218
+ #findTop3SustainabilityNeeds('We support Home appliances are all electric and use no fuel based energy')
219
 
220
  #We provide a credit card which gives 10% discount on purchasing home appliances and also provides low interest rates based loans
221
 
222
+ #customer need - We provide our customer with utmost comfort and at home service
223
+
224
  # subscriber take out
225
 
226
  # 250 and below with a negative factor of 2.0