Spaces:
Sleeping
Sleeping
ruchi
commited on
Commit
·
604214c
1
Parent(s):
9809cd8
Feedback changes
Browse files
app.py
CHANGED
|
@@ -2,10 +2,10 @@ import streamlit as st
|
|
| 2 |
import os
|
| 3 |
import math
|
| 4 |
import google.generativeai as genai
|
| 5 |
-
GOOGLE_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
|
|
@@ -25,13 +25,42 @@ st.markdown(
|
|
| 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
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
userProposal = st.text_area("Enter your final Proposition for Select City and Product")
|
| 34 |
-
submit_button = st.button("Submit")
|
| 35 |
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
|
| 36 |
|
| 37 |
Proposition - Culture bank Student – the Young Professionals Credit Card!
|
|
@@ -96,17 +125,24 @@ if selectedCity:
|
|
| 96 |
demographic = LimburgTownDemographic
|
| 97 |
population = LimburgTownPopulation
|
| 98 |
|
| 99 |
-
if
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
-
topMoneyNeeds, topMoneyNeedsDict = findTop3MoneyNeeds(moneyNeeds)
|
| 106 |
|
| 107 |
-
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
matchingTopologies, topologyDetails = findTop3Topologies(proposal, demographic)
|
| 112 |
|
|
@@ -118,17 +154,17 @@ if submit_button:
|
|
| 118 |
|
| 119 |
st.write("As for the money needs of this group your product is mostly targeting people with the spending behaviour described below:")
|
| 120 |
|
| 121 |
-
for idx, need in enumerate(
|
| 122 |
st.write("{}. {}".format(idx+1, need))
|
| 123 |
|
| 124 |
st.write("As for the customer experience needs of this group your product is mostly targeting people with the spending behaviour described below:",)
|
| 125 |
|
| 126 |
-
for idx, exp in enumerate(
|
| 127 |
st.write("{}. {}".format(idx+1, exp))
|
| 128 |
|
| 129 |
st.write("As for the sustainability needs of this group your product is mostly targeting people with the spending behaviour described below:",)
|
| 130 |
|
| 131 |
-
for idx, need in enumerate(
|
| 132 |
st.write("{}. {}".format(idx+1, need))
|
| 133 |
|
| 134 |
|
|
@@ -141,14 +177,15 @@ if submit_button:
|
|
| 141 |
|
| 142 |
for topology in matchingTopologies:
|
| 143 |
sumTopology = 0
|
| 144 |
-
for moneyNeed in
|
| 145 |
-
|
|
|
|
| 146 |
|
| 147 |
-
for customerExp in
|
| 148 |
-
sumTopology = sumTopology+int(customerExp[topology])
|
| 149 |
|
| 150 |
-
for sustainabilityNeed in
|
| 151 |
-
sumTopology = sumTopology+int(sustainabilityNeed[topology])
|
| 152 |
|
| 153 |
topologySumDict[topology] = math.floor(sumTopology/3)
|
| 154 |
|
|
@@ -206,7 +243,6 @@ if submit_button:
|
|
| 206 |
else:
|
| 207 |
st.write("Congratulations!! Your proposition exceeds the target subscriber take out. Additional takeout = {}".format(totalSubscriberTakeOut- subscriberTakeOut))
|
| 208 |
|
| 209 |
-
|
| 210 |
# 250 and below with a negative factor of 2.0
|
| 211 |
# 260 with a negative factor of 1.8
|
| 212 |
# 270 with a negative factor of 1.6
|
|
|
|
| 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)
|
| 7 |
model = genai.GenerativeModel(model_name = "gemini-pro")
|
| 8 |
+
from utils import findTop3MoneyNeeds, findTop3Topologies, findTop3CustomerExperienceNeeds, findTop3SustainabilityNeeds, listNeeds, generatePropositionExample
|
| 9 |
|
| 10 |
|
| 11 |
# Create a banner using Markdown
|
|
|
|
| 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 up. Enter the amount in multiples of 1000.", min_value=0, step=1)
|
| 29 |
+
productName = st.text_input("Please enter your product name")
|
| 30 |
+
|
| 31 |
+
moneyNeedsList, moneyNeedsDict = listNeeds('money_needs')
|
| 32 |
+
customerExperienceList, customerExperienceDict = listNeeds('customer_exp')
|
| 33 |
+
sutainabilityNeedsList, sutainabilityNeedsDict = listNeeds('sustainability')
|
| 34 |
+
|
| 35 |
+
moneyNeeds = st.multiselect(
|
| 36 |
+
label="Select three money needs of your target audience which best describe their spending",
|
| 37 |
+
options=moneyNeedsList,
|
| 38 |
+
max_selections=3
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
customerExperience = st.multiselect(
|
| 42 |
+
label="Select three options which best describe the cuetomer experience you are targeting to provide",
|
| 43 |
+
options=customerExperienceList,
|
| 44 |
+
max_selections=3
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
sutainabilityNeeds = st.multiselect(
|
| 48 |
+
label="Select three options which best describe the sustainability needs of your customer",
|
| 49 |
+
options=sutainabilityNeedsList,
|
| 50 |
+
max_selections=3
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
#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.")
|
| 55 |
+
#customerExperience = st.text_area("Describe the customer experience needs of your target audience.")
|
| 56 |
+
#sutainabilityNeeds = st.text_area("Describe the sutainability needs of your target audience.")
|
| 57 |
+
|
| 58 |
+
submit_button_details = st.button("Submit details to generate an example proposition")
|
| 59 |
+
|
| 60 |
+
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))
|
| 61 |
+
|
| 62 |
+
submit_button_proposition = st.button("Submit Proposition")
|
| 63 |
|
|
|
|
|
|
|
| 64 |
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
|
| 65 |
|
| 66 |
Proposition - Culture bank Student – the Young Professionals Credit Card!
|
|
|
|
| 125 |
demographic = LimburgTownDemographic
|
| 126 |
population = LimburgTownPopulation
|
| 127 |
|
| 128 |
+
if submit_button_details:
|
| 129 |
+
st.session_state.disabled = False
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
#topMoneyNeeds = moneyNeeds #findTop3MoneyNeeds(moneyNeeds)
|
| 133 |
+
|
| 134 |
+
#topCustomerExp = customerExperience #findTop3CustomerExperienceNeeds(customerExperience)
|
| 135 |
|
| 136 |
+
#topSustainabilityNeeds = sutainabilityNeeds #findTop3SustainabilityNeeds(sutainabilityNeeds)
|
|
|
|
| 137 |
|
| 138 |
+
st.session_state.propositionVal = generatePropositionExample(productName, selectedProduct, moneyNeeds, customerExperience, sutainabilityNeeds)
|
| 139 |
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
if submit_button_proposition:
|
| 143 |
+
proposal = '''Given proposal is for the city {} with product {}. The propsal is as below.
|
| 144 |
+
{}'''
|
| 145 |
+
proposal = proposal.format(selectedCity, selectedProduct, userProposal)
|
| 146 |
|
| 147 |
matchingTopologies, topologyDetails = findTop3Topologies(proposal, demographic)
|
| 148 |
|
|
|
|
| 154 |
|
| 155 |
st.write("As for the money needs of this group your product is mostly targeting people with the spending behaviour described below:")
|
| 156 |
|
| 157 |
+
for idx, need in enumerate(moneyNeeds):
|
| 158 |
st.write("{}. {}".format(idx+1, need))
|
| 159 |
|
| 160 |
st.write("As for the customer experience needs of this group your product is mostly targeting people with the spending behaviour described below:",)
|
| 161 |
|
| 162 |
+
for idx, exp in enumerate(customerExperience):
|
| 163 |
st.write("{}. {}".format(idx+1, exp))
|
| 164 |
|
| 165 |
st.write("As for the sustainability needs of this group your product is mostly targeting people with the spending behaviour described below:",)
|
| 166 |
|
| 167 |
+
for idx, need in enumerate(sutainabilityNeeds):
|
| 168 |
st.write("{}. {}".format(idx+1, need))
|
| 169 |
|
| 170 |
|
|
|
|
| 177 |
|
| 178 |
for topology in matchingTopologies:
|
| 179 |
sumTopology = 0
|
| 180 |
+
for moneyNeed in moneyNeeds:
|
| 181 |
+
#print(" Money need = {}, Topology is {}".format(moneyNeed, topology))
|
| 182 |
+
sumTopology = sumTopology+int(moneyNeedsDict[moneyNeed][topology])
|
| 183 |
|
| 184 |
+
for customerExp in customerExperience:
|
| 185 |
+
sumTopology = sumTopology+int(customerExperienceDict[customerExp][topology])
|
| 186 |
|
| 187 |
+
for sustainabilityNeed in sutainabilityNeeds:
|
| 188 |
+
sumTopology = sumTopology+int(sutainabilityNeedsDict[sustainabilityNeed][topology])
|
| 189 |
|
| 190 |
topologySumDict[topology] = math.floor(sumTopology/3)
|
| 191 |
|
|
|
|
| 243 |
else:
|
| 244 |
st.write("Congratulations!! Your proposition exceeds the target subscriber take out. Additional takeout = {}".format(totalSubscriberTakeOut- subscriberTakeOut))
|
| 245 |
|
|
|
|
| 246 |
# 250 and below with a negative factor of 2.0
|
| 247 |
# 260 with a negative factor of 1.8
|
| 248 |
# 270 with a negative factor of 1.6
|
utils.py
CHANGED
|
@@ -76,6 +76,11 @@ def transform_topologies_to_dict(columns, rows):
|
|
| 76 |
|
| 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)
|
|
@@ -188,6 +193,26 @@ def findTop3Topologies(proposition, demographic):
|
|
| 188 |
return obj['matches'], topologyDetails
|
| 189 |
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
# def findTop3Needs(proposition, moneyNeeds):
|
| 192 |
|
| 193 |
# moneyNeedsString = concatenate_keys(moneyNeeds)
|
|
|
|
| 76 |
|
| 77 |
return result
|
| 78 |
|
| 79 |
+
def listNeeds(tableName, dbName='data.sqlite'):
|
| 80 |
+
needs, rows = fetch_db_rows_as_dicts(dbName, tableName)
|
| 81 |
+
needsDict = transform_to_dict_of_dicts(needs, rows)
|
| 82 |
+
return list(needsDict.keys()), needsDict
|
| 83 |
+
|
| 84 |
def findTop3MoneyNeeds(proposition):
|
| 85 |
moneyNeeds, rows = fetch_db_rows_as_dicts('data.sqlite', 'money_needs')
|
| 86 |
moneyNeedsDict = transform_to_dict_of_dicts(moneyNeeds, rows)
|
|
|
|
| 193 |
return obj['matches'], topologyDetails
|
| 194 |
|
| 195 |
|
| 196 |
+
def generatePropositionExample(productName, selectedProduct, moneyNeeds, customerExperience, sutainabilityNeeds):
|
| 197 |
+
|
| 198 |
+
proposal = '''You are a business sales professional who can form propostion summary of 100 words based upon the details.
|
| 199 |
+
Please take the below details and summarize a propostion in less than 100 words.
|
| 200 |
+
|
| 201 |
+
product name = {}
|
| 202 |
+
|
| 203 |
+
product type = {}
|
| 204 |
+
|
| 205 |
+
money needs of customer which this product is supposed to target = {}
|
| 206 |
+
|
| 207 |
+
Customer experience needs which our company will provide = {}
|
| 208 |
+
|
| 209 |
+
Sustainability needs which our product takes care of = {}
|
| 210 |
+
'''
|
| 211 |
+
proposal = proposal.format(productName, selectedProduct, moneyNeeds, customerExperience, sutainabilityNeeds)
|
| 212 |
+
response = model.generate_content([proposal])
|
| 213 |
+
return response.text
|
| 214 |
+
|
| 215 |
+
|
| 216 |
# def findTop3Needs(proposition, moneyNeeds):
|
| 217 |
|
| 218 |
# moneyNeedsString = concatenate_keys(moneyNeeds)
|