import streamlit as st import os from groq import Groq client = Groq( api_key=os.environ.get("GROQ_API_KEY"), ) # -- page config st.set_page_config( page_title="TailorMail", page_icon="📧", layout="centered", initial_sidebar_state="collapsed", ) # -- hiding the sidebar st.markdown( """ """, unsafe_allow_html=True, ) # variable to check button status if 'access' not in st.session_state: st.session_state.access = False if 'conversation_history' not in st.session_state: st.session_state.conversation_history = [] system_prompt = {"role": "system", "content": "You are an expert at writing personalized emails. Your task is to write a personalized email in a mail format given some details of the email like recipient details, sender details, reason of email and some other attributes of mail. And make changes based on user's follow up requests."} # welcome page def welcome_page(): # -- page title st.markdown( "

Welcome to TailorMail📧

", unsafe_allow_html=True ) st.markdown( "
Personalize Your Emails with Ease
", unsafe_allow_html=True, ) # -- adding space b/w texts st.title("\n\n") button_style = """ """ cols = st.columns((1,3,1)) with cols[1]: access_button = st.button("Access the tool", type = "primary", use_container_width=True) if access_button: st.session_state['access'] = True st.rerun() # This can be replaced with navigation to the main tool interface def generate_user_prompt(recipient_name, recipient_role, company_name, sender_name, sender_role, sender_contact, sender_company, email_reason, specific_details, language, tone_style, cta_outcome, attachment_info, additional_instructions): prompt = f"""Instructions to draft the mail: 1. Understand the details about recipient, sender and other attributes of email like reason, tone, language, etc. 2. The subject of the mail will not be provided to you, so once you understand the reason and other details about the mail, create a good subject for the mail that meets the user requirements and is in aligned with the details mentioned. 3. The output returned need to be of the email format and not as one big long paragraph. 4. Do add greetings based on the type of the mail. IMPORTANT: User might not provide us with some these details : recipient_role, company_name, sender_role, sender_contact, sender_company, specific_details, cta_outcome, attachment_info, additional_instructions. So in that case don't interpret things and add up on your own. You need to generate content based on the content user has provided and ignore the fields which user has left blank (empty string). Also, don't show variable names in the response, use the names and details which are provided and leave the ones which are blank or empty strings. Make sure to not add any extra commentary in the output other than the complete mail. And avoid using special symbols like * etc on the places where its not required. Here are the details of the email provided by the user. Use these details to draft a mail, remember some of these could be empty strings: Recipient Name : {recipient_name}, Recipient Role: {recipient_role}, Recipient Company Name: {company_name}, Sender Name: {sender_name}, Sender Role: {sender_role}, Sender Contact: {sender_contact}, Sender Company: {sender_company}, Reason of writing the mail: {email_reason}, Specific details about the mail, if any: {specific_details}, Formality Type: {language}, Tone of the mail: {tone_style}, Call to action, if any: {cta_outcome}, Information about the file or document attached, if any: {attachment_info}, These are some special instructions from the user that we need to consider while drafting the mail: {additional_instructions}""" return prompt def generate_response(user_prompt, model, temperature, tokens): messages = st.session_state.conversation_history + [{"role": "user", "content": user_prompt}] if model=='Mistral': model = 'mixtral-8x7b-32768' else: model = 'llama-3.1-8b-instant' chat_completion = client.chat.completions.create( messages=messages, model= model, temperature = temperature, max_tokens = tokens ) response = chat_completion.choices[0].message.content # Append the assistant's response to the conversation history st.session_state.conversation_history.append({"role": "assistant", "content": response}) return response def run_email_tool(st): # Apply custom CSS to style the Streamlit app st.markdown( """ """, unsafe_allow_html=True ) # UI Title st.markdown("

TailorMail📧

", unsafe_allow_html=True) # Section 1: Recipient Information st.markdown("

Recipient Information

", unsafe_allow_html=True) # Recipient's Name Field st.markdown("""
Recipient's Name (Required)
""", unsafe_allow_html=True) recipient_name = st.text_input("", placeholder="e.g., John Doe", key="recipient_name", label_visibility="collapsed") # Add a small margin between the input field and the next heading st.markdown("
", unsafe_allow_html=True) # Recipient's Job Title/Role Field st.markdown("""
Recipient's Job Title/Role (Optional)
""", unsafe_allow_html=True) recipient_role = st.text_input("", placeholder="e.g., Marketing Manager", key="recipient_role", label_visibility="collapsed") # Company Name Field st.markdown("""
Company Name (Optional)
""", unsafe_allow_html=True) company_name = st.text_input("", placeholder="e.g., ABC Corporation", label_visibility="collapsed") # Section 2: Sender Information st.markdown("

Sender Information

", unsafe_allow_html=True) # Sender's Name Field st.markdown("""
Sender's Name (Required)
""", unsafe_allow_html=True) sender_name = st.text_input("", placeholder="e.g., Jane Smith", label_visibility="collapsed") # Sender's Job Title Field st.markdown("""
Sender's Job Title (Optional)
""", unsafe_allow_html=True) sender_role = st.text_input("", placeholder="e.g., Project Lead", label_visibility="collapsed") # Sender's Contact Information Field st.markdown("""
Sender's Contact Information (Optional)
""", unsafe_allow_html=True) sender_contact = st.text_input("", placeholder="Enter your mail or mobile number", label_visibility="collapsed") # Sender's Company Name/Organization Field st.markdown("""
Company Name/Organization (Optional)
""", unsafe_allow_html=True) sender_company = st.text_input("", placeholder="e.g., XYZ Ltd.", label_visibility="collapsed") # Section 3: Purpose of the Email st.markdown("

Purpose of the Email

", unsafe_allow_html=True) # Reason for the Email Field st.markdown("""
Reason for the Email (Required)
""", unsafe_allow_html=True) email_reason = st.text_area("", placeholder="e.g., I want to discuss the project updates", label_visibility="collapsed") # Specific Details Field st.markdown("""
Specific Details (Optional)
""", unsafe_allow_html=True) specific_details = st.text_area("", placeholder="Enter any specific details that you would like to mention e.g., Provide an update on the project status...", label_visibility="collapsed") # Section 4: Tone of the Email st.markdown("

Tone of the Email

", unsafe_allow_html=True) # CSS to make radio button options appear side by side st.markdown( """