cd14 commited on
Commit
4f60771
1 Parent(s): af5e40b

adding gen ai support

Browse files
Files changed (4) hide show
  1. app.py +21 -4
  2. config.py +22 -0
  3. requirements.txt +2 -1
  4. utils.py +56 -0
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
@@ -18,7 +20,6 @@ import os
18
  #from ipyfilechooser import FileChooser
19
 
20
  #from IPython.display import display
21
- from io import BytesIO
22
  from bs4 import BeautifulSoup
23
  import matplotlib.pyplot as plt
24
  import numpy as np
@@ -478,7 +479,7 @@ if st.button('Generate Predictions'):
478
  #ax.bar_label(bars)
479
 
480
  ax.set_yticks(np.arange(len(chars)))
481
- ax.set_yticklabels(tuple([str(x) for x in chars]), fontsize=14)
482
  ax.set_title('Character Counts vs. Target Variable Rates', fontsize=18)
483
  ax.set_ylabel('Character Counts', fontsize=16)
484
  ax.set_xlabel('Target Rates %', fontsize=16)
@@ -495,9 +496,25 @@ if st.button('Generate Predictions'):
495
  st.plotly_chart(fig, use_container_width=True)
496
 
497
  st.write("\n")
 
 
498
  #st.write(np.array(chars))
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
 
502
 
503
  placeholder.empty()
 
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
 
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
 
479
  #ax.bar_label(bars)
480
 
481
  ax.set_yticks(np.arange(len(chars)))
482
+ ax.set_yticklabels(tuple(chars), fontsize=14)
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
  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
  #st.write(np.array(chars))
502
+ prefrence_variables=res=["charcter counts: "+str(x)+", Target Rate: "+str(y) for x,y in zip(chars,sel_var_values)]
503
+ preference = st.selectbox(
504
+ 'Please select your preferences',
505
+ prefrence_variables,
506
+ index=1
507
+ )
508
+ for x in sel_var_values:
509
+ if str(x) in preference:
510
+ pref_cc=x
511
+ ai_generated_email=generate_example_email_with_context(email_body, campaign, industry, target, sorted_chars_out, pref_cc)
512
+ st.markdown('##### Here is the recommended Generated Email for you:')
513
+ st.markdown('####### {}:'.format(ai_generated_email),unsafe_allow_html=True)
514
+
515
+
516
+ # chars_out = dict(zip(chars, sel_var_values))
517
+ # sorted_chars_out = sorted(chars_out.items(), key=lambda x: x[1], reverse=True)
518
 
519
 
520
  placeholder.empty()
