blueAI / app.py
ruchi
Fix subscriber take up count to 3 values
e8b5d00
import streamlit as st
import os
import math
import google.generativeai as genai
GOOGLE_API_KEY=os.getenv('GEMINI_API_KEY')
genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel(model_name = "gemini-pro")
from utils import findTop3MoneyNeeds, findTop3Topologies, findTop3CustomerExperienceNeeds, findTop3SustainabilityNeeds, listNeeds, generatePropositionExample
# Create a banner using Markdown
st.markdown(
"""
<div style="min-width: 1000px;">
<div style="background-color:#87CEEB;padding:10px;border-radius:10px;">
<h1 style="color:white;text-align:center;">Blue AI</h1>
</div>
<div style="color:black;text-align:center;">
<h1>Welcome to the Proposition Management Tool</h1>
</div>
</div>
""",
unsafe_allow_html=True
)
selectedCity = st.selectbox("Please select the City and the Bank Product for Your Proposition.", ["CharlesTown", "Limburg"])
selectedProduct = st.selectbox("Please select the Product", ["Current", "Mortage", "Credit Card", "Crypto"])
subscriberTakeOut = st.number_input("Please enter your subscriber take up target for year 1", min_value=0, step=1)
subscriberTakeOutYear2 = st.number_input("Please enter your subscriber take up target for year 2", min_value=0, step=1)
subscriberTakeOutYear3 = st.number_input("Please enter your subscriber take up target for year 3", min_value=0, step=1)
productName = st.text_input("Please enter your product name")
moneyNeedsList, moneyNeedsDict = listNeeds('money_needs')
customerExperienceList, customerExperienceDict = listNeeds('customer_exp')
sutainabilityNeedsList, sutainabilityNeedsDict = listNeeds('sustainability')
moneyNeeds = st.multiselect(
label="Select three money needs of your target audience which best describe their spending",
options=moneyNeedsList,
max_selections=3
)
customerExperience = st.multiselect(
label="Select three options which best describe the cuetomer experience you are targeting to provide",
options=customerExperienceList,
max_selections=3
)
sutainabilityNeeds = st.multiselect(
label="Select three options which best describe the sustainability needs of your customer",
options=sutainabilityNeedsList,
max_selections=3
)
#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.")
#customerExperience = st.text_area("Describe the customer experience needs of your target audience.")
#sutainabilityNeeds = st.text_area("Describe the sutainability needs of your target audience.")
submit_button_details = st.button("Submit details to generate an example proposition")
userProposal = st.text_area("Enter your final Proposition for Select City and Product", value=st.session_state.get("propositionVal", ""), disabled=st.session_state.get("disabled", True))
submit_button_proposition = st.button("Submit Proposition")
pre_prompt = '''You are a business analyser bot. I will give you data and references and you will analyse the propositions and will give them scoring on particular criterias. An example is below
Proposition - Culture bank Student – the Young Professionals Credit Card!
Description:
Culture bank is offering Limburg residents a Credit card for students and under 30’s with special discounts at major online stores. The card offers a 1% off on all purchases from Amazon and 10% off all travel purchases all available through our Mobile App. You will also get a free current account to use for your everyday savings too! This group are short on cash but not afraid to be in debt as they will pay it off in the future. They want a product that is easy to use and not complicated. They want connect on Social Media sites. They want great deals and want to manage things independantly. They want the brand to be fun and positive
The card is free with no annual fee and available via our online portal
Some more details about proposition
Question: What are their money needs?
Answer: This group are short on cash but not afraid to be in debt as they will pay it off in the future
Question: What is thee customer experience
Answer: They want a product that is easy to use and not complicated
Question: what is the key demographic behaviour?
Answer: They want connect on Social Media sites
Question: Prime Money Attitudes?
Answer: They want great deals and want to manage things independantly
Question: Brand needs?sss
Answer: They want the brand to be fun and positive
Analyse this proposition and score it on the below criteria based upon its popularity within the audience 'Living of today'
Refer the barometer goals being set for 'Living for today people'
I want to feel socially responsible 67
I want to feel in control of my future 58
I want the bank to help me understand what I can afford 93
I do active charity work 99
I want to manage my carbon footprint 112
Being rich is a priority for me 86
I have achieved all I need in life 52
I feel out of depth with my finances 103
Helps me gain control over my future 97
The brand is fun 120
Rank the proposition on all the above barometers based upon how much they match with the barometer with semantic similarity. Rank should be decided by this logic-
1. Score should be between 0 - 200.
2. On the basis of score then rank the proposition on all benchmark goals from 1(low) to 5(high).
3. If the score of proposition differ from the goal within the range 0-10 then it should have higher rank. Similarly as the difference increases from goal value the rank should be lower.
Show the rank between 1 to 5 and the score between 0-200 for every goal in a tabular format with a sum total and average rank at the end of table.
Only show the table and conclusion remarks if the proposition suits the target audience or not. Do not show the barometers or any other part of the prompt
{{0}}
'''
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.'''
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'''
CharlesTownPopulation = 10000
LimburgTownPopulation = 20000
demographic = ''
population = 0
if selectedCity:
if selectedCity == 'CharlesTown':
st.write(CharlesTownDemographic)
demographic = CharlesTownDemographic
population = CharlesTownPopulation
if selectedCity == 'Limburg':
st.write(LimburgTownDemographic)
demographic = LimburgTownDemographic
population = LimburgTownPopulation
if submit_button_details:
st.session_state.disabled = False
#topMoneyNeeds = moneyNeeds #findTop3MoneyNeeds(moneyNeeds)
#topCustomerExp = customerExperience #findTop3CustomerExperienceNeeds(customerExperience)
#topSustainabilityNeeds = sutainabilityNeeds #findTop3SustainabilityNeeds(sutainabilityNeeds)
st.session_state.propositionVal = generatePropositionExample(productName, selectedProduct, moneyNeeds, customerExperience, sutainabilityNeeds)
if submit_button_proposition:
proposal = '''Given proposal is for the city {} with product {}. The propsal is as below.
{}'''
proposal = proposal.format(selectedCity, selectedProduct, userProposal)
matchingTopologies, topologyDetails = findTop3Topologies(proposal, demographic)
response = model.generate_content([pre_prompt.format(proposal)])
st.write("{} city people are mainly from the {} group with a population of {}. Out of this {} of perople belong to this group".format(selectedCity, matchingTopologies[0], population, topologyDetails[matchingTopologies[0]]['Proportion Sample']))
st.write("Entered proposal:", proposal)
st.write("Analyzing your proposition")
st.write("As for the money needs of this group your product is mostly targeting people with the spending behaviour described below:")
for idx, need in enumerate(moneyNeeds):
st.write("{}. {}".format(idx+1, need))
st.write("As for the customer experience needs of this group your product is mostly targeting people with the spending behaviour described below:",)
for idx, exp in enumerate(customerExperience):
st.write("{}. {}".format(idx+1, exp))
st.write("As for the sustainability needs of this group your product is mostly targeting people with the spending behaviour described below:",)
for idx, need in enumerate(sutainabilityNeeds):
st.write("{}. {}".format(idx+1, need))
st.write("Overall your targeted demographic and proposition are focusing the three topologies below. The figures show the weighting of your proposition to each demographic:",)
for idx, topology in enumerate(matchingTopologies):
st.write("{}. {}".format(idx+1, topology))
topologySumDict = {}
for topology in matchingTopologies:
sumTopology = 0
for moneyNeed in moneyNeeds:
#print(" Money need = {}, Topology is {}".format(moneyNeed, topology))
sumTopology = sumTopology+int(moneyNeedsDict[moneyNeed][topology])
for customerExp in customerExperience:
sumTopology = sumTopology+int(customerExperienceDict[customerExp][topology])
for sustainabilityNeed in sutainabilityNeeds:
sumTopology = sumTopology+int(sutainabilityNeedsDict[sustainabilityNeed][topology])
topologySumDict[topology] = math.floor(sumTopology/3)
for topology in matchingTopologies:
st.write("{}. {}".format(topology, topologySumDict[topology]))
totalSubscriberTakeOut = 0
for topology in matchingTopologies:
proportion = int(topologyDetails[topology]['Proportion Sample'].replace('%', ''))
topologyPopulation = math.floor((proportion * population) / 100)
topologyScore = topologySumDict[topology]
topologyPopulation = math.floor(topologyPopulation/2)
if topologyScore <=250:
topologyPopulation = topologyPopulation/2
elif topologyScore >250 and topologyScore<=260:
topologyPopulation = math.floor(topologyPopulation/1.8)
elif topologyScore >260 and topologyScore<=270:
topologyPopulation = math.floor(topologyPopulation/1.6)
elif topologyScore >270 and topologyScore<=280:
topologyPopulation = math.floor(topologyPopulation/1.4)
elif topologyScore >280 and topologyScore<=300:
topologyPopulation = topologyPopulation
elif topologyScore >300 and topologyScore<=310:
topologyPopulation = math.floor(topologyPopulation * 1.2)
elif topologyScore >310 and topologyScore<=320:
topologyPopulation = math.floor(topologyPopulation * 1.4)
elif topologyScore >320 and topologyScore<=340:
topologyPopulation = math.floor(topologyPopulation * 1.5)
elif topologyScore >340 and topologyScore<=360:
topologyPopulation = math.floor(topologyPopulation * 1.6)
else:
topologyPopulation = math.floor(topologyPopulation * 2)
totalSubscriberTakeOut = totalSubscriberTakeOut + topologyPopulation
st.write("{}. {} and has subscriber takeout of {}".format(topology, topologySumDict[topology], topologyPopulation))
st.write(" Target Subscriber takeout = {}".format(totalSubscriberTakeOut))
st.write(" Total Subscriber take up for Year 3 = {}".format(subscriberTakeOutYear3))
if totalSubscriberTakeOut<subscriberTakeOutYear3:
st.write("Overall there is not a close match of your proposition to the main demographic. Takeout score difference = {}".format(subscriberTakeOutYear3-totalSubscriberTakeOut))
elif totalSubscriberTakeOut==subscriberTakeOutYear3:
st.write("Amazing! Your proposition exactly match the target subscriber take oup for year 3")
else:
st.write("Great Job! Your proposition exceeds the target subscriber take up for year 3. Additional takeout = {}".format(totalSubscriberTakeOut- subscriberTakeOutYear3))
# 250 and below with a negative factor of 2.0
# 260 with a negative factor of 1.8
# 270 with a negative factor of 1.6
# 280 with a negative factor of 1.0
# 300 with a factor of 1
# 310 with a factor of 1.2
# 320 with a factor of 1.4
# 340 with a factor or 1.5
# 360+ with a factor of 2.0