Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import openai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
openai.api_key = os.getenv("openapikey")
|
| 8 |
+
|
| 9 |
+
def generate_email(relation, context):
|
| 10 |
+
messages = [
|
| 11 |
+
{"role": "system", "content": "You are a professional email writer. Create clear and concise emails based on relation and context."},
|
| 12 |
+
{"role": "user", "content": f"Write an email with the following relation: {relation} and context: {context}."}
|
| 13 |
+
]
|
| 14 |
+
try:
|
| 15 |
+
response = openai.chat.completions.create(
|
| 16 |
+
model="gpt-3.5-turbo", # Or another suitable chat model
|
| 17 |
+
messages=messages,
|
| 18 |
+
max_tokens=300
|
| 19 |
+
)
|
| 20 |
+
return response.choices[0].message.content.strip()
|
| 21 |
+
except openai.OpenAIError as e:
|
| 22 |
+
return f"An error occurred: {e}"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
st.title("Email Generator")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
url='https://tse4.mm.bing.net/th?id=OIP.BdvrOOYHCuegoiraAC3sAAHaDt&pid=Api&P=0&h=180'
|
| 29 |
+
st.image(url,width=1000,)
|
| 30 |
+
st.markdown(f"""
|
| 31 |
+
<style>
|
| 32 |
+
/* Set the background image for the entire app */
|
| 33 |
+
.stApp {{
|
| 34 |
+
background-color: #708090;
|
| 35 |
+
background-size: 100px;
|
| 36 |
+
background-repeat:no;
|
| 37 |
+
background-attachment: auto;
|
| 38 |
+
background-position:center;
|
| 39 |
+
}}
|
| 40 |
+
</style>
|
| 41 |
+
""", unsafe_allow_html=True)
|
| 42 |
+
|
| 43 |
+
relation = st.selectbox("Please select the type of Relation ",options=["Colleague", "Friend"," Client"])
|
| 44 |
+
context = st.text_input("Context (e.g., Meeting Request, Follow-up, Thank You):")
|
| 45 |
+
if relation and context:
|
| 46 |
+
email = generate_email(relation, context)
|
| 47 |
+
st.write(email)
|