Duy-Anh Dang commited on
Commit
184bc4e
·
1 Parent(s): 9340cb9
Files changed (1) hide show
  1. app.py +65 -65
app.py CHANGED
@@ -122,7 +122,7 @@ region_variables = ['Africa', 'America', 'Asia', 'Europe', 'Oceania']
122
  st.markdown("#### Sentiment Analysis: Email Industry v1.2")
123
 
124
  stats_col1, stats_col2, stats_col3, stats_col4 = st.columns([1,1,1,1])
125
- '''
126
  with stats_col1:
127
  st.caption("Verified: Production")
128
  #st.metric(label="Verified", value= "Production")
@@ -136,8 +136,8 @@ with stats_col3:
136
  with stats_col4:
137
  st.caption("Industry: Email")
138
  #st.metric(label="Industry", value="Email")
139
- '''
140
- coluno, coldos = st.columns([5, 1])
141
 
142
  with coluno:
143
  input_text = st.text_area("Please enter your email text here: ", height=50)
@@ -220,67 +220,67 @@ with coluno:
220
  if input_text == "":
221
  st.error('Please enter a sentence!')
222
  else:
223
- placeholder = st.empty()
224
- placeholder.text('Loading Data...')
225
-
226
- # Starting predictions
227
- bucket='emailcampaignmodeldata'
228
- # file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
229
-
230
- # email_data = utils.get_files_from_aws(bucket,file_key)
231
- tone_key = 'ModelSADataSets/Tone_and_target.csv'
232
- tone_data = FunctionsModelSA_V1.load_data()
233
- test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
234
-
235
- # st.dataframe(test_predictions)
236
- # st.dataframe(tones)
237
- campaign_val='campaign_type_'+ campaign
238
- industry_val='industry_'+ industry
239
- pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
240
- worst_target,best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
241
- #best_target, best_target_tones
242
- #FunctionsModelSA_V1.plot_CI(pred,lower,upper)
243
- st.write('The Predicted Value is ' + str(pred))
244
- fig1 = go.Figure(go.Bar(
245
- name = 'Tone Levels',
246
- x=[joyful_tone_value, confident_tone_value, urgent_tone_value, friendly_tone_value, optimistic_tone_value, analytical_tone_value, casual_tone_value],
247
- y=['Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'],
248
- orientation='h')
249
- )
250
- st.plotly_chart(fig1, use_container_width=True)
251
-
252
- #if((best_target!=0) and (pred<best_target)):
253
- if Loxz_recom_box == True:
254
- recommended_changes=(best_target_tones)
255
- change=best_target-pred
256
- #recommend(tones,recommended_changes,change,target)
257
-
258
- fig2 = go.Figure()
259
- fig2.add_trace(go.Bar(
260
- y=tone_labels,
261
- x=recommended_changes,
262
- name='Recommend changes',
263
- orientation='h',
264
- text=np.round(recommended_changes,3),
265
- width=.5,
266
- marker=dict(
267
- color='#e60f00',
268
- line=dict(color='rgba(58, 71, 80, 1.0)', width=1)))
269
  )
270
- fig2.update_traces(textfont_size=18, textposition="outside", cliponaxis=False)
271
- if target == 'Revenue_Per_Email':
272
- out = f"${round(change,2)}"
273
- st.write("The output will be between the range " + str(round(lower,2)) + ' and ' + str(round(upper,2)))
274
- st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)))
275
- else:
276
- out = f"{round(change,2)*100}%"
277
- st.write("The output will be between the range " + str(round(lower,2) * 100) + ' and ' + str(round(upper,2) *100))
278
- st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)*100))
279
- fig2.update_layout(title_text=f'The following Changes will yield a {out} increase in {target}')
280
- st.plotly_chart(fig2, use_container_width=True)
281
- #FunctionsModelSA_V1.corrections(best_target_tones,test_predictions))
282
-
283
- placeholder.empty()
284
-
285
- WHITE_SPACE(10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  WHITE_SPACE(10)
 
122
  st.markdown("#### Sentiment Analysis: Email Industry v1.2")
123
 
124
  stats_col1, stats_col2, stats_col3, stats_col4 = st.columns([1,1,1,1])
125
+
126
  with stats_col1:
127
  st.caption("Verified: Production")
128
  #st.metric(label="Verified", value= "Production")
 
136
  with stats_col4:
137
  st.caption("Industry: Email")
138
  #st.metric(label="Industry", value="Email")
139
+
140
+ coluno, coldos = st.columns([5, 3])
141
 
142
  with coluno:
143
  input_text = st.text_area("Please enter your email text here: ", height=50)
 
220
  if input_text == "":
221
  st.error('Please enter a sentence!')
222
  else:
223
+ with coldos:
224
+ placeholder = st.empty()
225
+ placeholder.text('Loading Data...')
226
+
227
+ # Starting predictions
228
+ bucket='emailcampaignmodeldata'
229
+ # file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
230
+
231
+ # email_data = utils.get_files_from_aws(bucket,file_key)
232
+ tone_key = 'ModelSADataSets/Tone_and_target.csv'
233
+ tone_data = FunctionsModelSA_V1.load_data()
234
+ test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
235
+
236
+ # st.dataframe(test_predictions)
237
+ # st.dataframe(tones)
238
+ campaign_val='campaign_type_'+ campaign
239
+ industry_val='industry_'+ industry
240
+ pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
241
+ worst_target,best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
242
+ #best_target, best_target_tones
243
+ #FunctionsModelSA_V1.plot_CI(pred,lower,upper)
244
+ st.write('The Predicted Value is ' + str(pred))
245
+ fig1 = go.Figure(go.Bar(
246
+ name = 'Tone Levels',
247
+ x=[joyful_tone_value, confident_tone_value, urgent_tone_value, friendly_tone_value, optimistic_tone_value, analytical_tone_value, casual_tone_value],
248
+ y=['Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'],
249
+ orientation='h')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  )
251
+ st.plotly_chart(fig1, use_container_width=True)
252
+
253
+ #if((best_target!=0) and (pred<best_target)):
254
+ if Loxz_recom_box == True:
255
+ recommended_changes=(best_target_tones)
256
+ change=best_target-pred
257
+ #recommend(tones,recommended_changes,change,target)
258
+
259
+ fig2 = go.Figure()
260
+ fig2.add_trace(go.Bar(
261
+ y=tone_labels,
262
+ x=recommended_changes,
263
+ name='Recommend changes',
264
+ orientation='h',
265
+ text=np.round(recommended_changes,3),
266
+ width=.5,
267
+ marker=dict(
268
+ color='#e60f00',
269
+ line=dict(color='rgba(58, 71, 80, 1.0)', width=1)))
270
+ )
271
+ fig2.update_traces(textfont_size=18, textposition="outside", cliponaxis=False)
272
+ if target == 'Revenue_Per_Email':
273
+ out = f"${round(change,2)}"
274
+ st.write("The output will be between the range " + str(round(lower,2)) + ' and ' + str(round(upper,2)))
275
+ st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)))
276
+ else:
277
+ out = f"{round(change,2)*100}%"
278
+ st.write("The output will be between the range " + str(round(lower,2) * 100) + ' and ' + str(round(upper,2) *100))
279
+ st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)*100))
280
+ fig2.update_layout(title_text=f'The following Changes will yield a {out} increase in {target}')
281
+ st.plotly_chart(fig2, use_container_width=True)
282
+ #FunctionsModelSA_V1.corrections(best_target_tones,test_predictions))
283
+
284
+ placeholder.empty()
285
+
286
  WHITE_SPACE(10)