Spaces:
Sleeping
Sleeping
ruchi
commited on
Commit
·
44173cd
1
Parent(s):
f08130b
Add end to end workflow with topologies
Browse files- app.py +81 -5
- topologies_desc.csv +6 -0
- utils.py +13 -3
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
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)
|
@@ -24,7 +25,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 |
-
subscriberTakeOut = st.
|
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.")
|
@@ -78,16 +79,22 @@ Only show the table and conclusion remarks if the proposition suits the target a
|
|
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.
|
@@ -98,7 +105,7 @@ if submit_button:
|
|
98 |
|
99 |
topMoneyNeeds, topMoneyNeedsDict = findTop3MoneyNeeds(moneyNeeds)
|
100 |
|
101 |
-
matchingTopologies,
|
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",)
|
@@ -111,7 +118,76 @@ if submit_button:
|
|
111 |
|
112 |
for idx, topology in enumerate(matchingTopologies):
|
113 |
st.write("{}. {}".format(idx+1, topology))
|
114 |
-
|
115 |
-
#st.write(response.text)
|
116 |
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
+
import math
|
4 |
import google.generativeai as genai
|
5 |
GOOGLE_API_KEY= os.getenv('GEMINI_API_KEY')
|
6 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
|
25 |
|
26 |
selectedCity = st.selectbox("Please select the City and the Bank Product for Your Proposition.", ["CharlesTown", "Limburg"])
|
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.")
|
|
|
79 |
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.'''
|
80 |
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'''
|
81 |
|
82 |
+
CharlesTownPopulation = 10000
|
83 |
+
LimburgTownPopulation = 20000
|
84 |
+
|
85 |
demographic = ''
|
86 |
+
population = 0
|
87 |
if selectedCity:
|
88 |
if selectedCity == 'CharlesTown':
|
89 |
|
90 |
st.write(CharlesTownDemographic)
|
91 |
demographic = CharlesTownDemographic
|
92 |
+
population = CharlesTownPopulation
|
93 |
|
94 |
if selectedCity == 'Limburg':
|
95 |
st.write(LimburgTownDemographic)
|
96 |
demographic = LimburgTownDemographic
|
97 |
+
population = LimburgTownPopulation
|
98 |
|
99 |
if submit_button:
|
100 |
proposal = '''Given proposal is for the city {} with product {}. The propsal is as below.
|
|
|
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",)
|
|
|
118 |
|
119 |
for idx, topology in enumerate(matchingTopologies):
|
120 |
st.write("{}. {}".format(idx+1, topology))
|
|
|
|
|
121 |
|
122 |
+
topologySumDict = {}
|
123 |
+
|
124 |
+
for topology in matchingTopologies:
|
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]))
|
132 |
+
|
133 |
+
totalSubscriberTakeOut = 0
|
134 |
+
for topology in matchingTopologies:
|
135 |
+
proportion = int(topologyDetails[topology]['Proportion Sample'].replace('%', ''))
|
136 |
+
topologyPopulation = math.floor((proportion * population) / 100)
|
137 |
+
|
138 |
+
topologyScore = topologySumDict[topology]
|
139 |
+
|
140 |
+
topologyPopulation = math.floor(topologyPopulation/2)
|
141 |
+
if topologyScore <=250:
|
142 |
+
topologyPopulation = topologyPopulation/2
|
143 |
+
|
144 |
+
elif topologyScore >250 and topologyScore<=260:
|
145 |
+
topologyPopulation = math.floor(topologyPopulation/1.8)
|
146 |
+
|
147 |
+
elif topologyScore >260 and topologyScore<=270:
|
148 |
+
topologyPopulation = math.floor(topologyPopulation/1.6)
|
149 |
+
|
150 |
+
elif topologyScore >270 and topologyScore<=280:
|
151 |
+
topologyPopulation = math.floor(topologyPopulation/1.4)
|
152 |
+
|
153 |
+
elif topologyScore >280 and topologyScore<=300:
|
154 |
+
topologyPopulation = topologyPopulation
|
155 |
+
|
156 |
+
elif topologyScore >300 and topologyScore<=310:
|
157 |
+
topologyPopulation = math.floor(topologyPopulation * 1.2)
|
158 |
+
|
159 |
+
elif topologyScore >310 and topologyScore<=320:
|
160 |
+
topologyPopulation = math.floor(topologyPopulation * 1.4)
|
161 |
+
|
162 |
+
elif topologyScore >320 and topologyScore<=340:
|
163 |
+
topologyPopulation = math.floor(topologyPopulation * 1.5)
|
164 |
+
|
165 |
+
elif topologyScore >340 and topologyScore<=360:
|
166 |
+
topologyPopulation = math.floor(topologyPopulation * 1.6)
|
167 |
+
|
168 |
+
else:
|
169 |
+
topologyPopulation = math.floor(topologyPopulation * 2)
|
170 |
+
|
171 |
+
totalSubscriberTakeOut = totalSubscriberTakeOut + topologyPopulation
|
172 |
+
st.write("{}. {} and has subscriber takeout of {}".format(topology, topologySumDict[topology], topologyPopulation))
|
173 |
+
|
174 |
+
st.write(" Target Subscriber takeout = {}".format(totalSubscriberTakeOut))
|
175 |
+
st.write(" Total Subscriber takeout = {}".format(subscriberTakeOut))
|
176 |
+
|
177 |
+
if totalSubscriberTakeOut<subscriberTakeOut:
|
178 |
+
st.write("Sorry Your proposition did not match the target subscriber take out. Takeout score difference = {}".format(subscriberTakeOut-totalSubscriberTakeOut))
|
179 |
+
elif totalSubscriberTakeOut==subscriberTakeOut:
|
180 |
+
st.write("Great Job !! Your proposition exactly match the target subscriber take out.")
|
181 |
+
else:
|
182 |
+
st.write("Congratulations!! Your proposition exceeds the target subscriber take out. Additional takeout = {}".format(totalSubscriberTakeOut- subscriberTakeOut))
|
183 |
+
|
184 |
+
|
185 |
+
# 250 and below with a negative factor of 2.0
|
186 |
+
# 260 with a negative factor of 1.8
|
187 |
+
# 270 with a negative factor of 1.6
|
188 |
+
# 280 with a negative factor of 1.0
|
189 |
+
# 300 with a factor of 1
|
190 |
+
# 310 with a factor of 1.2
|
191 |
+
# 320 with a factor of 1.4
|
192 |
+
# 340 with a factor or 1.5
|
193 |
+
# 360+ with a factor of 2.0
|
topologies_desc.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Column1,Ambitious Strivers,Comfortable Altruistic,Retired and liquid,Living for Today,Struggling Families,High Wealth,Money Managers,Digital Pioneers,Ultra High Wealth,
|
2 |
+
Proportion Sample,10%,10%,18%,17%,18%,8%,11%,6%,2%,
|
3 |
+
Description,"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","More to life than money; socially responsible; do their bit for the environment, give time and money to causes that matter, Money cautios, they don�t get a kick out of making money; the use comparison tables and like to keep a distance from big banks","Over 55, active pensioners, treat themselve to short holidays, money cautious, use comparison tables to get the best deals, loyal to banks, not self directed, more to life than money, have family with children either at university or in early employment","Between 18 and 34 years old, independant, accept being in debt, salary spent at end of month, rented / shared accomodation or living at home, working in first job or in academic education","Between the ages of 21 and 40 years old. In manual or zero hour contracts, struggle to manage outgoings, have trouble managing finances to the end of the month and so low savings; in rented accomodation; dependant on support network (family) to get by","Over 40 years old, independent, city dweling, working in the professional services/banking or property sector. Has expensive tastes, owne more than 1 property, and has investments.","Couples who enjoy managing their money, actively looking for the best deal, and move money around to get the base offer. Not loyal to brands and mistrust financial instutions. In active employment but save aggressively. Do not like being in debt.","22- 35, Love exploring new ways to make money through digital means. Less afraid of risk, Open to new payment methods and technologies - like Crypto, online investing, Actively use technology to do this. Single below 40 living in metropolitan areas","Extremely high net worth from inheritied money or from CX role in a blue chip or successful entrepreneur.. Loves the high life, travels frequently, takes risky investments, has prpoerties around the world, very discreet with income and spend",
|
4 |
+
Household Income,�42K,�64k,�55K,�24k,�32K,150k,�55k,�32K,�750K+,
|
5 |
+
dropout %,,2%,,,,,,,10%,
|
6 |
+
Propensity to Buy,1.4,1.2,0.7,0.5,0.5,0.9,0.4,1.2,0.8,
|
utils.py
CHANGED
@@ -4,7 +4,7 @@ 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)
|
9 |
model = genai.GenerativeModel(model_name = "gemini-pro")
|
10 |
|
@@ -153,7 +153,7 @@ def findTop3Topologies(proposition, demographic):
|
|
153 |
output = output.replace('```', '')
|
154 |
obj = load_json_from_string(output)
|
155 |
print(obj)
|
156 |
-
return obj['matches'],
|
157 |
|
158 |
|
159 |
def findTop3Needs(proposition, moneyNeeds):
|
@@ -182,8 +182,18 @@ def findTop3Needs(proposition, moneyNeeds):
|
|
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 |
-
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
9 |
model = genai.GenerativeModel(model_name = "gemini-pro")
|
10 |
|
|
|
153 |
output = output.replace('```', '')
|
154 |
obj = load_json_from_string(output)
|
155 |
print(obj)
|
156 |
+
return obj['matches'], topologyDetails
|
157 |
|
158 |
|
159 |
def findTop3Needs(proposition, moneyNeeds):
|
|
|
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
|
192 |
+
# 260 with a negative factor of 1.8
|
193 |
+
# 270 with a negative factor of 1.6
|
194 |
+
# 280 with a negative factor of 1.0
|
195 |
+
# 300 with a factor of 1
|
196 |
+
# 310 with a factor of 1.2
|
197 |
+
# 320 with a factor of 1.4
|
198 |
+
# 340 with a factor or 1.5
|
199 |
+
# 360+ with a factor of 2.0
|