Spaces:
Runtime error
Runtime error
File size: 5,565 Bytes
af1cbd8 4994bfb af1cbd8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
from ast import arg
import FunctionsModelSA_V1
import streamlit as st
import pandas as pd
import PIL
# import re
# from io import StringIO
# import boto3
import time
import main_app
import utils
def table_data():
# creating table data
field = [
'Data Scientist',
'Dataset',
'Algorithm',
'Framework',
'Ensemble',
'Domain',
'Model Size'
]
data = [
'Jeffrey Ott',
'Internal + Campaign monitor',
'BERT_Uncased_L_2_H_128_A-2, Single Linear Layer Neural Network, Random Forest',
'Pytorch',
'Bootstrapping',
'NLP Text Classification',
'16.8 MB'
]
data = {
'Field':field,
'Data':data
}
df = pd.DataFrame.from_dict(data)
return df
def add_bg_from_url():
st.markdown(
f"""
<style>
.stApp {{
background-image: linear-gradient(#0A3144,#126072,#1C8D99);
background-attachment: fixed;
background-size: cover
}}
</style>
""",
unsafe_allow_html=True
)
# add_bg_from_url()
st.markdown("# Sentiment Analysis: Email Industry")
# col1, col2, col3 = st.columns([1,1,1])
# with col2:
# img = PIL.Image.open("figures/ModelCC_solid.png")
# st.image(img)
stats_col1, stats_col2, stats_col3, stats_col4 = st.columns([1,1,1,1])
with stats_col1:
st.metric(label="Verified", value="Production")
with stats_col2:
st.metric(label="Accuracy", value="85%")
with stats_col3:
st.metric(label="Speed", value="3.86 ms")
with stats_col4:
st.metric(label="Industry", value="Email")
with st.sidebar:
with st.expander('Model Description', expanded=False):
img = PIL.Image.open("figures/ModelSA.png")
st.image(img)
st.markdown('The model seeks to solve the problem of how to set the tone for an email campaign appropriately. This 5th generation model from the Loxz family uses state-of-the-art NLP to determine and predict the optimized sentiment of an email using tokenization techniques. The model will analyze any email text “shape” and help the user understand the tone and how that tone correlates with the metric of interest. We applied a pre-trained tiny BERT model to vectorize the email campaign text body, then a softmax dense layer was added to get the multi-label classifications. Email metrics are provided prior to campaign launch, and the model determines the optimal engagement rate based on several factors, including inputs by the campaign engineer.')
with st.expander('Model Information', expanded=False):
hide_table_row_index = """
<style>
thead tr th:first-child {display:none}
tbody th {display:none}
</style>
"""
st.markdown(hide_table_row_index, unsafe_allow_html=True)
st.table(table_data())
utils.url_button('Model Homepage','https://loxz.com/#/models/SA')
# url_button('Full Report','https://resources.loxz.com/reports/realtime-ml-character-count-model')
utils.url_button('Amazon Market Place','https://aws.amazon.com/marketplace')
industry_lists = ['Software and Technology', 'Academic and Education',
'Entertainment', 'Finance and Banking', 'Hospitality',
'Real Estate', 'Retail', 'Energy', 'Healthcare']
campaign_types = ['Webinar', 'Engagement', 'Product_Announcement', 'Promotional',
'Newsletter', 'Abandoned_Cart', 'Review_Request', 'Survey',
'Transactional', 'Usage_and_Consumption']
target_variables = ['Conversion_Rate','Click_To_Open_Rate','Revenue_Per_Email']
input_text = st.text_area("Please enter your email text here", height=300)
industry = st.selectbox(
'Please select your industry',
industry_lists,
index=6
)
campaign = st.selectbox(
'Please select your industry',
campaign_types,
index=5
)
target = st.selectbox(
'Please select your target variable',
target_variables,
index=1
)
if st.button('Generate Predictions'):
start_time = time.time()
if input_text is "":
st.error('Please enter a sentence!')
else:
placeholder = st.empty()
placeholder.text('Loading Data')
# Starting predictions
bucket='emailcampaignmodeldata'
# file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
# email_data = utils.get_files_from_aws(bucket,file_key)
tone_key = 'ModelSADataSets/Tone_and_target.csv'
tone_data = FunctionsModelSA_V1.load_data(bucket,tone_key)
test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
# st.dataframe(test_predictions)
# st.dataframe(tones)
campaign_val='campaign_type_'+campaign
industry_val='industry_'+ industry
pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
FunctionsModelSA_V1.plot_CI(pred,lower,upper,streamlit=True)
if((best_target!=0) and (pred<best_target)):
recommended_changes=(best_target_tones-tones.loc[0])
change=best_target-pred
FunctionsModelSA_V1.recommend(tones,recommended_changes,change,target,streamlit=True)
FunctionsModelSA_V1.corrections(best_target_tones,test_predictions,streamlit=True)
placeholder.empty()
# print(time.time() - start_time) |