Chandan Dwivedi commited on
Commit
5dc6b6c
·
1 Parent(s): b0b3685

Added LLM support

Browse files
Files changed (6) hide show
  1. .DS_Store +0 -0
  2. README.md +2 -2
  3. app.py +56 -16
  4. config.py +1 -1
  5. main_app.py +0 -15
  6. requirements.txt +12 -5
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
README.md CHANGED
@@ -4,10 +4,10 @@ emoji: ✉️
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
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
4
  colorFrom: purple
5
  colorTo: yellow
6
  sdk: streamlit
7
+ sdk_version: 1.25.0
8
+ python_version: 3.9
9
  app_file: app.py
10
  pinned: false
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -7,6 +7,8 @@ from io import StringIO
7
  import boto3
8
  from urlextract import URLExtract
9
  import time
 
 
10
  # from joblib import dump, load
11
 
12
  import joblib
@@ -14,15 +16,18 @@ 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,7 +184,7 @@ def add_bg_from_url():
179
  f"""
180
  <style>
181
  .stApp {{
182
- background-image: linear-gradient(#45eff5,#1C8D99);
183
  background-attachment: fixed;
184
  background-size: cover
185
 
@@ -262,6 +267,10 @@ target_variables = [
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,7 +307,6 @@ st.markdown("""---""")
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
  """
@@ -317,12 +325,17 @@ def get_files_from_aws(bucket, prefix):
317
 
318
  # st.info([industry,campaign,target,char_reco_preference])
319
 
 
 
 
320
 
321
- if st.button('Generate Predictions'):
 
322
  start_time = time.time()
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,7 +385,7 @@ if st.button('Generate Predictions'):
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,7 +393,7 @@ if st.button('Generate Predictions'):
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,10 +445,10 @@ if st.button('Generate Predictions'):
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,8 +466,13 @@ if st.button('Generate Predictions'):
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,7 +483,7 @@ if st.button('Generate Predictions'):
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)
@@ -481,12 +499,34 @@ if st.button('Generate Predictions'):
481
 
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
 
 
 
 
 
 
 
 
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
  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
  f"""
185
  <style>
186
  .stApp {{
187
+ background-image: linear-gradient(135deg,#061c2c,#084e69 35%,#3e7e89);
188
  background-attachment: fixed;
189
  background-size: cover
190
 
 
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
  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
  """
 
325
 
326
  # st.info([industry,campaign,target,char_reco_preference])
327
 
328
+ act=st.button('Generate Predictions')
329
+ if st.session_state.get('button') != True:
330
+ st.session_state['button'] = act
331
 
332
+ # if act:
333
+ if st.session_state.get('button') == True:
334
  start_time = time.time()
335
  if uploaded_file is None:
336
  st.error('Please upload a email (HTML format)')
337
  else:
338
+ save_file(uploaded_file)
339
  placeholder = st.empty()
340
  placeholder.text('Loading Data')
341
 
 
385
  print(
386
  "Sorry, Current model couldn't provide predictions on the target variable you selected.")
387
  else:
388
+ st.markdown('##### Current Character Count in Your Email is: <span style="color:yellow">{}</span>'.format(
389
  character_cnt), unsafe_allow_html=True)
390
  # st.info('The model predicts that it achieves a {} of {}%'.format(target, str(round(output_rate*100,2))))
391
  if target == 'conversion_rate':
 
393
  else:
394
  target_vis = 'Open_Rate'
395
 
396
+ st.markdown('##### The model predicts that it achieves a <span style="color:yellow">{}</span> of <span style="color:yellow">{}</span>%'.format(
397
  target_vis, str(round(output_rate*100, 3))), unsafe_allow_html=True)
398
  selected_industry_code = industry_code_dict.get(industry)
399
 
 
445
  if selected_variable == "Click_Through_Rate":
446
  selected_variable = "Conversion_Rate"
447
 
448
+ st.markdown('##### To get higher, <span style="color:yellow">{}</span>, the model recommends the following options:'.format(
449
  selected_variable), unsafe_allow_html=True)
450
  if len(df_reco_opt_rank) == 0:
451
+ st.markdown('##### You ve already achieved the highest, <span style="color:yellow">{}</span>, with the current character count!'.format(
452
  selected_variable), unsafe_allow_html=True)
