import streamlit as st import openai 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 TEMPLATE = "Write a {tone} email to the customers of a {company_type} offering {offer}" def main(): st.title("Email Generator") st.text("by Marc Puig") st.sidebar.markdown("### :arrow_right: Parameters") email_tone = st.sidebar.selectbox( label="tone", options=("funny", "formal", "professional", "informal", "friendly", "humorous", "serious", "optimistic", "motivating", "respectful", "assertive", "conversational", "urgent",) ), email_company_type = st.sidebar.selectbox( label="Company type", options=("telco company", "bank", "insurance") ) offer = st.sidebar.text_area( label="offer description", value="100 minutes free if they buy 1000 minutes" ) prompt_input = "lorem ipsum" if email_tone and email_company_type and offer: prompt_input = TEMPLATE.format(tone=email_tone, company_type=email_company_type, offer=offer) 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=750, value=200 ) with st.form(key="form"): if st.form_submit_button(label='Generate email', disabled=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()