shukdevdatta123 commited on
Commit
33b4f25
·
verified ·
1 Parent(s): fb0d0ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import streamlit as st
3
+
4
+ # Function to call the OpenAI API and get the email content
5
+ def generate_email(api_key, email_type, details):
6
+ openai.api_key = api_key # Set OpenAI API key provided by the user
7
+
8
+ prompt = f"""
9
+ I need to write a professional email for the following situation:
10
+ Email Type: {email_type}
11
+ Details: {details}
12
+ Please generate the body of the email, including suggestions for the subject line and sign-off. Ensure the email tone is professional and polite.
13
+ """
14
+
15
+ try:
16
+ # Request to OpenAI API
17
+ response = openai.Completion.create(
18
+ engine="o3-mini", # Using OpenAI's GPT-3 model (adjust for specific LLM as needed)
19
+ prompt=prompt,
20
+ max_tokens=1200,
21
+ temperature=0.7
22
+ )
23
+
24
+ # Return the generated email content
25
+ return response.choices[0].text.strip()
26
+ except Exception as e:
27
+ return f"Error: {str(e)}"
28
+
29
+ # Streamlit app
30
+ def email_composer():
31
+ st.title("Automated Email Composer")
32
+ st.write("This tool helps you generate professional emails, improve tone and grammar, and suggest appropriate subject lines and sign-offs.")
33
+
34
+ # Step 1: Enter OpenAI API key
35
+ api_key = st.text_input("Enter your OpenAI API Key", type="password")
36
+
37
+ # Step 2: Select email type
38
+ email_type = st.selectbox(
39
+ "Select Email Type",
40
+ ["Request for Information", "Follow-Up", "Introduction", "Complaint", "Thank You", "Job Application", "Meeting Request", "Others"]
41
+ )
42
+
43
+ # Step 3: Enter email details
44
+ details = st.text_area("Enter Email Details", "Please provide the necessary details for the email.")
45
+
46
+ # Step 4: Generate email button
47
+ if st.button("Generate Email"):
48
+ if api_key and details:
49
+ with st.spinner("Generating email..."):
50
+ # Call the generate_email function to get the email content
51
+ email_content = generate_email(api_key, email_type, details)
52
+ st.subheader("Generated Email")
53
+ st.write(email_content)
54
+ else:
55
+ if not api_key:
56
+ st.error("Please enter your OpenAI API key.")
57
+ if not details:
58
+ st.error("Please enter the email details to generate the email.")
59
+
60
+ # Run the Streamlit app
61
+ if __name__ == "__main__":
62
+ email_composer()