Spaces:
Sleeping
Sleeping
ruchi
commited on
Commit
•
e209a2d
1
Parent(s):
0c6560f
Display money needs pattern
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -88,8 +88,14 @@ if submit_button:
|
|
88 |
st.write("Entered proposal:", proposal)
|
89 |
st.write("Analyzing your proposition")
|
90 |
|
91 |
-
topMoneyNeeds = findTop3MoneyNeeds(moneyNeeds)
|
92 |
|
93 |
response = model.generate_content([pre_prompt.format(proposal)])
|
94 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
95 |
|
|
|
|
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
|
|
|
88 |
st.write("Entered proposal:", proposal)
|
89 |
st.write("Analyzing your proposition")
|
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 |
|
101 |
+
|
db.py
CHANGED
@@ -15,12 +15,15 @@ def fetch_db_rows_as_dicts(db_path, table_name):
|
|
15 |
# Print the column names
|
16 |
print("Column names:", column_names)
|
17 |
|
|
|
18 |
# Execute a query to fetch all rows from the table
|
19 |
cursor.execute(f"SELECT * FROM {table_name};")
|
20 |
rows = cursor.fetchall()
|
21 |
|
|
|
|
|
|
|
22 |
assert len(rows) > 1
|
23 |
-
|
24 |
return column_names, rows[1:]
|
25 |
|
26 |
except sqlite3.Error as e:
|
@@ -33,4 +36,4 @@ def fetch_db_rows_as_dicts(db_path, table_name):
|
|
33 |
|
34 |
|
35 |
# Example usage:
|
36 |
-
|
|
|
15 |
# Print the column names
|
16 |
print("Column names:", column_names)
|
17 |
|
18 |
+
|
19 |
# Execute a query to fetch all rows from the table
|
20 |
cursor.execute(f"SELECT * FROM {table_name};")
|
21 |
rows = cursor.fetchall()
|
22 |
|
23 |
+
#for row in rows:
|
24 |
+
# row_dict = dict(zip(column_names, row))
|
25 |
+
# print(row_dict)
|
26 |
assert len(rows) > 1
|
|
|
27 |
return column_names, rows[1:]
|
28 |
|
29 |
except sqlite3.Error as e:
|
|
|
36 |
|
37 |
|
38 |
# Example usage:
|
39 |
+
fetch_db_rows_as_dicts('topologies.sqlite', 'topologies')
|
topologies.sqlite
ADDED
Binary file (8.19 kB). View file
|
|
utils.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
from db import fetch_db_rows_as_dicts
|
2 |
import google.generativeai as genai
|
3 |
import json
|
|
|
4 |
|
5 |
-
GOOGLE_API_KEY='
|
6 |
genai.configure(api_key=GOOGLE_API_KEY)
|
7 |
model = genai.GenerativeModel(model_name = "gemini-pro")
|
8 |
|
@@ -27,6 +28,33 @@ def transform_to_dict_of_dicts(columns, rows):
|
|
27 |
|
28 |
# Iterate over each row
|
29 |
for row in rows:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# The first element of the row is the key for the outer dictionary
|
31 |
outer_key = row[0].strip()
|
32 |
|
@@ -55,7 +83,54 @@ def findTop3MoneyNeeds(proposition):
|
|
55 |
needDictIndexes.append(moneyNeedsDict[need])
|
56 |
|
57 |
print(needDictIndexes)
|
58 |
-
return needDictIndexes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
def findTop3Needs(proposition, moneyNeeds):
|
@@ -81,4 +156,7 @@ def findTop3Needs(proposition, moneyNeeds):
|
|
81 |
return obj['matches']
|
82 |
|
83 |
|
|
|
84 |
#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')
|
|
|
|
|
|
1 |
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)
|
8 |
model = genai.GenerativeModel(model_name = "gemini-pro")
|
9 |
|
|
|
28 |
|
29 |
# Iterate over each row
|
30 |
for row in rows:
|
31 |
+
print(dict(row))
|
32 |
+
# The first element of the row is the key for the outer dictionary
|
33 |
+
outer_key = row[0].strip()
|
34 |
+
|
35 |
+
# Initialize the inner dictionary
|
36 |
+
inner_dict = {}
|
37 |
+
|
38 |
+
# Iterate over the rest of the elements in the row
|
39 |
+
for i, value in enumerate(row[1:], start=1):
|
40 |
+
# The corresponding column name is the key for the inner dictionary
|
41 |
+
inner_key = columns[i].strip()
|
42 |
+
# Add the key-value pair to the inner dictionary
|
43 |
+
inner_dict[inner_key] = value
|
44 |
+
|
45 |
+
# Add the inner dictionary to the result dictionary with the outer key
|
46 |
+
result[outer_key] = inner_dict
|
47 |
+
|
48 |
+
return result
|
49 |
+
|
50 |
+
|
51 |
+
def transform_topologies_to_dict(columns, rows):
|
52 |
+
# Initialize the result dictionary
|
53 |
+
result = {}
|
54 |
+
|
55 |
+
# Iterate over each row
|
56 |
+
for row in rows:
|
57 |
+
print(dict(row))
|
58 |
# The first element of the row is the key for the outer dictionary
|
59 |
outer_key = row[0].strip()
|
60 |
|
|
|
83 |
needDictIndexes.append(moneyNeedsDict[need])
|
84 |
|
85 |
print(needDictIndexes)
|
86 |
+
return needs, needDictIndexes
|
87 |
+
|
88 |
+
|
89 |
+
def findTop3Needs(proposition, moneyNeeds):
|
90 |
+
|
91 |
+
moneyNeedsString = concatenate_keys(moneyNeeds)
|
92 |
+
|
93 |
+
prompt = '''You have these listed needs of customers
|
94 |
+
{}
|
95 |
+
|
96 |
+
Now given a proposition
|
97 |
+
"{}"
|
98 |
+
|
99 |
+
Find the best 3 strings out of the list which matches this proposition. Return output strictly only in json under a list called matches
|
100 |
+
'''
|
101 |
+
|
102 |
+
moneyNeedsPrompt = prompt.format(moneyNeedsString, proposition)
|
103 |
+
response = model.generate_content([moneyNeedsPrompt])
|
104 |
+
output = response.text
|
105 |
+
output = output.replace('```json', '')
|
106 |
+
output = output.replace('```', '')
|
107 |
+
obj = load_json_from_string(output)
|
108 |
+
print(obj)
|
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 |
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
|