Danialebrat commited on
Commit
7f7111d
Β·
1 Parent(s): 74c9bd0

- changing UI, reading users from source campaign

Browse files
Files changed (1) hide show
  1. app.py +31 -29
app.py CHANGED
@@ -6,6 +6,9 @@ from snowflake.snowpark import Session
6
  from bs4 import BeautifulSoup
7
  from Messaging_system.Permes import Permes
8
  from dotenv import load_dotenv
 
 
 
9
  load_dotenv()
10
 
11
 
@@ -77,7 +80,7 @@ if not st.session_state.get("authenticated", False):
77
  def init_state() -> None:
78
  defaults = dict(
79
  involve_recsys_result=False, personalization=False,
80
- involve_last_interaction=False,
81
  valid_instructions="",
82
  invalid_instructions="",
83
  messaging_type="push",
@@ -136,26 +139,37 @@ st.markdown(
136
  # ──────────────────────────────────────────────────────────────────────────────
137
  init_state()
138
  with st.sidebar:
139
- # we will read this from snowflake in future
140
- uploaded_file = "Data/Singeo_Camp.csv"
141
- if uploaded_file:
142
- st.session_state.data = load_data(uploaded_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  st.success("File loaded!")
144
 
145
- st.markdown("---")
146
 
147
  if st.session_state.data is not None:
148
- id_col = "user_id"
149
  st.session_state.identifier_column = id_col
150
 
151
-
152
- # ─ Brand
153
- st.selectbox(
154
- "Brand *",
155
- ["drumeo", "pianote", "guitareo", "singeo"],
156
- key="brand",
157
- )
158
-
159
  st.session_state.config = load_config_("Config_files/message_system_config.json")
160
 
161
  # ─ Brand
@@ -219,7 +233,7 @@ with tab0:
219
  if st.session_state.data is not None:
220
  st.dataframe(st.session_state.data.head(100))
221
  else:
222
- st.info("Upload a CSV to preview it here.")
223
 
224
 
225
  # ------------------------------------------------------------------ TAB 2 ---#
@@ -230,18 +244,6 @@ with tab2:
230
 
231
  if st.session_state.get("generate_clicked", False):
232
 
233
- # ─ build Snowflake session
234
- conn = dict(
235
- user=get_credential("snowflake_user"),
236
- password=get_credential("snowflake_password"),
237
- account=get_credential("snowflake_account"),
238
- role=get_credential("snowflake_role"),
239
- database=get_credential("snowflake_database"),
240
- warehouse=get_credential("snowflake_warehouse"),
241
- schema=get_credential("snowflake_schema")
242
- )
243
- session = Session.builder.configs(conn).create()
244
-
245
  # ─ prepare parameters
246
  st.session_state.messaging_mode = (
247
  "recsys_result" if st.session_state.include_recommendation
@@ -273,7 +275,7 @@ with tab2:
273
 
274
  permes = Permes()
275
  df_msg = permes.create_personalize_messages(
276
- session=session,
277
  users=st.session_state.data,
278
  brand=st.session_state.brand,
279
  segment_info=st.session_state.segment_info,
 
6
  from bs4 import BeautifulSoup
7
  from Messaging_system.Permes import Permes
8
  from dotenv import load_dotenv
9
+
10
+ from Messaging_system.SnowFlakeConnection import SnowFlakeConn
11
+
12
  load_dotenv()
13
 
14
 
 
80
  def init_state() -> None:
81
  defaults = dict(
82
  involve_recsys_result=False, personalization=False,
83
+ involve_last_interaction=False, session=None,
84
  valid_instructions="",
85
  invalid_instructions="",
86
  messaging_type="push",
 
139
  # ──────────────────────────────────────────────────────────────────────────────
140
  init_state()
141
  with st.sidebar:
142
+
143
+ # ─ Brand
144
+ st.selectbox(
145
+ "Select a Brand to Start! *",
146
+ ["drumeo", "pianote", "guitareo", "singeo"],
147
+ key="brand",
148
+ )
149
+
150
+ if st.session_state.brand is not None and st.session_state.session is None:
151
+ # ─ build Snowflake session
152
+ conn = dict(
153
+ user=get_credential("snowflake_user"),
154
+ password=get_credential("snowflake_password"),
155
+ account=get_credential("snowflake_account"),
156
+ role=get_credential("snowflake_role"),
157
+ database=get_credential("snowflake_database"),
158
+ warehouse=get_credential("snowflake_warehouse"),
159
+ schema=get_credential("snowflake_schema")
160
+ )
161
+ st.session_state.session = Session.builder.configs(conn).create()
162
+
163
+ snowflake = SnowFlakeConn(session=st.session_state.session, brand=st.session_state.brand)
164
+ st.session_state.data = snowflake.get_users_in_campaign(brand=st.session_state.brand)
165
  st.success("File loaded!")
166
 
167
+ st.markdown("---")
168
 
169
  if st.session_state.data is not None:
170
+ id_col = "email"
171
  st.session_state.identifier_column = id_col
172
 
 
 
 
 
 
 
 
 
173
  st.session_state.config = load_config_("Config_files/message_system_config.json")
174
 
175
  # ─ Brand
 
233
  if st.session_state.data is not None:
234
  st.dataframe(st.session_state.data.head(100))
235
  else:
236
+ st.info("Select a brand to preview the data here.")
237
 
238
 
239
  # ------------------------------------------------------------------ TAB 2 ---#
 
244
 
245
  if st.session_state.get("generate_clicked", False):
246
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  # ─ prepare parameters
248
  st.session_state.messaging_mode = (
249
  "recsys_result" if st.session_state.include_recommendation
 
275
 
276
  permes = Permes()
277
  df_msg = permes.create_personalize_messages(
278
+ session=st.session_state.session,
279
  users=st.session_state.data,
280
  brand=st.session_state.brand,
281
  segment_info=st.session_state.segment_info,