from random import choice import streamlit as st import openai PROMPT_TEMPLATE = "Write a {tone} email to the customers of a {company_type} offering {offer}" VOICE_TONE_OPTIONS = "funny,formal,professional,informal,friendly,humorous," \ "serious,optimistic,motivating,respectful,assertive," \ "conversational,urgent".split(",") COMPANY_TYPE_OPTIONS = "bank,insurance,telecommunications (telco),retail,transportation".split(",") # "pharmaceutical,energy,automotive,real estate,technology," \ # "hospitality,food and beverage,healthcare,manufacturing,construction," \ # "mining,agriculture,e-commerce,entertainment," \ # "consulting services,accounting services,legal services".split(",") EXAMPLE_OFFERS = { "bank": [ "Checking Accounts that allows customers to deposit and withdraw funds, write checks, and make electronic transactions", "Savings Accounts, where customers can deposit money and earn interest on their savings", "Certificates of Deposit, a type of savings account where customers deposit money for a fixed term and earn a higher rate of interest", "Personal Loans, a loan offered to individuals for personal use, such as home improvement, debt consolidation, or medical expenses", "Home Loans, a loan for the purpose of purchasing or refinancing a home", ], "insurance": [ "Auto Insurance: A type of insurance policy that provides coverage for losses related to an individual's car, including liability, collision, and comprehensive coverage", "Home Insurance: A type of insurance policy that provides coverage for losses related to an individual's home, including protection for the structure, personal belongings, and liability coverage", "Life Insurance: A type of insurance policy that provides financial protection to an individual's family in the event of their death", "Health Insurance: A type of insurance policy that provides coverage for medical expenses and treatments, including doctor visits, hospital stays, and prescription drugs", "Business Insurance: A type of insurance policy that provides coverage for losses related to a business, including liability, property, and workers' compensation coverage", ], "telecommunications (telco)": [ "Postpaid Plan: A postpaid plan provides customers with a monthly bill for services used. The customer typically receives a set amount of data, minutes, and texts for a fixed price, with the option to add extra services for an additional fee", "Prepaid Plan: A prepaid plan allows customers to pay for services in advance, before they use them. The customer adds credit to their account, which is then deducted for each call, text, or data usage", "Family Plan: A family plan allows multiple users to share a single account, pooling their data, minutes, and texts. This type of plan is often more cost-effective than individual plans and is popular with families or groups of friends", "Unlimited Plan: An unlimited plan provides customers with unlimited data, minutes, and texts for a fixed monthly fee. These plans are attractive to customers who use their mobile devices frequently and need a lot of data", "Roaming Plan: A roaming plan provides customers with the ability to use their mobile devices while traveling abroad. The customer pays a fee for each day they use their device, and is provided with a set amount of data, minutes, and texts while they are overseas", ], "retail": [ "Buy one, get one free: Customers can purchase one product and receive a second product of equal or lesser value for free", "Limited-time discount: A temporary reduction in price for a specific product or product line, designed to encourage customers to make a purchase quickly", "Bundled offer: A package deal that combines multiple products or services at a discounted price, often as a way to promote complementary products", "Loyalty program: A reward system that incentivizes customers to continue making purchases by offering points, coupons, or other benefits for their spending", "Free gift with purchase: Customers receive a complimentary item when they make a purchase, often to promote new products or drive sales of slower-moving inventory.", ], "transportation": [ "Express Delivery Service - This offer would be ideal for customers who need to have their packages delivered quickly and with a guaranteed delivery time. This could be done through the use of priority shipping, courier services, and specialized delivery vehicles", "Freight Shipping - This offer would target customers who need to transport large quantities of goods over long distances. The company would provide the necessary resources, such as shipping containers, trailers, and trucks, to safely transport the goods from point A to point B", "Logistics Solutions - This offer would provide customers with a comprehensive set of services for managing their supply chain. This could include warehousing, inventory management, and order fulfillment services, among others", "Shuttle Services - This offer would target customers who need to transport groups of people from one location to another, such as airport transfers, school trips, and group tours. The company would provide the necessary vehicles and drivers to safely transport the passengers", "Last-Mile Delivery - This offer would be ideal for customers who need to have their packages delivered directly to the end customer. This could be done through the use of delivery vehicles, bicycles, and even drones, depending on the needs of the customer", ] } openai.api_key = st.secrets["openai-api-key"] def generate_email(prompt: str, max_tokens: int = 256) -> str: """ Returns a generated an email using GPT3 with a certain prompt and starting sentence """ completions = openai.Completion.create( model="text-davinci-003", prompt=prompt, temperature=0.7, max_tokens=max_tokens, top_p=1, frequency_penalty=0, presence_penalty=0 ) message = completions.choices[0].text return message def company_type_changed(): company_type = st.session_state['company_type'] st.session_state['offer'] = choice(EXAMPLE_OFFERS.get(company_type)) def main(): st.title("Email Generator") st.text("by Marc Puig") st.sidebar.markdown("### :arrow_right: Parameters") email_tone = st.sidebar.selectbox( label="Email voice tone", options=(sorted(VOICE_TONE_OPTIONS)) ), email_company_type = st.sidebar.selectbox( label="Company type", key="company_type", options=(sorted(COMPANY_TYPE_OPTIONS)), on_change=company_type_changed, ) if 'offer' not in st.session_state: st.session_state['offer'] = choice(EXAMPLE_OFFERS.get(email_company_type)) email_offer = st.sidebar.text_area( label="Offer description", key="offer", value=st.session_state['offer'], height=200, ) email_include_emojis = st.sidebar.checkbox('Include emojis 🤩') prompt_input = None if email_tone and email_company_type and email_offer: prompt_input = PROMPT_TEMPLATE.format(tone=email_tone, company_type=email_company_type, offer=email_offer) if email_include_emojis: prompt_input = prompt_input + ", including emojis" max_tokens_input = st.slider( label="How many characters do you want your email to be? ", help="A typical email is usually 100-500 characters", min_value=64, max_value=400, value=200 ) with st.form(key="form"): if st.form_submit_button(label='Generate email', disabled=prompt_input is None or len(prompt_input) == 0): with st.spinner("Generating email..."): output = generate_email(prompt_input, max_tokens=max_tokens_input) st.markdown("----") st.markdown(output) if __name__ == "__main__": main()