|
import openai |
|
import streamlit as st |
|
|
|
|
|
def generate_email(api_key, email_type, details): |
|
openai.api_key = api_key |
|
|
|
prompt = f""" |
|
I need to write a professional email for the following situation: |
|
Email Type: {email_type} |
|
Details: {details} |
|
Please generate the body of the email, including suggestions for the subject line and sign-off. Ensure the email tone is professional and polite. |
|
""" |
|
|
|
try: |
|
|
|
response = openai.Completion.create( |
|
engine="gpt-4o", |
|
prompt=prompt, |
|
max_tokens=1200, |
|
temperature=0.7 |
|
) |
|
|
|
|
|
return response.choices[0].text.strip() |
|
except Exception as e: |
|
return f"Error: {str(e)}" |
|
|
|
|
|
def email_composer(): |
|
st.title("Automated Email Composer") |
|
st.write("This tool helps you generate professional emails, improve tone and grammar, and suggest appropriate subject lines and sign-offs.") |
|
|
|
|
|
api_key = st.text_input("Enter your OpenAI API Key", type="password") |
|
|
|
|
|
email_type = st.selectbox( |
|
"Select Email Type", |
|
["Request for Information", "Follow-Up", "Introduction", "Complaint", "Thank You", "Job Application", "Meeting Request", "Others"] |
|
) |
|
|
|
|
|
details = st.text_area("Enter Email Details", "Please provide the necessary details for the email.") |
|
|
|
|
|
if st.button("Generate Email"): |
|
if api_key and details: |
|
with st.spinner("Generating email..."): |
|
|
|
email_content = generate_email(api_key, email_type, details) |
|
st.subheader("Generated Email") |
|
st.write(email_content) |
|
else: |
|
if not api_key: |
|
st.error("Please enter your OpenAI API key.") |
|
if not details: |
|
st.error("Please enter the email details to generate the email.") |
|
|
|
|
|
if __name__ == "__main__": |
|
email_composer() |
|
|