File size: 1,478 Bytes
4dbd661
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st
import openai
import os



openai.api_key = os.getenv("openapikey")

def generate_email(relation, context):
    messages = [
        {"role": "system", "content": "You are a professional email writer. Create clear and concise emails based on relation and context."},
        {"role": "user", "content": f"Write an email with the following relation: {relation} and context: {context}."}
    ]
    try:
        response = openai.chat.completions.create(
            model="gpt-3.5-turbo",  # Or another suitable chat model
            messages=messages,
            max_tokens=300
        )
        return response.choices[0].message.content.strip()
    except openai.OpenAIError as e:
        return f"An error occurred: {e}"


st.title("Email Generator")


url='https://tse4.mm.bing.net/th?id=OIP.BdvrOOYHCuegoiraAC3sAAHaDt&pid=Api&P=0&h=180'
st.image(url,width=1000,)
st.markdown(f"""
<style>
    /* Set the background image for the entire app */
    .stApp {{
        background-color: #708090;
        background-size: 100px;
        background-repeat:no;
        background-attachment: auto;
        background-position:center;
    }}
</style>
""", unsafe_allow_html=True)

relation = st.selectbox("Please select the type of Relation ",options=["Colleague", "Friend"," Client"])
context = st.text_input("Context (e.g., Meeting Request, Follow-up, Thank You):")
if relation and context:
    email = generate_email(relation, context)
    st.write(email)