Duy-Anh Dang commited on
Commit
cf208d2
·
1 Parent(s): 0697e5d

replace None

Browse files
Files changed (1) hide show
  1. app.py +140 -136
app.py CHANGED
@@ -137,153 +137,157 @@ with stats_col4:
137
  st.caption("Industry: Email")
138
  #st.metric(label="Industry", value="Email")
139
 
140
- with st.empty().container():
141
- input_text = st.text_area("Please enter your email text here: ", height=50)
142
-
143
- with st.expander('Please select your parameters: '):
144
- with streamlit_analytics.track('test123'):
145
- industry = st.selectbox(
146
- 'Please select your industry',
147
- industry_lists,
148
- index=6
149
- )
150
-
151
- target = st.selectbox(
152
- 'Please select your target variable',
153
- target_variables,
154
- index=1
155
- )
156
-
157
- campaign = st.selectbox(
158
- 'Please select your campaign type',
159
- campaign_types,
160
- index=7
161
- )
162
-
163
- region = st.selectbox(
164
- 'Select your target region to generate the email with a more appropriate tone:',
165
- region_variables,
166
- index=1
167
- )
168
-
169
-
170
- with st.expander('Adjust your tone intensities for your preference: '):
171
- #'Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'
172
- joyful_tone_value = st.slider(
173
- 'Joyful: ',
174
- value = 0
175
  )
176
- st.write('Joyful: ', joyful_tone_value)
177
-
178
- confident_tone_value = st.slider(
179
- 'Confident: ',
180
- value = 0
181
  )
182
- st.write('Confident: ', confident_tone_value)
183
 
184
- urgent_tone_value = st.slider(
185
- 'Urgent: ',
186
- value = 0
 
187
  )
188
- st.write('Urgent: ', urgent_tone_value)
189
 
190
- friendly_tone_value = st.slider(
191
- 'Friendly: ',
192
- value = 0
 
193
  )
194
- st.write('Friendly: ', friendly_tone_value)
195
 
196
- optimistic_tone_value = st.slider(
197
- 'Optimistic: ',
198
- value = 0
199
- )
200
- st.write('Optimistic: ', optimistic_tone_value)
201
 
202
- analytical_tone_value = st.slider(
203
- 'Analytical: ',
204
- value = 0
205
- )
206
- st.write('Analytical: ', analytical_tone_value)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
 
208
- casual_tone_value = st.slider(
209
- 'Casual: ',
210
- value = 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  )
212
- st.write('Casual: ', casual_tone_value)
213
-
214
- Loxz_recom_box = st.checkbox('Select Loxz Recommended Tones for Optimal Output')
215
-
216
- chart_position = st.empty()
217
- with chart_position.container():
218
- WHITE_SPACE(10)
219
-
220
- if st.button('Generate Predictions'):
221
- #with st.empty.container():
222
  with chart_position.container():
223
- start_time = time.time()
224
- if input_text == "":
225
- st.error('Please enter a sentence!')
226
- else:
227
- placeholder = st.empty()
228
- placeholder.text('Loading Data...')
229
-
230
- # Starting predictions
231
- bucket='emailcampaignmodeldata'
232
- # file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
233
-
234
- # email_data = utils.get_files_from_aws(bucket,file_key)
235
- tone_key = 'ModelSADataSets/Tone_and_target.csv'
236
- tone_data = FunctionsModelSA_V1.load_data()
237
- test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
238
-
239
- # st.dataframe(test_predictions)
240
- # st.dataframe(tones)
241
- campaign_val='campaign_type_'+ campaign
242
- industry_val='industry_'+ industry
243
- pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
244
- worst_target,best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
245
- #best_target, best_target_tones
246
- #FunctionsModelSA_V1.plot_CI(pred,lower,upper)
247
- st.write('The Predicted Value is ' + str(pred))
248
- fig1 = go.Figure(go.Bar(
249
- name = 'Tone Levels',
250
- x=[joyful_tone_value, confident_tone_value, urgent_tone_value, friendly_tone_value, optimistic_tone_value, analytical_tone_value, casual_tone_value],
251
- y=['Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'],
252
- orientation='h')
253
  )
