heysho commited on
Commit
ef4e6a3
β€’
1 Parent(s): 8500333

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import traceback
2
+ import streamlit as st
3
+ from langchain_core.prompts import ChatPromptTemplate
4
+ from langchain_core.output_parsers import StrOutputParser
5
+ from langchain_openai import ChatOpenAI
6
+ from langchain_anthropic import ChatAnthropic
7
+ from langchain_google_genai import ChatGoogleGenerativeAI
8
+
9
+ ###### dotenv γ‚’εˆ©η”¨γ™γ‚‹ε ΄εˆ ######
10
+ try:
11
+ from dotenv import load_dotenv
12
+ load_dotenv()
13
+ except ImportError:
14
+ import warnings
15
+ warnings.warn("dotenv not found. Please make sure to set your environment variables manually.", ImportWarning)
16
+ ################################################
17
+
18
+
19
+ PROMPT = """
20
+ You are an AI language model that helps users generate email replies. Given the context of an email conversation, you will create a well-structured, appropriate response based on the provided inputs. The response should match the specified tone and length.
21
+
22
+ Input:
23
+ 1. Sender: The person sending the email (e.g., boss, client, etc.)
24
+ 2. Email Subject: The subject of the email (e.g., About scheduling a meeting)
25
+ 3. Email Message: The content of the sender's email (e.g., I would like to adjust the time for tomorrow's meeting, are you available in the afternoon?)
26
+ 4. What you want to say: The desired response (e.g., I am available after 2 PM.)
27
+ 5. Length: The desired length of the response (e.g., Within 100 characters)
28
+
29
+ Output:
30
+ Generate a reply that addresses the sender's message, incorporates the user's desired response, and maintains a professional tone.
31
+
32
+ Examples:
33
+ Sender: Client
34
+ Email Subject: About scheduling a meeting
35
+ Email Message: I would like to adjust the time for tomorrow's meeting, are you available in the afternoon?
36
+ What you want to say: I am available after 2 PM.
37
+ Length: 100 characters
38
+ Generated Reply: Dear [Client's Name], Thank you for reaching out. I am available after 2 PM tomorrow for the meeting. Please let me know if this time works for you. Best regards, [Your Name]
39
+
40
+ Please generate a reply based on the provided inputs.
41
+ ---
42
+ - Sender: {sender},
43
+ - Email Subject : {subject},
44
+ - Content of the recipient's email:{message},
45
+ - What you want to say:{reply},
46
+ ---
47
+ """
48
+
49
+ def init_page():
50
+ st.set_page_config(
51
+ page_title="Email Reply AI Agent",
52
+ page_icon="βœ‰οΈ"
53
+ )
54
+ st.header("Email Reply AI Agent βœ‰οΈ")
55
+
56
+
57
+ def select_model(temperature=0):
58
+ models = ("GPT-4o","GPT-4o-mini", "Claude 3.5 Sonnet", "Gemini 1.5 Pro")
59
+ model_choice = st.radio("Choose a model:", models)
60
+ if model_choice == "GPT-4o":
61
+ return ChatOpenAI(temperature=temperature, model_name="gpt-4o")
62
+ elif model_choice == "GPT-4o-mini":
63
+ return ChatOpenAI(temperature=temperature, model_name="gpt-4o-mini")
64
+ elif model_choice == "Claude 3.5 Sonnet":
65
+ return ChatAnthropic(temperature=temperature, model_name="claude-3-5-sonnet-20240620")
66
+ elif model_choice == "Gemini 1.5 Pro":
67
+ return ChatGoogleGenerativeAI(temperature=temperature, model="gemini-1.5-pro-latest")
68
+
69
+ def init_chain():
70
+ llm = select_model()
71
+ prompt = ChatPromptTemplate.from_messages([
72
+ ("user", PROMPT),
73
+ ])
74
+ output_parser = StrOutputParser()
75
+ chain = prompt | llm | output_parser
76
+ return chain
77
+
78
+ def main():
79
+ init_page()
80
+ chain = init_chain()
81
+ if chain:
82
+ sender = st.selectbox("Sender",("Co-worker", "Boss", "Client", "Friend"),key="sender")
83
+ subject = st.text_input("Email Subject (e.g., About scheduling a meeting)", key="subject")
84
+ message = st.text_area("Content of the recipient's email: (e.g., I would like to adjust the time for tomorrow's meeting, are you available in the afternoon?)", key="message")
85
+ reply = st.text_input("What you want to say: (e.g., I am available after 2 PM.)", key="reply")
86
+ if st.button("θΏ”δΏ‘γ‚’η”Ÿζˆγ™γ‚‹"):
87
+ result = chain.stream({"sender": sender, "subject": subject, "message": message, "reply": reply})
88
+ st.write(result)
89
+
90
+
91
+ if __name__ == '__main__':
92
+ main()
93
+
94
+ # Style adjustments (optional, remove if not needed)
95
+ st.markdown(
96
+ """
97
+ <style>
98
+ /* Custom style adjustments */
99
+ .st-emotion-cache-iiif1v { display: none !important; }
100
+ </style>
101
+ """,
102
+ unsafe_allow_html=True,
103
+ )