Spaces:
Sleeping
Sleeping
Santiago Hincapie Potes
commited on
Commit
•
75c75cb
1
Parent(s):
619fe5f
augmented generation
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import os
|
2 |
|
3 |
import google.generativeai as palm
|
4 |
import streamlit as st
|
@@ -24,8 +24,51 @@ This is what amazon customers are saying about similar products:
|
|
24 |
Can you write some recomendations about how can we disrupt this market? Try to propose the necesary methodology to create a breaking product."""
|
25 |
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def setup_palm():
|
28 |
-
palm.configure(api_key=os.environ.get('PALM_TOKEN'))
|
|
|
|
|
29 |
|
30 |
@st.cache_data
|
31 |
def load_data():
|
@@ -81,12 +124,17 @@ def handler_review_query():
|
|
81 |
)
|
82 |
|
83 |
# TODO: check if there are relevant products
|
|
|
|
|
|
|
|
|
84 |
|
85 |
relevant_reviews = deploy_utils.get_relevant_reviews(
|
86 |
relevant_products, reviews)
|
87 |
|
88 |
raw_topic_assigment = deploy_utils.clusterize_reviews(
|
89 |
relevant_reviews, reviews_model, clusterer)
|
|
|
90 |
relevant_reviews["topic"] = raw_topic_assigment
|
91 |
reviews_with_topics = relevant_reviews[relevant_reviews["topic"] != -1]
|
92 |
|
@@ -104,10 +152,14 @@ def handler_review_query():
|
|
104 |
st.session_state.user_prompt = prompt
|
105 |
|
106 |
|
|
|
|
|
|
|
|
|
107 |
|
108 |
def palm_handler():
|
109 |
response = palm.generate_text(prompt=st.session_state.user_prompt)
|
110 |
-
st.session_state.palm_output = response
|
111 |
|
112 |
|
113 |
def render_search():
|
@@ -122,18 +174,20 @@ def render_search():
|
|
122 |
)
|
123 |
|
124 |
if query:
|
125 |
-
|
|
|
|
|
|
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
132 |
|
133 |
-
st.
|
134 |
-
|
135 |
-
key="location_search",
|
136 |
-
on_click=palm_handler)
|
137 |
|
138 |
st.write("---")
|
139 |
render_cta_link(
|
@@ -146,7 +200,7 @@ def render_search():
|
|
146 |
def render_palm_results():
|
147 |
# TODO: temporal
|
148 |
st.write("# ALMond recommendations")
|
149 |
-
st.write(st.session_state.palm_output
|
150 |
|
151 |
# Execution start here!
|
152 |
|
|
|
1 |
+
import os
|
2 |
|
3 |
import google.generativeai as palm
|
4 |
import streamlit as st
|
|
|
24 |
Can you write some recomendations about how can we disrupt this market? Try to propose the necesary methodology to create a breaking product."""
|
25 |
|
26 |
|
27 |
+
def get_prompt_without_reviews(title):
|
28 |
+
return f"""We are doing a marketing research analysis, in particular we are trying to understand what users thing about a particular market in order to generate tips for future sellers.
|
29 |
+
In particular, we are interesting to analyze the market for "{title}"
|
30 |
+
|
31 |
+
Can you write some recomendations about how can we disrupt this market? Try to propose the necesary methodology to create a breaking product."""
|
32 |
+
|
33 |
+
|
34 |
+
no_electronics_message = """
|
35 |
+
Sorry, we are currently only recommending business that operate around electronics. Would you like to input another search?
|
36 |
+
|
37 |
+
|
38 |
+
This doesn't mean you make a mistake, I search amazon products and try to extract relevant reviews from similar products and we didn't find relevant products for your search.
|
39 |
+
|
40 |
+
#### Maybe you are way ahead of the market!
|
41 |
+
|
42 |
+
|
43 |
+
```
|
44 |
+
.
|
45 |
+
___,,,
|
46 |
+
\_[o o]
|
47 |
+
Errare humanum est! C\ _\/
|
48 |
+
/ _____),_/__
|
49 |
+
________ / \/ /
|
50 |
+
_| .| / o /
|
51 |
+
| | .| / /
|
52 |
+
\| .| / /
|
53 |
+
|________| /_ \/
|
54 |
+
__|___|__ _//\ \\
|
55 |
+
_____|_________|____ \ \ \ \\
|
56 |
+
_| /// \ \\
|
57 |
+
| \ /
|
58 |
+
| / /
|
59 |
+
| / /
|
60 |
+
________________ | /__ /_
|
61 |
+
...|_|.............. /______\.......
|
62 |
+
```
|
63 |
+
"""
|
64 |
+
|
65 |
+
TEST_MODE = False
|
66 |
+
|
67 |
+
|
68 |
def setup_palm():
|
69 |
+
# palm.configure(api_key=os.environ.get('PALM_TOKEN'))
|
70 |
+
palm.configure(api_key="AIzaSyCbbwbNqjqPYzLOx9-5iO9zaYeHG5CGNxI")
|
71 |
+
|
72 |
|
73 |
@st.cache_data
|
74 |
def load_data():
|
|
|
124 |
)
|
125 |
|
126 |
# TODO: check if there are relevant products
|
127 |
+
if len(relevant_products) == 0:
|
128 |
+
st.session_state.user_prompt = None
|
129 |
+
st.session_state.palm_output = no_electronics_message
|
130 |
+
return
|
131 |
|
132 |
relevant_reviews = deploy_utils.get_relevant_reviews(
|
133 |
relevant_products, reviews)
|
134 |
|
135 |
raw_topic_assigment = deploy_utils.clusterize_reviews(
|
136 |
relevant_reviews, reviews_model, clusterer)
|
137 |
+
|
138 |
relevant_reviews["topic"] = raw_topic_assigment
|
139 |
reviews_with_topics = relevant_reviews[relevant_reviews["topic"] != -1]
|
140 |
|
|
|
152 |
st.session_state.user_prompt = prompt
|
153 |
|
154 |
|
155 |
+
def handler_product_without_reviews():
|
156 |
+
st.session_state.user_prompt = get_prompt_without_reviews(
|
157 |
+
st.session_state.user_search_query)
|
158 |
+
|
159 |
|
160 |
def palm_handler():
|
161 |
response = palm.generate_text(prompt=st.session_state.user_prompt)
|
162 |
+
st.session_state.palm_output = response.result
|
163 |
|
164 |
|
165 |
def render_search():
|
|
|
174 |
)
|
175 |
|
176 |
if query:
|
177 |
+
try:
|
178 |
+
handler_review_query()
|
179 |
+
except:
|
180 |
+
handler_product_without_reviews()
|
181 |
|
182 |
+
if TEST_MODE:
|
183 |
+
_ = st.text_area(
|
184 |
+
label="test env",
|
185 |
+
placeholder="prompt here",
|
186 |
+
key="user_prompt"
|
187 |
+
)
|
188 |
|
189 |
+
if "user_prompt" in st.session_state and st.session_state.user_prompt:
|
190 |
+
palm_handler()
|
|
|
|
|
191 |
|
192 |
st.write("---")
|
193 |
render_cta_link(
|
|
|
200 |
def render_palm_results():
|
201 |
# TODO: temporal
|
202 |
st.write("# ALMond recommendations")
|
203 |
+
st.write(st.session_state.palm_output)
|
204 |
|
205 |
# Execution start here!
|
206 |
|