254
- st.plotly_chart(fig1, use_container_width=True)
255
-
256
- #if((best_target!=0) and (pred<best_target)):
257
- if Loxz_recom_box == True:
258
- recommended_changes=(best_target_tones)
259
- change=best_target-pred
260
- #recommend(tones,recommended_changes,change,target)
261
-
262
- fig2 = go.Figure()
263
- fig2.add_trace(go.Bar(
264
- y=tone_labels,
265
- x=recommended_changes,
266
- name='Recommend changes',
267
- orientation='h',
268
- text=np.round(recommended_changes,3),
269
- width=.5,
270
- marker=dict(
271
- color='#e60f00',
272
- line=dict(color='rgba(58, 71, 80, 1.0)', width=1)))
273
- )
274
- fig2.update_traces(textfont_size=18, textposition="outside", cliponaxis=False)
275
- if target == 'Revenue_Per_Email':
276
- out = f"${round(change,2)}"
277
- st.write("The output will be between the range " + str(round(lower,2)) + ' and ' + str(round(upper,2)))
278
- st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)))
279
- else:
280
- out = f"{round(change,2)*100}%"
281
- st.write("The output will be between the range " + str(round(lower,2) * 100) + ' and ' + str(round(upper,2) *100))
282
- st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)*100))
283
- fig2.update_layout(title_text=f'The following Changes will yield a {out} increase in {target}')
284
- st.plotly_chart(fig2, use_container_width=True)
285
- #FunctionsModelSA_V1.corrections(best_target_tones,test_predictions))
286
-
287
- placeholder.empty()
288
 
289
 
 
137
  st.caption("Industry: Email")
138
  #st.metric(label="Industry", value="Email")
139
 
140
+ input_text = st.text_area("Please enter your email text here: ", height=50)
141
+
142
+ with st.expander('Please select your parameters: '):
143
+ with streamlit_analytics.track('test123'):
144
+ industry = st.selectbox(
145
+ 'Please select your industry',
146
+ industry_lists,
147
+ index=6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  )
149
+
150
+ target = st.selectbox(
151
+ 'Please select your target variable',
152
+ target_variables,
153
+ index=1
154
  )
 
155
 
156
+ campaign = st.selectbox(
157
+ 'Please select your campaign type',
158
+ campaign_types,
159
+ index=7
160
  )
 
161
 
162
+ region = st.selectbox(
163
+ 'Select your target region to generate the email with a more appropriate tone:',
164
+ region_variables,
165
+ index=1
166
  )
 
167
 
 
 
 
 
 
168
 
169
+ with st.expander('Adjust your tone intensities for your preference: '):
170
+ #'Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'
171
+ joyful_tone_value = st.slider(
172
+ 'Joyful: ',
173
+ value = 0
174
+ )
175
+ st.write('Joyful: ', joyful_tone_value)
176
+
177
+ confident_tone_value = st.slider(
178
+ 'Confident: ',
179
+ value = 0
180
+ )
181
+ st.write('Confident: ', confident_tone_value)
182
+
183
+ urgent_tone_value = st.slider(
184
+ 'Urgent: ',
185
+ value = 0
186
+ )
187
+ st.write('Urgent: ', urgent_tone_value)
188
+
189
+ friendly_tone_value = st.slider(
190
+ 'Friendly: ',
191
+ value = 0
192
+ )
193
+ st.write('Friendly: ', friendly_tone_value)
194
+
195
+ optimistic_tone_value = st.slider(
196
+ 'Optimistic: ',
197
+ value = 0
198
+ )
199
+ st.write('Optimistic: ', optimistic_tone_value)
200
+
201
+ analytical_tone_value = st.slider(
202
+ 'Analytical: ',
203
+ value = 0
204
+ )
205
+ st.write('Analytical: ', analytical_tone_value)
206
+
207
+ casual_tone_value = st.slider(
208
+ 'Casual: ',
209
+ value = 0
210
+ )
211
+ st.write('Casual: ', casual_tone_value)
212
+
213
+ Loxz_recom_box = st.checkbox('Select Loxz Recommended Tones for Optimal Output')
214
+
215
+ chart_position = st.empty()
216
+ chart_position2 = st.empty()
217
+
218
+ with chart_position.container():
219
+ None
220
+ with chart_position2.container():
221
+ None
222
+ if st.button('Generate Predictions'):
223
+
224
+ start_time = time.time()
225
+ if input_text == "":
226
+ st.error('Please enter a sentence!')
227
+ else:
228
+ placeholder = st.empty()
229
+ placeholder.text('Loading Data...')
230
+
231
+ # Starting predictions
232
+ bucket='emailcampaignmodeldata'
233
+ # file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
234
 