453
  else:
454
  #for _, row in df_reco_opt_rank.iterrows():
 
466
  selected_variable_number = row[3]
467
  chars.append(int(Character_Count))
468
  sel_var_values.append(round(selected_variable_number, 3)*100)
469
+ # st.write(f"·Number of Characters: {int(Character_Count)}, Target Rate: {round(round(selected_variable_number, 3)*100, 3)}", "%")
470
  st.write("\n")
471
+ df_modelpred=pd.DataFrame(list(zip(chars, sel_var_values)), columns=["Number of Characters", "Target_Rate"])
472
+ # st.checkbox("Use container width", value=False, key="use_container_width")
473
+ # st.dataframe(df_modelpred.style.highlight_max(axis=0), use_container_width=st.session_state.use_container_width)
474
+ df_modelpred.sort_values(by='Target_Rate', ascending=False, inplace = True)
475
+ st.dataframe(df_modelpred)
476
 
477
  if len(chars) > 1:
478
  #fig = plt.figure()
 
483
  #ax.bar_label(bars)
484
 
485
  ax.set_yticks(np.arange(len(chars)))
486
+ ax.set_yticklabels(tuple(chars), fontsize=14)
487
  ax.set_title('Character Counts vs. Target Variable Rates', fontsize=18)
488
  ax.set_ylabel('Character Counts', fontsize=16)
489
  ax.set_xlabel('Target Rates %', fontsize=16)
 
499
 
500
  st.plotly_chart(fig, use_container_width=True)
501
 
502
+ # st.write("\n")
503
+ chars_out = dict(zip(chars, sel_var_values))
504
+ sorted_chars_out = sorted(chars_out.items(), key=lambda x: x[1], reverse=True)
505
+ prefrence_variables=res=["charcter counts: "+str(x)+", Target Rate: "+str(y) for x,y in zip(chars,sel_var_values)]
506
+ preference = st.selectbox(
507
+ 'Please select your preferences',
508
+ prefrence_variables,
509
+ index=1
510
+ )
511
+ if st.button('Generate AI Recommended Email'):
512
+ if(preference is None):
513
+ st.error('Please upload a email (HTML format)')
514
+ else:
515
+ ai_generated_email=generate_example_email_with_context(email_body, campaign, industry, target, sorted_chars_out, preference)
516
+ st.markdown('##### Here is the recommended Generated Email for you:')
517
+ st.markdown('{}:'.format(ai_generated_email),unsafe_allow_html=True)
518
+ # st.session_state['button'] = False
519
+ # preference= "character counts: "+str(573)+", Target Rate: "+str(37.2)
520
+ # ai_generated_email=generate_example_email_with_context(email_body, campaign, industry, target, sorted_chars_out, preference)
521
+ # print("ai_generated_email: ",ai_generated_email)
522
+ # st.markdown('##### Here is the recommended Generated Email for you:')
523
+ # st.markdown('####### {}'.format(ai_generated_email),unsafe_allow_html=True)
524
  #st.write(np.array(chars))
 
 
 
525
 
 
 
526
 
527
+ # chars_out = dict(zip(chars, sel_var_values))
528
+ # sorted_chars_out = sorted(chars_out.items(), key=lambda x: x[1], reverse=True)
529
+
530
+
531
+ # placeholder.empty()
532
+ #st.write(time.time() - start_time)
config.py CHANGED
@@ -5,7 +5,7 @@ import os
5
  import argparse
6
 
7
  class Config(object):
8
- OPEN_API_KEY='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'
9
  OPENAI_MODEL_TYPE='text-davinci-003'
10
  OPENAI_MODEL_TEMP=0.3
11
  MODELCC_DATA_S3PATH='s3://emailcampaigntrainingdata/modelCC'
 
5
  import argparse
6
 
7
  class Config(object):
8
+ OPEN_API_KEY='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'
9
  OPENAI_MODEL_TYPE='text-davinci-003'
10
  OPENAI_MODEL_TEMP=0.3
11
  MODELCC_DATA_S3PATH='s3://emailcampaigntrainingdata/modelCC'
main_app.py DELETED
@@ -1,15 +0,0 @@
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,11 +1,18 @@
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
 
 
1
+ # transformers
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.25.0
18
+ openai==0.8.0