Spaces:
Running
Running
implement basic comparison
Browse files
app.py
CHANGED
@@ -62,9 +62,48 @@ def init_session_state():
|
|
62 |
|
63 |
def callback_count_checked():
|
64 |
st.session_state['count_checked'] = 0
|
|
|
65 |
for key in list(st.session_state.keys()):
|
66 |
if (key.split('__')[0] == 'cb_compare') and (st.session_state[key] == True):
|
67 |
st.session_state['count_checked'] += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# initialize connection to pinecone (get API key at app.pinecone.io)
|
70 |
pinecone.init(
|
@@ -130,7 +169,6 @@ if st.button('Submit'):
|
|
130 |
# print(f"above_thr_sorted: {above_thr_sorted}")
|
131 |
# print(f"results: {results}")
|
132 |
# print(f"metadata: {metadata}")
|
133 |
-
|
134 |
# # TEST ONLY
|
135 |
# above_thr_sorted = [('2086773', 0.800059378), ('1951083', 0.797319531), ('1998714', 0.795623)]
|
136 |
# results = {'1951083': {'productid': '1951083', 'name': '2 for 1 Turn-key Business Opportunity in Lynnwood, Washington - BizBuySell', 'category': 'Other', 'alternatename': None, 'url': 'https://www.bizbuysell.com/Business-Opportunity/2-for-1-Turn-key-Business-Opportunity/1951083/', 'logo': 'https://images.bizbuysell.com/shared/listings/195/1951083/87198e08-a191-4d97-a33b-9e9f40fa02f4-W768.jpg', 'description': 'Your chance to own a successful Korean traditional KBBQ grill restaurant and Korean dive bar. Owner is retiring after 19 years of business. This Korean BBQ restaurant utilizes a traditional grill called "Sot Ttu Kkeong" widely found in Korea. There are 10 separate grilling tables with a unique hood system to eliminate odors immediately. The bar next door may be able to extend hours into the summer. With one shared full kitchen, the new owner will be able to maximize business and potentially earn double income.'}, '1998714': {'productid': '1998714', 'name': 'Portland CPA Firm in Portland, Oregon - BizBuySell', 'category': 'Accounting and Tax Practices', 'alternatename': None, 'url': 'https://www.bizbuysell.com/Business-Opportunity/Portland-CPA-Firm/1998714/', 'logo': 'https://images.bizbuysell.com/shared/listings/199/1998714/cd02bdb9-32c9-409d-b82e-d0531c12eb39-W768.jpg', 'description': 'OR1002: UPDATED :The seller of this Portland CPA firm is approaching retirement and ready to sell the firm. The firm has a great reputation, has good systems in place, is paperless, and has a great staff. The mix of services offers a consistent stream of cash flow to the owner. The seller is seeking a CPA buyer. The office space is available for continued lease after the sale. Revenues for sale include:7% Accounting, bookkeeping and payroll services26% Income tax preparation services for individual clients35% Income tax preparation services for business and other clients28% Audits and reviews4% Consulting services'}, '2086773': {'productid': '2086773', 'name': 'Asian Grocery Supermarket, 1 owner for 29 years in Salem, Oregon - BizBuySell', 'category': 'Grocery Stores and Supermarkets', 'alternatename': None, 'url': 'https://www.bizbuysell.com/Business-Real-Estate-For-Sale/Asian-Grocery-Supermarket-1-owner-for-29-years/2086773/', 'logo': 'https://images.bizbuysell.com/shared/listings/208/2086773/861f6ba6-a994-4e90-9c62-0a593dae2a31-W768.jpg', 'description': 'Great location, well established and profitable supermarket.We have been the sole owner for almost 29 years, so business boasts of a great reputation.'}}
|
@@ -145,6 +183,8 @@ if st.button('Submit'):
|
|
145 |
|
146 |
if st.session_state['display_results']:
|
147 |
|
|
|
|
|
148 |
st.header("Results")
|
149 |
st.divider()
|
150 |
|
@@ -180,9 +220,27 @@ if st.session_state['display_results']:
|
|
180 |
with col_compare:
|
181 |
st.checkbox('compare', key=f"cb_compare__{pid}", on_change=callback_count_checked)
|
182 |
|
|
|
183 |
if st.session_state['count_checked'] > 0:
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
with st.expander("developer tool"):
|
188 |
st.json(st.session_state)
|
|
|
62 |
|
63 |
def callback_count_checked():
|
64 |
st.session_state['count_checked'] = 0
|
65 |
+
st.session_state['checked_boxes'] = []
|
66 |
for key in list(st.session_state.keys()):
|
67 |
if (key.split('__')[0] == 'cb_compare') and (st.session_state[key] == True):
|
68 |
st.session_state['count_checked'] += 1
|
69 |
+
st.session_state['checked_boxes'].append(key)
|
70 |
+
|
71 |
+
def summarize_products(products: list) -> str:
|
72 |
+
"""
|
73 |
+
Input:
|
74 |
+
products = [
|
75 |
+
{text information of product#1},
|
76 |
+
{text information of product#2},
|
77 |
+
{text information of product#3},
|
78 |
+
]
|
79 |
+
|
80 |
+
Output:
|
81 |
+
summary = "{summary of all products}"
|
82 |
+
"""
|
83 |
+
NEW_LINE = '\n'
|
84 |
+
prompt = f"""
|
85 |
+
Based on the product information below, please read and try to understand it.
|
86 |
+
{ f"{NEW_LINE*2}---{NEW_LINE*2}".join(products) }
|
87 |
+
Please write a concise and insightful summary table (display as HTML) to compare the products for investors, which should inlcude but not limited to:
|
88 |
+
- description
|
89 |
+
- category
|
90 |
+
- asking price
|
91 |
+
- location
|
92 |
+
- potential profit margin
|
93 |
+
"""
|
94 |
+
print(f"prompt: {prompt}")
|
95 |
+
|
96 |
+
openai.api_key = OPENAI_API_KEY
|
97 |
+
completion = openai.ChatCompletion.create(
|
98 |
+
model="gpt-4",
|
99 |
+
messages=[
|
100 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
101 |
+
{"role": "user", "content": prompt}
|
102 |
+
]
|
103 |
+
)
|
104 |
+
|
105 |
+
summary = completion.choices[0].message
|
106 |
+
return summary
|
107 |
|
108 |
# initialize connection to pinecone (get API key at app.pinecone.io)
|
109 |
pinecone.init(
|
|
|
169 |
# print(f"above_thr_sorted: {above_thr_sorted}")
|
170 |
# print(f"results: {results}")
|
171 |
# print(f"metadata: {metadata}")
|
|
|
172 |
# # TEST ONLY
|
173 |
# above_thr_sorted = [('2086773', 0.800059378), ('1951083', 0.797319531), ('1998714', 0.795623)]
|
174 |
# results = {'1951083': {'productid': '1951083', 'name': '2 for 1 Turn-key Business Opportunity in Lynnwood, Washington - BizBuySell', 'category': 'Other', 'alternatename': None, 'url': 'https://www.bizbuysell.com/Business-Opportunity/2-for-1-Turn-key-Business-Opportunity/1951083/', 'logo': 'https://images.bizbuysell.com/shared/listings/195/1951083/87198e08-a191-4d97-a33b-9e9f40fa02f4-W768.jpg', 'description': 'Your chance to own a successful Korean traditional KBBQ grill restaurant and Korean dive bar. Owner is retiring after 19 years of business. This Korean BBQ restaurant utilizes a traditional grill called "Sot Ttu Kkeong" widely found in Korea. There are 10 separate grilling tables with a unique hood system to eliminate odors immediately. The bar next door may be able to extend hours into the summer. With one shared full kitchen, the new owner will be able to maximize business and potentially earn double income.'}, '1998714': {'productid': '1998714', 'name': 'Portland CPA Firm in Portland, Oregon - BizBuySell', 'category': 'Accounting and Tax Practices', 'alternatename': None, 'url': 'https://www.bizbuysell.com/Business-Opportunity/Portland-CPA-Firm/1998714/', 'logo': 'https://images.bizbuysell.com/shared/listings/199/1998714/cd02bdb9-32c9-409d-b82e-d0531c12eb39-W768.jpg', 'description': 'OR1002: UPDATED :The seller of this Portland CPA firm is approaching retirement and ready to sell the firm. The firm has a great reputation, has good systems in place, is paperless, and has a great staff. The mix of services offers a consistent stream of cash flow to the owner. The seller is seeking a CPA buyer. The office space is available for continued lease after the sale. Revenues for sale include:7% Accounting, bookkeeping and payroll services26% Income tax preparation services for individual clients35% Income tax preparation services for business and other clients28% Audits and reviews4% Consulting services'}, '2086773': {'productid': '2086773', 'name': 'Asian Grocery Supermarket, 1 owner for 29 years in Salem, Oregon - BizBuySell', 'category': 'Grocery Stores and Supermarkets', 'alternatename': None, 'url': 'https://www.bizbuysell.com/Business-Real-Estate-For-Sale/Asian-Grocery-Supermarket-1-owner-for-29-years/2086773/', 'logo': 'https://images.bizbuysell.com/shared/listings/208/2086773/861f6ba6-a994-4e90-9c62-0a593dae2a31-W768.jpg', 'description': 'Great location, well established and profitable supermarket.We have been the sole owner for almost 29 years, so business boasts of a great reputation.'}}
|
|
|
183 |
|
184 |
if st.session_state['display_results']:
|
185 |
|
186 |
+
summary_container = st.empty()
|
187 |
+
|
188 |
st.header("Results")
|
189 |
st.divider()
|
190 |
|
|
|
220 |
with col_compare:
|
221 |
st.checkbox('compare', key=f"cb_compare__{pid}", on_change=callback_count_checked)
|
222 |
|
223 |
+
# display summary tab
|
224 |
if st.session_state['count_checked'] > 0:
|
225 |
+
with summary_container.container():
|
226 |
+
st.header('Summary')
|
227 |
+
if st.button('Compare Products'):
|
228 |
+
products = []
|
229 |
+
for key in st.session_state['checked_boxes']:
|
230 |
+
# TODO: Need to pull all the document
|
231 |
+
# TODO: Need to dedup the pid too
|
232 |
+
pid = key.split('__')[-1]
|
233 |
+
products.append(
|
234 |
+
st.session_state['metadata'][pid].get('document')
|
235 |
+
)
|
236 |
+
summary = summarize_products(products)
|
237 |
+
st.markdown(summary.get("content"), unsafe_allow_html=True)
|
238 |
+
else:
|
239 |
+
try:
|
240 |
+
summary_container.empty()
|
241 |
+
except NameError:
|
242 |
+
pass
|
243 |
+
|
244 |
|
245 |
with st.expander("developer tool"):
|
246 |
st.json(st.session_state)
|