Spaces:
Runtime error
Runtime error
Duy-Anh Dang
commited on
Commit
·
66ea967
1
Parent(s):
1de34cd
added streamlit analytics
Browse files- app.py +53 -52
- requirements.txt +3 -1
app.py
CHANGED
@@ -4,6 +4,7 @@ import streamlit as st
|
|
4 |
import pandas as pd
|
5 |
import PIL
|
6 |
import time
|
|
|
7 |
|
8 |
import main_app
|
9 |
import utils
|
@@ -111,55 +112,55 @@ target_variables = ['Conversion_Rate','Click_To_Open_Rate','Revenue_Per_Email']
|
|
111 |
|
112 |
input_text = st.text_area("Please enter your email text here", height=50)
|
113 |
|
114 |
-
|
115 |
-
industry = st.selectbox(
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
)
|
120 |
-
|
121 |
-
campaign = st.selectbox(
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
)
|
126 |
-
|
127 |
-
target = st.selectbox(
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
)
|
132 |
-
|
133 |
-
|
134 |
-
if st.button('Generate Predictions'):
|
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 |
-
|
|
|
4 |
import pandas as pd
|
5 |
import PIL
|
6 |
import time
|
7 |
+
import streamlit_analytics
|
8 |
|
9 |
import main_app
|
10 |
import utils
|
|
|
112 |
|
113 |
input_text = st.text_area("Please enter your email text here", height=50)
|
114 |
|
115 |
+
with streamlit_analytics.track():
|
116 |
+
industry = st.selectbox(
|
117 |
+
'Please select your industry',
|
118 |
+
industry_lists,
|
119 |
+
index=6
|
120 |
+
)
|
121 |
+
|
122 |
+
campaign = st.selectbox(
|
123 |
+
'Please select your campaign type',
|
124 |
+
campaign_types,
|
125 |
+
index=5
|
126 |
+
)
|
127 |
+
|
128 |
+
target = st.selectbox(
|
129 |
+
'Please select your target variable',
|
130 |
+
target_variables,
|
131 |
+
index=1
|
132 |
+
)
|
133 |
+
|
134 |
+
|
135 |
+
if st.button('Generate Predictions'):
|
136 |
+
start_time = time.time()
|
137 |
+
if input_text is "":
|
138 |
+
st.error('Please enter a sentence!')
|
139 |
+
else:
|
140 |
+
placeholder = st.empty()
|
141 |
+
placeholder.text('Loading Data')
|
142 |
+
|
143 |
+
# Starting predictions
|
144 |
+
bucket='emailcampaignmodeldata'
|
145 |
+
# file_key = 'fullEmailBody/fullemailtextbody_labeled_3rates_8tones_20220524.csv'
|
146 |
+
|
147 |
+
# email_data = utils.get_files_from_aws(bucket,file_key)
|
148 |
+
tone_key = 'ModelSADataSets/Tone_and_target.csv'
|
149 |
+
tone_data = FunctionsModelSA_V1.load_data(bucket,tone_key)
|
150 |
+
test_predictions,tones = FunctionsModelSA_V1.convert_text_to_tone(input_text)
|
151 |
+
|
152 |
+
# st.dataframe(test_predictions)
|
153 |
+
# st.dataframe(tones)
|
154 |
+
campaign_val='campaign_type_'+campaign
|
155 |
+
industry_val='industry_'+ industry
|
156 |
+
pred,lower,upper,model = FunctionsModelSA_V1.prediction(tones,campaign_val,industry_val,target)
|
157 |
+
best_target,best_target_tones = FunctionsModelSA_V1.find_max_cat(tone_data,target,industry_val,campaign_val)
|
158 |
+
|
159 |
+
FunctionsModelSA_V1.plot_CI(pred,lower,upper,streamlit=True)
|
160 |
+
if((best_target!=0) and (pred<best_target)):
|
161 |
+
recommended_changes=(best_target_tones-tones.loc[0])
|
162 |
+
change=best_target-pred
|
163 |
+
FunctionsModelSA_V1.recommend(tones,recommended_changes,change,target,streamlit=True)
|
164 |
+
FunctionsModelSA_V1.corrections(best_target_tones,test_predictions,streamlit=True)
|
165 |
+
|
166 |
+
placeholder.empty()
|
requirements.txt
CHANGED
@@ -12,4 +12,6 @@ bs4
|
|
12 |
boto3
|
13 |
torch
|
14 |
bokeh==2.4.1
|
15 |
-
scikit-learn
|
|
|
|
|
|
12 |
boto3
|
13 |
torch
|
14 |
bokeh==2.4.1
|
15 |
+
scikit-learn
|
16 |
+
|
17 |
+
streamlit-analytics
|