Spaces:
Runtime error
Runtime error
Duy-Anh Dang
commited on
Commit
·
ce54155
1
Parent(s):
c661d94
html component
Browse files
app.py
CHANGED
|
@@ -75,6 +75,7 @@ def add_bg_from_url():
|
|
| 75 |
|
| 76 |
# add_bg_from_url()
|
| 77 |
|
|
|
|
| 78 |
#add whitespace to fix scroll
|
| 79 |
def WHITE_SPACE(lines):
|
| 80 |
for x in range(lines):
|
|
@@ -212,8 +213,68 @@ with st.expander('Adjust your tone intensities for your preference: '):
|
|
| 212 |
|
| 213 |
Loxz_recom_box = st.checkbox('Select Loxz Recommended Tones for Optimal Output')
|
| 214 |
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
start_time = time.time()
|
| 218 |
if input_text == "":
|
| 219 |
st.error('Please enter a sentence!')
|
|
@@ -221,67 +282,49 @@ if st.button('Generate Predictions'):
|
|
| 221 |
placeholder = st.empty()
|
| 222 |
placeholder.text('Loading Data...')
|
| 223 |
|
| 224 |
-
|
| 225 |
-
bucket='emailcampaignmodeldata'
|
| 226 |
-
# file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
|
| 227 |
-
|
| 228 |
-
# email_data = utils.get_files_from_aws(bucket,file_key)
|
| 229 |
-
tone_key = 'ModelSADataSets/Tone_and_target.csv'
|
| 230 |
-
tone_data = FunctionsModelSA_V1.load_data()
|
| 231 |
-
|
| 232 |
-
test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
|
| 233 |
-
|
| 234 |
-
# st.dataframe(test_predictions)
|
| 235 |
-
# st.dataframe(tones)
|
| 236 |
-
campaign_val='campaign_type_'+ campaign
|
| 237 |
-
industry_val='industry_'+ industry
|
| 238 |
-
pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
|
| 239 |
-
worst_target,best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
|
| 240 |
-
#best_target, best_target_tones
|
| 241 |
-
#FunctionsModelSA_V1.plot_CI(pred,lower,upper)
|
| 242 |
-
st.write('The Predicted Value is ' + str(pred))
|
| 243 |
-
fig1 = go.Figure(go.Bar(
|
| 244 |
-
name = 'Tone Levels',
|
| 245 |
-
x=[joyful_tone_value, confident_tone_value, urgent_tone_value, friendly_tone_value, optimistic_tone_value, analytical_tone_value, casual_tone_value],
|
| 246 |
-
y=['Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'],
|
| 247 |
-
orientation='h')
|
| 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 |
-
fig2 = go.Figure()
|
| 258 |
-
fig2.add_trace(go.Bar(
|
| 259 |
-
y=tone_labels,
|
| 260 |
-
x=recommended_changes,
|
| 261 |
-
name='Recommend changes',
|
| 262 |
-
orientation='h',
|
| 263 |
-
text=np.round(recommended_changes,3),
|
| 264 |
-
width=.5,
|
| 265 |
-
marker=dict(
|
| 266 |
-
color='#e60f00',
|
| 267 |
-
line=dict(color='rgba(58, 71, 80, 1.0)', width=1)))
|
| 268 |
-
)
|
| 269 |
-
fig2.update_traces(textfont_size=18, textposition="outside", cliponaxis=False)
|
| 270 |
-
if target == 'Revenue_Per_Email':
|
| 271 |
-
out = f"${round(change,2)}"
|
| 272 |
-
st.write("The output will be between the range " + str(round(lower,2)) + ' and ' + str(round(upper,2)))
|
| 273 |
-
st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)))
|
| 274 |
-
else:
|
| 275 |
-
out = f"{round(change,2)*100}%"
|
| 276 |
-
st.write("The output will be between the range " + str(round(lower,2) * 100) + ' and ' + str(round(upper,2) *100))
|
| 277 |
-
st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)*100))
|
| 278 |
-
fig2.update_layout(title_text=f'The following Changes will yield a {out} increase in {target}')
|
| 279 |
-
|
| 280 |
-
st.plotly_chart(fig2, use_container_width=True)
|
| 281 |
-
#FunctionsModelSA_V1.corrections(best_target_tones,test_predictions))
|
| 282 |
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
WHITE_SPACE(10)
|
| 286 |
-
st.write('
|
| 287 |
|
|
|
|
| 75 |
|
| 76 |
# add_bg_from_url()
|
| 77 |
|
| 78 |
+
|
| 79 |
#add whitespace to fix scroll
|
| 80 |
def WHITE_SPACE(lines):
|
| 81 |
for x in range(lines):
|
|
|
|
| 213 |
|
| 214 |
Loxz_recom_box = st.checkbox('Select Loxz Recommended Tones for Optimal Output')
|
| 215 |
|
| 216 |
+
def create_charts():
|
| 217 |
+
# Starting predictions
|
| 218 |
+
bucket='emailcampaignmodeldata'
|
| 219 |
+
# file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
|
| 220 |
|
| 221 |
+
# email_data = utils.get_files_from_aws(bucket,file_key)
|
| 222 |
+
tone_key = 'ModelSADataSets/Tone_and_target.csv'
|
| 223 |
+
tone_data = FunctionsModelSA_V1.load_data()
|
| 224 |
+
|
| 225 |
+
test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
|
| 226 |
+
|
| 227 |
+
# st.dataframe(test_predictions)
|
| 228 |
+
# st.dataframe(tones)
|
| 229 |
+
campaign_val='campaign_type_'+ campaign
|
| 230 |
+
industry_val='industry_'+ industry
|
| 231 |
+
pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
|
| 232 |
+
worst_target,best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
|
| 233 |
+
#best_target, best_target_tones
|
| 234 |
+
#FunctionsModelSA_V1.plot_CI(pred,lower,upper)
|
| 235 |
+
st.write('The Predicted Value is ' + str(pred))
|
| 236 |
+
fig1 = go.Figure(go.Bar(
|
| 237 |
+
name = 'Tone Levels',
|
| 238 |
+
x=[joyful_tone_value, confident_tone_value, urgent_tone_value, friendly_tone_value, optimistic_tone_value, analytical_tone_value, casual_tone_value],
|
| 239 |
+
y=['Joyful', 'Confident', 'Urgent', 'Friendly', 'Optimistic', 'Analytical', 'Casual'],
|
| 240 |
+
orientation='h')
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
st.plotly_chart(fig1, use_container_width=True)
|
| 244 |
+
|
| 245 |
+
#if((best_target!=0) and (pred<best_target)):
|
| 246 |
+
if Loxz_recom_box == True:
|
| 247 |
+
recommended_changes=(best_target_tones)
|
| 248 |
+
change=best_target-pred
|
| 249 |
+
#recommend(tones,recommended_changes,change,target)
|
| 250 |
+
fig2 = go.Figure()
|
| 251 |
+
fig2.add_trace(go.Bar(
|
| 252 |
+
y=tone_labels,
|
| 253 |
+
x=recommended_changes,
|
| 254 |
+
name='Recommend changes',
|
| 255 |
+
orientation='h',
|
| 256 |
+
text=np.round(recommended_changes,3),
|
| 257 |
+
width=.5,
|
| 258 |
+
marker=dict(
|
| 259 |
+
color='#e60f00',
|
| 260 |
+
line=dict(color='rgba(58, 71, 80, 1.0)', width=1)))
|
| 261 |
+
)
|
| 262 |
+
fig2.update_traces(textfont_size=18, textposition="outside", cliponaxis=False)
|
| 263 |
+
if target == 'Revenue_Per_Email':
|
| 264 |
+
out = f"${round(change,2)}"
|
| 265 |
+
st.write("The output will be between the range " + str(round(lower,2)) + ' and ' + str(round(upper,2)))
|
| 266 |
+
st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)))
|
| 267 |
+
else:
|
| 268 |
+
out = f"{round(change,2)*100}%"
|
| 269 |
+
st.write("The output will be between the range " + str(round(lower,2) * 100) + ' and ' + str(round(upper,2) *100))
|
| 270 |
+
st.write("The Predicted "+str(target) +" is "+ str(round(pred,2)*100))
|
| 271 |
+
fig2.update_layout(title_text=f'The following Changes will yield a {out} increase in {target}')
|
| 272 |
+
|
| 273 |
+
st.plotly_chart(fig2, use_container_width=True)
|
| 274 |
+
#FunctionsModelSA_V1.corrections(best_target_tones,test_predictions))
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
if st.button('Generate Predictions'):
|
| 278 |
start_time = time.time()
|
| 279 |
if input_text == "":
|
| 280 |
st.error('Please enter a sentence!')
|
|
|
|
| 282 |
placeholder = st.empty()
|
| 283 |
placeholder.text('Loading Data...')
|
| 284 |
|
| 285 |
+
create_charts()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
+
placeholder.empty()
|
| 288 |
+
|
| 289 |
+
st.components.v1.html(
|
| 290 |
+
"""
|
| 291 |
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
| 292 |
+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
| 293 |
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
|
| 294 |
+
<div id="accordion">
|
| 295 |
+
<div class="card">
|
| 296 |
+
<div class="card-header" id="headingOne">
|
| 297 |
+
<h5 class="mb-0">
|
| 298 |
+
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
|
| 299 |
+
Collapsible Group Item #1
|
| 300 |
+
</button>
|
| 301 |
+
</h5>
|
| 302 |
+
</div>
|
| 303 |
+
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
|
| 304 |
+
<div class="card-body">
|
| 305 |
+
Collapsible Group Item #1 content
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
<div class="card">
|
| 310 |
+
<div class="card-header" id="headingTwo">
|
| 311 |
+
<h5 class="mb-0">
|
| 312 |
+
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
|
| 313 |
+
Collapsible Group Item #2
|
| 314 |
+
</button>
|
| 315 |
+
</h5>
|
| 316 |
+
</div>
|
| 317 |
+
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
|
| 318 |
+
<div class="card-body">
|
| 319 |
+
Collapsible Group Item #2 content
|
| 320 |
+
</div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
""",
|
| 325 |
+
height=600,
|
| 326 |
+
)
|
| 327 |
|
| 328 |
WHITE_SPACE(10)
|
| 329 |
+
st.write('All rights reserved by Loxz Digital')
|
| 330 |
|