Spaces:
Sleeping
Sleeping
| 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) |