Spaces:
Runtime error
Runtime error
Duy-Anh Dang
commited on
Commit
·
184bc4e
1
Parent(s):
9340cb9
col 2
Browse files
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,
|
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 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
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 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|