235
+ # email_data = utils.get_files_from_aws(bucket,file_key)
236
+ tone_key = 'ModelSADataSets/Tone_and_target.csv'
237
+ tone_data = FunctionsModelSA_V1.load_data()
238
+
239
+ test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
240
+
241
+ # st.dataframe(test_predictions)
242
+ # st.dataframe(tones)
243
+ campaign_val='campaign_type_'+ campaign
244
+ industry_val='industry_'+ industry
245
+ pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
246
+ worst_target,best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
247
+ #best_target, best_target_tones
248
+ #FunctionsModelSA_V1.plot_CI(pred,lower,upper)
249
+ st.write('The Predicted Value is ' + str(pred))
250
+ fig1 = go.Figure(go.Bar(
251
+ name = 'Tone Levels',
252
+ x=[joyful_tone_value, confident_tone_value, urgent_tone_value, friendly_tone_value, optimistic_tone_value, analytical_tone_value, casual_tone_value],
253
+ y=['Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'],
254
+ orientation='h')
255
  )
 
 
 
 
 
 
 
 
 
 
256
  with chart_position.container():
257
+ st.plotly_chart(fig1, use_container_width=True)
258
+
259
+ #if((best_target!=0) and (pred<best_target)):
260
+ if Loxz_recom_box == True:
261
+ recommended_changes=(best_target_tones)
262
+ change=best_target-pred
263
+ #recommend(tones,recommended_changes,change,target)
264
+ with chart_position2.container():
265
+ fig2 = go.Figure()
266
+ fig2.add_trace(go.Bar(
267
+ y=tone_labels,
268
+ x=recommended_changes,
269
+ name='Recommend changes',
270
+ orientation='h',
271
+ text=np.round(recommended_changes,3),
272
+ width=.5,
273
+ marker=dict(
274
+ color='#e60f00',
275
+ line=dict(color='rgba(58, 71, 80, 1.0)', width=1)))
 
 
 
 
 
 
 
 
 
 
 
276
  )
277
+ fig2.update_traces(textfont_size=18, textposition="outside", cliponaxis=False)
278
+ if target == 'Revenue_Per_Email':
279
+ out = f"${round(change,2)}"
280
+ st.write("The output will be between the range " + str(round(lower,2)) + ' and ' + str(round(upper,2)))
281
+ st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)))
282
+ else:
283
+ out = f"{round(change,2)*100}%"
284
+ st.write("The output will be between the range " + str(round(lower,2) * 100) + ' and ' + str(round(upper,2) *100))
285
+ st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)*100))
286
+ fig2.update_layout(title_text=f'The following Changes will yield a {out} increase in {target}')
287
+
288
+ st.plotly_chart(fig2, use_container_width=True)
289
+ #FunctionsModelSA_V1.corrections(best_target_tones,test_predictions))
290
+
291
+ placeholder.empty()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
 
293