Spaces:
Runtime error
Runtime error
adding rayan prompt
Browse files
app.py
CHANGED
|
@@ -2,9 +2,6 @@ from ast import arg
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import PIL
|
| 5 |
-
import re
|
| 6 |
-
from io import StringIO
|
| 7 |
-
import boto3
|
| 8 |
from urlextract import URLExtract
|
| 9 |
import time
|
| 10 |
from utils import *
|
|
@@ -304,24 +301,6 @@ st.markdown("""---""")
|
|
| 304 |
# index=1)
|
| 305 |
|
| 306 |
|
| 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 |
-
"""
|
| 313 |
-
s3_client = boto3.client('s3',
|
| 314 |
-
aws_access_key_id=st.secrets["aws_id"],
|
| 315 |
-
aws_secret_access_key=st.secrets["aws_key"])
|
| 316 |
-
|
| 317 |
-
file_obj = s3_client.get_object(Bucket=bucket, Key=prefix)
|
| 318 |
-
body = file_obj['Body']
|
| 319 |
-
string = body.read().decode('utf-8')
|
| 320 |
-
|
| 321 |
-
df = pd.read_csv(StringIO(string))
|
| 322 |
-
|
| 323 |
-
return df
|
| 324 |
-
|
| 325 |
|
| 326 |
# st.info([industry,campaign,target,char_reco_preference])
|
| 327 |
|
|
@@ -515,22 +494,22 @@ if st.session_state.get('button') == True:
|
|
| 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 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
|
| 535 |
# st.session_state['button'] = False
|
| 536 |
# preference= "character counts: "+str(573)+", Target Rate: "+str(37.2)
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import PIL
|
|
|
|
|
|
|
|
|
|
| 5 |
from urlextract import URLExtract
|
| 6 |
import time
|
| 7 |
from utils import *
|
|
|
|
| 301 |
# index=1)
|
| 302 |
|
| 303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
# st.info([industry,campaign,target,char_reco_preference])
|
| 306 |
|
|
|
|
| 494 |
ai_generated_email=generate_example_email_with_context(email_body, campaign, industry, target, sorted_chars_out, preference)
|
| 495 |
st.markdown('##### Here is the recommended Generated Email for you:')
|
| 496 |
st.markdown('{}:'.format(ai_generated_email),unsafe_allow_html=True)
|
| 497 |
+
options = st.multiselect(
|
| 498 |
+
'Select propmts you want to use to generate your email:',
|
| 499 |
+
["Convey key message in fewer words",
|
| 500 |
+
"Rephrase sentences to be more concise",
|
| 501 |
+
"Remove unnecessary details/repetitions",
|
| 502 |
+
"Use bullet points or numbered lists",
|
| 503 |
+
"Include clear call-to-action in the email",
|
| 504 |
+
"Link to information instead of writing it out",
|
| 505 |
+
"Shorten the subject line",
|
| 506 |
+
"Replace technical terms with simpler language"],
|
| 507 |
+
["Remove unnecessary details/repetitions"])
|
| 508 |
+
optimized_email, optimized_char_cnt, optimized_url_cnt = optimize_email_prompt_multi(email_body, options)
|
| 509 |
+
charc, tmval=get_optimized_prediction("sagemakermodelcc", "modelCC.sav", "sagemakermodelcc", target, industry,
|
| 510 |
+
optimized_char_cnt, optimized_url_cnt, industry_code_dict)
|
| 511 |
+
st.markdown('##### Current Character Count in Your Optimized Email is: {}'.format(charc), unsafe_allow_html=True)
|
| 512 |
+
st.markdown('##### The model predicts that it achieves a {} of {}%'.format(target,tmval), unsafe_allow_html=True)
|
| 513 |
|
| 514 |
# st.session_state['button'] = False
|
| 515 |
# preference= "character counts: "+str(573)+", Target Rate: "+str(37.2)
|
utils.py
CHANGED
|
@@ -1,6 +1,14 @@
|
|
| 1 |
import openai
|
| 2 |
from io import BytesIO
|
| 3 |
from config import config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
openai.api_key = config.OPEN_API_KEY
|
| 6 |
|
|
@@ -80,6 +88,27 @@ def optimize_email_prompt_multi(email_body, dropdown_opt):
|
|
| 80 |
# Return the character count and URL count
|
| 81 |
return generate_email_response, character_count, url_count
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
def get_optimized_prediction(modellocation, model_filename, bucket_name, selected_variable, selected_industry,
|
| 84 |
char_cnt_uploaded, url_cnt_uploaded, industry_code_dict): #preference, industry_code_dict):
|
| 85 |
training_dataset = import_data("s3://emailcampaigntrainingdata/modelCC", 'training.csv')
|
|
|
|
| 1 |
import openai
|
| 2 |
from io import BytesIO
|
| 3 |
from config import config
|
| 4 |
+
import re
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import random
|
| 7 |
+
import boto3
|
| 8 |
+
s3 = boto3.resource('s3')
|
| 9 |
+
from io import StringIO
|
| 10 |
+
import joblib
|
| 11 |
+
s3_client = boto3.client('s3')
|
| 12 |
|
| 13 |
openai.api_key = config.OPEN_API_KEY
|
| 14 |
|
|
|
|
| 88 |
# Return the character count and URL count
|
| 89 |
return generate_email_response, character_count, url_count
|
| 90 |
|
| 91 |
+
def import_data(bucket, key):
|
| 92 |
+
return get_files_from_aws(bucket, key)
|
| 93 |
+
|
| 94 |
+
def get_files_from_aws(bucket, prefix):
|
| 95 |
+
"""
|
| 96 |
+
get files from aws s3 bucket
|
| 97 |
+
bucket (STRING): bucket name
|
| 98 |
+
prefix (STRING): file location in s3 bucket
|
| 99 |
+
"""
|
| 100 |
+
s3_client = boto3.client('s3',
|
| 101 |
+
aws_access_key_id=st.secrets["aws_id"],
|
| 102 |
+
aws_secret_access_key=st.secrets["aws_key"])
|
| 103 |
+
|
| 104 |
+
file_obj = s3_client.get_object(Bucket=bucket, Key=prefix)
|
| 105 |
+
body = file_obj['Body']
|
| 106 |
+
string = body.read().decode('utf-8')
|
| 107 |
+
|
| 108 |
+
df = pd.read_csv(StringIO(string))
|
| 109 |
+
|
| 110 |
+
return df
|
| 111 |
+
|
| 112 |
def get_optimized_prediction(modellocation, model_filename, bucket_name, selected_variable, selected_industry,
|
| 113 |
char_cnt_uploaded, url_cnt_uploaded, industry_code_dict): #preference, industry_code_dict):
|
| 114 |
training_dataset = import_data("s3://emailcampaigntrainingdata/modelCC", 'training.csv')
|