Spaces:
Runtime error
Runtime error
Chandan Dwivedi
commited on
Commit
·
b0b3685
1
Parent(s):
011c239
Added Generative AI LLM support
Browse files- .DS_Store +0 -0
- README.md +1 -2
- app.py +11 -46
- main_app.py +15 -0
- requirements.txt +5 -12
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
README.md
CHANGED
@@ -4,8 +4,7 @@ emoji: ✉️
|
|
4 |
colorFrom: purple
|
5 |
colorTo: yellow
|
6 |
sdk: streamlit
|
7 |
-
sdk_version: 1.
|
8 |
-
python_version: 3.9
|
9 |
app_file: app.py
|
10 |
pinned: false
|
11 |
duplicated_from: loxzdigital/Model-CC-Space
|
|
|
4 |
colorFrom: purple
|
5 |
colorTo: yellow
|
6 |
sdk: streamlit
|
7 |
+
sdk_version: 1.10.0
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
duplicated_from: loxzdigital/Model-CC-Space
|
app.py
CHANGED
@@ -7,8 +7,6 @@ from io import StringIO
|
|
7 |
import boto3
|
8 |
from urlextract import URLExtract
|
9 |
import time
|
10 |
-
from utils import *
|
11 |
-
|
12 |
# from joblib import dump, load
|
13 |
|
14 |
import joblib
|
@@ -16,18 +14,15 @@ import joblib
|
|
16 |
from bokeh.models.widgets import Div
|
17 |
|
18 |
import email
|
19 |
-
import os
|
20 |
#from ipyfilechooser import FileChooser
|
21 |
|
22 |
#from IPython.display import display
|
|
|
23 |
from bs4 import BeautifulSoup
|
24 |
import matplotlib.pyplot as plt
|
25 |
import numpy as np
|
26 |
import timeit
|
27 |
-
import shutil
|
28 |
|
29 |
-
CURRENT_THEME = "blue"
|
30 |
-
IS_DARK_THEME = True
|
31 |
|
32 |
def table_data():
|
33 |
# creating table data
|
@@ -184,7 +179,7 @@ def add_bg_from_url():
|
|
184 |
f"""
|
185 |
<style>
|
186 |
.stApp {{
|
187 |
-
background-image: linear-gradient(
|
188 |
background-attachment: fixed;
|
189 |
background-size: cover
|
190 |
|
@@ -267,10 +262,6 @@ target_variables = [
|
|
267 |
uploaded_file = st.file_uploader(
|
268 |
"Please upload your email (In HTML Format)", type=["html"])
|
269 |
|
270 |
-
def save_file(uploaded_file):
|
271 |
-
with open(os.path.join("./",uploaded_file.name),"wb") as f:
|
272 |
-
f.write(uploaded_file.getbuffer())
|
273 |
-
|
274 |
if uploaded_file is None:
|
275 |
# upload_img = PIL.Image.open(uploaded_file)
|
276 |
upload_img = None
|
@@ -307,6 +298,7 @@ st.markdown("""---""")
|
|
307 |
def get_files_from_aws(bucket, prefix):
|
308 |
"""
|
309 |
get files from aws s3 bucket
|
|
|
310 |
bucket (STRING): bucket name
|
311 |
prefix (STRING): file location in s3 bucket
|
312 |
"""
|
@@ -331,7 +323,6 @@ if st.button('Generate Predictions'):
|
|
331 |
if uploaded_file is None:
|
332 |
st.error('Please upload a email (HTML format)')
|
333 |
else:
|
334 |
-
save_file(uploaded_file)
|
335 |
placeholder = st.empty()
|
336 |
placeholder.text('Loading Data')
|
337 |
|
@@ -381,7 +372,7 @@ if st.button('Generate Predictions'):
|
|
381 |
print(
|
382 |
"Sorry, Current model couldn't provide predictions on the target variable you selected.")
|
383 |
else:
|
384 |
-
st.markdown('
|
385 |
character_cnt), unsafe_allow_html=True)
|
386 |
# st.info('The model predicts that it achieves a {} of {}%'.format(target, str(round(output_rate*100,2))))
|
387 |
if target == 'conversion_rate':
|
@@ -389,7 +380,7 @@ if st.button('Generate Predictions'):
|
|
389 |
else:
|
390 |
target_vis = 'Open_Rate'
|
391 |
|
392 |
-
st.markdown('
|
393 |
target_vis, str(round(output_rate*100, 3))), unsafe_allow_html=True)
|
394 |
selected_industry_code = industry_code_dict.get(industry)
|
395 |
|
@@ -441,10 +432,10 @@ if st.button('Generate Predictions'):
|
|
441 |
if selected_variable == "Click_Through_Rate":
|
442 |
selected_variable = "Conversion_Rate"
|
443 |
|
444 |
-
st.markdown('
|
445 |
selected_variable), unsafe_allow_html=True)
|
446 |
if len(df_reco_opt_rank) == 0:
|
447 |
-
st.markdown('
|
448 |
selected_variable), unsafe_allow_html=True)
|
449 |
else:
|
450 |
#for _, row in df_reco_opt_rank.iterrows():
|
@@ -462,13 +453,8 @@ if st.button('Generate Predictions'):
|
|
462 |
selected_variable_number = row[3]
|
463 |
chars.append(int(Character_Count))
|
464 |
sel_var_values.append(round(selected_variable_number, 3)*100)
|
465 |
-
|
466 |
st.write("\n")
|
467 |
-
df_modelpred=pd.DataFrame(list(zip(chars, sel_var_values)), columns=["Number of Characters", "Target_Rate"])
|
468 |
-
# st.checkbox("Use container width", value=False, key="use_container_width")
|
469 |
-
# st.dataframe(df_modelpred.style.highlight_max(axis=0), use_container_width=st.session_state.use_container_width)
|
470 |
-
df_modelpred.sort_values(by='Target_Rate', ascending=False, inplace = True)
|
471 |
-
st.dataframe(df_modelpred)
|
472 |
|
473 |
if len(chars) > 1:
|
474 |
#fig = plt.figure()
|
@@ -479,7 +465,7 @@ if st.button('Generate Predictions'):
|
|
479 |
#ax.bar_label(bars)
|
480 |
|
481 |
ax.set_yticks(np.arange(len(chars)))
|
482 |
-
ax.set_yticklabels(
|
483 |
ax.set_title('Character Counts vs. Target Variable Rates', fontsize=18)
|
484 |
ax.set_ylabel('Character Counts', fontsize=16)
|
485 |
ax.set_xlabel('Target Rates %', fontsize=16)
|
@@ -496,32 +482,11 @@ if st.button('Generate Predictions'):
|
|
496 |
st.plotly_chart(fig, use_container_width=True)
|
497 |
|
498 |
st.write("\n")
|
499 |
-
chars_out = dict(zip(chars, sel_var_values))
|
500 |
-
sorted_chars_out = sorted(chars_out.items(), key=lambda x: x[1], reverse=True)
|
501 |
-
prefrence_variables=res=["charcter counts: "+str(x)+", Target Rate: "+str(y) for x,y in zip(chars,sel_var_values)]
|
502 |
-
preference = st.selectbox(
|
503 |
-
'Please select your preferences',
|
504 |
-
prefrence_variables,
|
505 |
-
index=1
|
506 |
-
)
|
507 |
-
if st.button('Generate AI Recommended Email'):
|
508 |
-
if(preference is None):
|
509 |
-
st.error('Please upload a email (HTML format)')
|
510 |
-
else:
|
511 |
-
ai_generated_email=generate_example_email_with_context(email_body, campaign, industry, target, sorted_chars_out, preference)
|
512 |
-
st.markdown('##### Here is the recommended Generated Email for you:')
|
513 |
-
st.markdown('####### {}:'.format(ai_generated_email),unsafe_allow_html=True)
|
514 |
-
preference= "charcter counts: "+str(573)+", Target Rate: "+str(37.2)
|
515 |
-
ai_generated_email=generate_example_email_with_context(email_body, campaign, industry, target, sorted_chars_out, preference)
|
516 |
-
print("ai_generated_email: ",ai_generated_email)
|
517 |
-
st.markdown('##### Here is the recommended Generated Email for you:')
|
518 |
-
st.markdown('####### {}'.format(ai_generated_email),unsafe_allow_html=True)
|
519 |
#st.write(np.array(chars))
|
520 |
-
|
521 |
-
|
522 |
chars_out = dict(zip(chars, sel_var_values))
|
523 |
sorted_chars_out = sorted(chars_out.items(), key=lambda x: x[1], reverse=True)
|
524 |
|
525 |
|
526 |
placeholder.empty()
|
527 |
-
#st.write(time.time() - start_time)
|
|
|
|
7 |
import boto3
|
8 |
from urlextract import URLExtract
|
9 |
import time
|
|
|
|
|
10 |
# from joblib import dump, load
|
11 |
|
12 |
import joblib
|
|
|
14 |
from bokeh.models.widgets import Div
|
15 |
|
16 |
import email
|
|
|
17 |
#from ipyfilechooser import FileChooser
|
18 |
|
19 |
#from IPython.display import display
|
20 |
+
from io import BytesIO
|
21 |
from bs4 import BeautifulSoup
|
22 |
import matplotlib.pyplot as plt
|
23 |
import numpy as np
|
24 |
import timeit
|
|
|
25 |
|
|
|
|
|
26 |
|
27 |
def table_data():
|
28 |
# creating table data
|
|
|
179 |
f"""
|
180 |
<style>
|
181 |
.stApp {{
|
182 |
+
background-image: linear-gradient(#45eff5,#1C8D99);
|
183 |
background-attachment: fixed;
|
184 |
background-size: cover
|
185 |
|
|
|
262 |
uploaded_file = st.file_uploader(
|
263 |
"Please upload your email (In HTML Format)", type=["html"])
|
264 |
|
|
|
|
|
|
|
|
|
265 |
if uploaded_file is None:
|
266 |
# upload_img = PIL.Image.open(uploaded_file)
|
267 |
upload_img = None
|
|
|
298 |
def get_files_from_aws(bucket, prefix):
|
299 |
"""
|
300 |
get files from aws s3 bucket
|
301 |
+
|
302 |
bucket (STRING): bucket name
|
303 |
prefix (STRING): file location in s3 bucket
|
304 |
"""
|
|
|
323 |
if uploaded_file is None:
|
324 |
st.error('Please upload a email (HTML format)')
|
325 |
else:
|
|
|
326 |
placeholder = st.empty()
|
327 |
placeholder.text('Loading Data')
|
328 |
|
|
|
372 |
print(
|
373 |
"Sorry, Current model couldn't provide predictions on the target variable you selected.")
|
374 |
else:
|
375 |
+
st.markdown('#### Current Character Count in Your Email is: <span style="color:blue">{}</span>'.format(
|
376 |
character_cnt), unsafe_allow_html=True)
|
377 |
# st.info('The model predicts that it achieves a {} of {}%'.format(target, str(round(output_rate*100,2))))
|
378 |
if target == 'conversion_rate':
|
|
|
380 |
else:
|
381 |
target_vis = 'Open_Rate'
|
382 |
|
383 |
+
st.markdown('#### The model predicts that it achieves a <span style="color:blue">{}</span> of <span style="color:blue">{}</span>%'.format(
|
384 |
target_vis, str(round(output_rate*100, 3))), unsafe_allow_html=True)
|
385 |
selected_industry_code = industry_code_dict.get(industry)
|
386 |
|
|
|
432 |
if selected_variable == "Click_Through_Rate":
|
433 |
selected_variable = "Conversion_Rate"
|
434 |
|
435 |
+
st.markdown('#### To get higher, <span style="color:blue">{}</span>, the model recommends the following options:'.format(
|
436 |
selected_variable), unsafe_allow_html=True)
|
437 |
if len(df_reco_opt_rank) == 0:
|
438 |
+
st.markdown('#### You ve already achieved the highest, <span style="color:blue">{}</span>, with the current character count!'.format(
|
439 |
selected_variable), unsafe_allow_html=True)
|
440 |
else:
|
441 |
#for _, row in df_reco_opt_rank.iterrows():
|
|
|
453 |
selected_variable_number = row[3]
|
454 |
chars.append(int(Character_Count))
|
455 |
sel_var_values.append(round(selected_variable_number, 3)*100)
|
456 |
+
st.write(f"·Number of Characters: {int(Character_Count)}, Target Rate: {round(round(selected_variable_number, 3)*100, 3)}", "%")
|
457 |
st.write("\n")
|
|
|
|
|
|
|
|
|
|
|
458 |
|
459 |
if len(chars) > 1:
|
460 |
#fig = plt.figure()
|
|
|
465 |
#ax.bar_label(bars)
|
466 |
|
467 |
ax.set_yticks(np.arange(len(chars)))
|
468 |
+
ax.set_yticklabels(np.array(chars), fontsize=14)
|
469 |
ax.set_title('Character Counts vs. Target Variable Rates', fontsize=18)
|
470 |
ax.set_ylabel('Character Counts', fontsize=16)
|
471 |
ax.set_xlabel('Target Rates %', fontsize=16)
|
|
|
482 |
st.plotly_chart(fig, use_container_width=True)
|
483 |
|
484 |
st.write("\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
#st.write(np.array(chars))
|
|
|
|
|
486 |
chars_out = dict(zip(chars, sel_var_values))
|
487 |
sorted_chars_out = sorted(chars_out.items(), key=lambda x: x[1], reverse=True)
|
488 |
|
489 |
|
490 |
placeholder.empty()
|
491 |
+
#st.write(time.time() - start_time)
|
492 |
+
|
main_app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(layout="wide")
|
4 |
+
|
5 |
+
st.markdown(
|
6 |
+
"""
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
background-image: linear-gradient(#2e7bcf,#2e7bcf);
|
10 |
+
color: white;
|
11 |
+
}
|
12 |
+
</style>
|
13 |
+
""",
|
14 |
+
unsafe_allow_html=True,
|
15 |
+
)
|
requirements.txt
CHANGED
@@ -1,18 +1,11 @@
|
|
1 |
-
|
2 |
-
# torch
|
3 |
-
streamlit
|
4 |
-
altair<5
|
5 |
-
pickle5
|
6 |
-
numpy
|
7 |
-
pandas
|
8 |
-
scikit-learn==0.24.1
|
9 |
-
Cython==0.29.36
|
10 |
-
bokeh==2.4.3
|
11 |
joblib
|
12 |
boto3
|
|
|
13 |
urlextract
|
|
|
14 |
bs4
|
15 |
matplotlib
|
|
|
16 |
plotly
|
17 |
-
streamlit==1.
|
18 |
-
openai==0.8.0
|
|
|
1 |
+
bokeh==2.4.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
joblib
|
3 |
boto3
|
4 |
+
pandas
|
5 |
urlextract
|
6 |
+
scikit-learn==0.24.1
|
7 |
bs4
|
8 |
matplotlib
|
9 |
+
numpy
|
10 |
plotly
|
11 |
+
streamlit==1.21.0
|
|