ruchi commited on
Commit
f08130b
·
1 Parent(s): e209a2d

Add topology calculation

Browse files
Files changed (2) hide show
  1. app.py +22 -6
  2. utils.py +46 -19
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import streamlit as st
2
  import os
3
  import google.generativeai as genai
4
- GOOGLE_API_KEY= 'AIzaSyC0T2fN5Dga-6nkPc6HYV7-bDZskqgALX0' #os.getenv('GEMINI_API_KEY')
5
  genai.configure(api_key=GOOGLE_API_KEY)
6
  model = genai.GenerativeModel(model_name = "gemini-pro")
7
- from utils import findTop3MoneyNeeds
8
 
9
 
10
  # Create a banner using Markdown
@@ -24,6 +24,7 @@ st.markdown(
24
 
25
  selectedCity = st.selectbox("Please select the City and the Bank Product for Your Proposition.", ["CharlesTown", "Limburg"])
26
  selectedProduct = st.selectbox("Please select the Product", ["Current", "Mortage", "Credit Card", "Crypto"])
 
27
  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.")
28
  customerExperience = st.text_area("Describe the customer experience needs of your target audience.")
29
  sutainabilityNeeds = st.text_area("Describe the sutainability needs of your target audience.")
@@ -46,7 +47,7 @@ Question: what is the key demographic behaviour?
46
  Answer: They want connect on Social Media sites
47
  Question: Prime Money Attitudes?
48
  Answer: They want great deals and want to manage things independantly
49
- Question: Brand needs?
50
  Answer: They want the brand to be fun and positive
51
 
52
  Analyse this proposition and score it on the below criteria based upon its popularity within the audience 'Living of today'
@@ -74,13 +75,20 @@ Only show the table and conclusion remarks if the proposition suits the target a
74
  {{0}}
75
  '''
76
 
 
 
 
 
77
  if selectedCity:
78
  if selectedCity == 'CharlesTown':
79
- st.write('''{} city people are Living for today people mostly with a population of 10000. Out of this 65% are between the age of 18-25.'''.format(selectedCity))
 
 
80
 
81
  if selectedCity == 'Limburg':
82
- st.write('''{} 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
83
- them have kids aged between 0-15'''.format(selectedCity))
 
84
  if submit_button:
85
  proposal = '''Given proposal is for the city {} with product {}. The propsal is as below.
86
  {}'''
@@ -90,11 +98,19 @@ if submit_button:
90
 
91
  topMoneyNeeds, topMoneyNeedsDict = findTop3MoneyNeeds(moneyNeeds)
92
 
 
 
93
  response = model.generate_content([pre_prompt.format(proposal)])
94
  st.write("As per your money needs your product is mostly targeting the below spending patterns",)
95
 
96
  for idx, need in enumerate(topMoneyNeeds):
97
  st.write("{}. {}".format(idx+1, need))
 
 
 
 
 
 
98
 
99
  #st.write(response.text)
100
 
 
1
  import streamlit as st
2
  import os
3
  import google.generativeai as genai
4
+ GOOGLE_API_KEY= os.getenv('GEMINI_API_KEY')
5
  genai.configure(api_key=GOOGLE_API_KEY)
6
  model = genai.GenerativeModel(model_name = "gemini-pro")
7
+ from utils import findTop3MoneyNeeds, findTop3Topologies
8
 
9
 
10
  # Create a banner using Markdown
 
24
 
25
  selectedCity = st.selectbox("Please select the City and the Bank Product for Your Proposition.", ["CharlesTown", "Limburg"])
26
  selectedProduct = st.selectbox("Please select the Product", ["Current", "Mortage", "Credit Card", "Crypto"])
27
+ subscriberTakeOut = st.text_area("Please enter your subscriber take out")
28
  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.")
29
  customerExperience = st.text_area("Describe the customer experience needs of your target audience.")
30
  sutainabilityNeeds = st.text_area("Describe the sutainability needs of your target audience.")
 
47
  Answer: They want connect on Social Media sites
48
  Question: Prime Money Attitudes?
49
  Answer: They want great deals and want to manage things independantly
50
+ Question: Brand needs?sss
51
  Answer: They want the brand to be fun and positive
52
 
53
  Analyse this proposition and score it on the below criteria based upon its popularity within the audience 'Living of today'
 
75
  {{0}}
76
  '''
77
 
78
+ CharlesTownDemographic = '''CharlesTown city people are Living for today people mostly with a population of 10000. Out of this 65% are between the age of 18-25.'''
79
+ LimburgTownDemographic = '''Limburg 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'''
80
+
81
+ demographic = ''
82
  if selectedCity:
83
  if selectedCity == 'CharlesTown':
84
+
85
+ st.write(CharlesTownDemographic)
86
+ demographic = CharlesTownDemographic
87
 
88
  if selectedCity == 'Limburg':
89
+ st.write(LimburgTownDemographic)
90
+ demographic = LimburgTownDemographic
91
+
92
  if submit_button:
93
  proposal = '''Given proposal is for the city {} with product {}. The propsal is as below.
94
  {}'''
 
98
 
99
  topMoneyNeeds, topMoneyNeedsDict = findTop3MoneyNeeds(moneyNeeds)
100
 
101
+ matchingTopologies, topologies = findTop3Topologies(proposal, demographic)
102
+
103
  response = model.generate_content([pre_prompt.format(proposal)])
104
  st.write("As per your money needs your product is mostly targeting the below spending patterns",)
105
 
106
  for idx, need in enumerate(topMoneyNeeds):
107
  st.write("{}. {}".format(idx+1, need))
108
+
109
+
110
+ st.write("As per your demographic and your proposition here are the three topologies you are targeting",)
111
+
112
+ for idx, topology in enumerate(matchingTopologies):
113
+ st.write("{}. {}".format(idx+1, topology))
114
 
115
  #st.write(response.text)
116
 
utils.py CHANGED
@@ -2,6 +2,7 @@ from db import fetch_db_rows_as_dicts
2
  import google.generativeai as genai
3
  import json
4
  import os
 
5
 
6
  GOOGLE_API_KEY=os.getenv('GEMINI_API_KEY')
7
  genai.configure(api_key=GOOGLE_API_KEY)
@@ -109,28 +110,50 @@ def findTop3Needs(proposition, moneyNeeds):
109
  return obj['matches']
110
 
111
 
112
- def findTop3Topologies(proposition):
113
- topologies, rows = fetch_db_rows_as_dicts('topologies.sqlite', 'topologies')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
- topologiesDict = transform_to_dict_of_dicts(topologies, rows)
116
- print(topologiesDict)
117
- # prompt = '''You have these listed needs of customers
118
- # {}
119
 
120
- # Now given a proposition
121
- # "{}"
 
122
 
123
- # Find the best 3 strings out of the list which matches this proposition. Return output strictly only in json under a list called matches
124
- # '''
125
 
126
- # moneyNeedsPrompt = prompt.format(moneyNeedsString, proposition)
127
- # response = model.generate_content([moneyNeedsPrompt])
128
- # output = response.text
129
- # output = output.replace('```json', '')
130
- # output = output.replace('```', '')
131
- # obj = load_json_from_string(output)
132
- # print(obj)
133
- # return obj['matches']
134
 
135
 
136
  def findTop3Needs(proposition, moneyNeeds):
@@ -156,7 +179,11 @@ def findTop3Needs(proposition, moneyNeeds):
156
  return obj['matches']
157
 
158
 
159
- #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')
 
 
160
  #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')
161
 
162
  #We provide a credit card which gives 10% discount on purchasing home appliances and also provides low interest rates based loans
 
 
 
2
  import google.generativeai as genai
3
  import json
4
  import os
5
+ import pandas as pd
6
 
7
  GOOGLE_API_KEY=os.getenv('GEMINI_API_KEY')
8
  genai.configure(api_key=GOOGLE_API_KEY)
 
110
  return obj['matches']
111
 
112
 
113
+ def findTop3Topologies(proposition, demographic):
114
+
115
+ topologies = pd.read_csv('topologies_desc.csv', encoding = "ISO-8859-1")
116
+
117
+ topologies = topologies.dropna(axis=1, how='all')
118
+
119
+ topologyAttributes = topologies['Column1']
120
+ topologyNames = list(topologies.columns)
121
+ topologyNames.remove('Column1')
122
+
123
+ #print(" topologyNames = {} ", topologyNames)
124
+
125
+ topologyDetails = {}
126
+
127
+ for name in topologyNames:
128
+ topologyDetails[name] = {}
129
+ for attribute in topologyAttributes:
130
+ topologyDetails[name][attribute] = topologies[name][pd.Index(topologies['Column1']).get_loc(attribute)]
131
+
132
+ prompt = '''You have these listed topology names of a demographic in comma separated values below
133
+ {}
134
+
135
+ Now for each of these above topologies here are the details
136
+ {}
137
+
138
+ Now given a proposition details below
139
 
140
+ {}
 
 
 
141
 
142
+ and given a demographic details below
143
+
144
+ {}
145
 
146
+ Find the best 3 common strings out of the topology names which matches the proposition and the demographic the most. Return output strictly only in json under a list called matches
147
+ '''
148
 
149
+ topologyPrompt = prompt.format(", ".join(topologyNames), str(topologyDetails), proposition, demographic)
150
+ response = model.generate_content([topologyPrompt])
151
+ output = response.text
152
+ output = output.replace('```json', '')
153
+ output = output.replace('```', '')
154
+ obj = load_json_from_string(output)
155
+ print(obj)
156
+ return obj['matches'], topologies
157
 
158
 
159
  def findTop3Needs(proposition, moneyNeeds):
 
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