config.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ Configurations
3
+ '''
4
+ 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'
12
+ TRAINING_DATA_S3PATH='s3://emailcampaigntrainingdata/trainingdata'
13
+ MODEL_FILE_NAME='modelCC.sav'
14
+ MODEL_ALLOCATION_PREFIX='sagemakermodelcc'
15
+ MODEL_BUCKET_NAME='sagemakermodelcc'
16
+ DATASET_TRAINING='email_dataset_training'
17
+ DATASET_TRAINING_RAW='email_dataset_training_raw'
18
+ MODELCC_TRAINING_DATA='training.csv'
19
+ MODELCC_TEST_DATA='Xtest.csv'
20
+ MODELCC_TEST_LABEL='ytest.csv'
21
+
22
+ config=Config()
requirements.txt CHANGED
@@ -14,4 +14,5 @@ urlextract
14
  bs4
15
  matplotlib
16
  plotly
17
- streamlit==1.25.0
 
 
14
  bs4
15
  matplotlib
16
  plotly
17
+ streamlit==1.25.0
18
+ openai==0.8.0
utils.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ from io import BytesIO
3
+ from config import config
4
+
5
+
6
+ def ask_chat_gpt(prompt, model=config.OPENAI_MODEL_TYPE, temp=0, max_tokens=500):
7
+ response = openai.Completion.create(
8
+ engine=model,
9
+ prompt=prompt,
10
+ max_tokens=max_tokens,
11
+ stop=None,
12
+ temperature=temp,
13
+ )
14
+ message = response.choices[0].text
15
+ return message.strip()
16
+
17
+ def chat_gpt_user_input_loop():
18
+ prompt = "Ask me anything on regarding email optimization. "
19
+ user_input = input(prompt)
20
+ response = ask_chat_gpt(prompt + user_input)
21
+ chat_gpt_user_input_loop()
22
+
23
+
24
+ def generate_example_email_with_context(email_body, selected_campaign_type, selected_industry, selected_variable, chars_out, dropdown_cc):
25
+ if len(chars_out) == 1:
26
+ if str(chars_out[0][0]) in dropdown_cc:
27
+ generate_email_prompt = "Rewrite this email keeping relevant information (people, date, location): " + email_body + "." "Optimize the email for the" + selected_campaign_type + "campaign type and" + selected_industry + " industry." + "The email body should be around" + str(chars_out[0][0]+200) + "characters in length."
28
+ generate_email_response = ask_chat_gpt(generate_email_prompt, temp=config.OPENAI_MODEL_TEMP, max_tokens=chars_out[0][0] + 200)
29
+ return generate_email_response
30
+
31
+ if len(chars_out) == 2:
32
+ if str(chars_out[0][0]) in dropdown_cc:
33
+ generate_email_prompt = "Rewrite this email keeping relevant information (people, date, location): " + email_body + "." "Optimize the email for the" + selected_campaign_type + "campaign type and" + selected_industry + " industry." + "The email body should be around" + str(chars_out[0][0]+200) + "characters in length."
34
+ generate_email_response = ask_chat_gpt(generate_email_prompt, temp=config.OPENAI_MODEL_TEMP, max_tokens=chars_out[0][0] + 200)
35
+ return generate_email_response
36
+
37
+ if str(chars_out[1][0]) in dropdown_cc:
38
+ generate_email_prompt = "Rewrite this email keeping relevant information (people, date, location): " + email_body + "." "Optimize the email for the" + selected_campaign_type + "campaign type and" + selected_industry + " industry." + "The email body should be around" + str(chars_out[1][0]+200) + "characters in length." + "Add more information and description as needed."
39
+ generate_email_response = ask_chat_gpt(generate_email_prompt, temp=config.OPENAI_MODEL_TEMP, max_tokens=chars_out[1][0] + 200)
40
+ return generate_email_response
41
+
42
+ if len(chars_out) == 3:
43
+ if str(chars_out[0][0]) in dropdown_cc:
44
+ generate_email_prompt = "Rewrite this email keeping relevant information (people, date, location): " + email_body + "." "Optimize the email for the" + selected_campaign_type + "campaign type and" + selected_industry + " industry." + "The email body should be around" + str(chars_out[0][0]+200) + "characters in length."
45
+ generate_email_response = ask_chat_gpt(generate_email_prompt, temp=config.OPENAI_MODEL_TEMP, max_tokens=chars_out[0][0] + 200)
46
+ return generate_email_response
47
+
48
+ if str(chars_out[1][0]) in dropdown_cc:
49
+ generate_email_prompt = "Rewrite this email keeping relevant information (people, date, location): " + email_body + "." "Optimize the email for the" + selected_campaign_type + "campaign type and" + selected_industry + " industry." + "The email body should be around" + str(chars_out[1][0]+200) + "characters in length." + "Add more information and description as needed."
50
+ generate_email_response = ask_chat_gpt(generate_email_prompt, temp=config.OPENAI_MODEL_TEMP, max_tokens=chars_out[1][0] + 200)
51
+ return generate_email_response
52
+
53
+ if str(chars_out[2][0]) in dropdown_cc:
54
+ generate_email_prompt = "Rewrite this email keeping relevant information (people, date, location): " + email_body + "." "Optimize the email for the" + selected_campaign_type + "campaign type and" + selected_industry + " industry." + "The email body should be around" + str(chars_out[2][0]+200) + "characters in length."
55
+ generate_email_response = ask_chat_gpt(generate_email_prompt, temp=config.OPENAI_MODEL_TEMP, max_tokens=chars_out[2][0] + 200)
56
+ return generate_email_response