usernameiskheejay commited on
Commit
59393cb
·
1 Parent(s): 0ffc5f4

email generator

Browse files
Files changed (2) hide show
  1. app.py +62 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from openai import OpenAI
3
+
4
+ # Initialize the NVIDIA model
5
+ client = OpenAI(
6
+ base_url="https://integrate.api.nvidia.com/v1",
7
+ api_key="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" # Replace with your actual API key
8
+ )
9
+
10
+ # Streamlit App Layout
11
+ st.title("Personalized Email Drafting Tool")
12
+ st.subheader("Generate professional emails effortlessly!")
13
+
14
+ # Input fields for user
15
+ st.sidebar.header("Email Preferences")
16
+ email_tone = st.sidebar.selectbox("Select the tone of your email:",
17
+ ["Professional", "Formal", "Casual", "Persuasive", "Friendly", "Angry"])
18
+ email_topic = st.text_input("Topic of the email", placeholder="e.g., Meeting reschedule")
19
+ email_points = st.text_area("Key points to include",
20
+ placeholder="e.g., Highlight urgency, request a response by Friday")
21
+
22
+ # Slider for temperature control (creativity level)
23
+ temperature = st.sidebar.slider("Set creativity level (temperature):", 0.0, 1.0, 0.5)
24
+
25
+ # Generate email button
26
+ if st.button("Generate Email"):
27
+ if email_topic and email_points:
28
+ # Display loading spinner
29
+ with st.spinner("Generating your email..."):
30
+ # Call NVIDIA's model
31
+ messages = [
32
+ {"role": "system", "content": f"Write an email with a {email_tone.lower()} tone."},
33
+ {"role": "user", "content": f"Topic: {email_topic}\nKey Points: {email_points}"}
34
+ ]
35
+ completion = client.chat.completions.create(
36
+ model="meta/llama-3.1-405b-instruct",
37
+ messages=messages,
38
+ temperature=temperature,
39
+ top_p=0.7,
40
+ max_tokens=512,
41
+ stream=True
42
+ )
43
+
44
+ # Placeholder for real-time streaming output
45
+ email_placeholder = st.empty()
46
+ email_output = "" # To accumulate content
47
+
48
+ for chunk in completion:
49
+ if chunk.choices[0].delta.content is not None:
50
+ email_output += chunk.choices[0].delta.content
51
+ email_placeholder.text(email_output) # Update the same placeholder
52
+
53
+ # Store the generated email in session state to persist across button clicks
54
+ if email_output:
55
+ st.session_state.generated_email = email_output # Store in session state
56
+
57
+ else:
58
+ st.warning("Please fill in both the topic and key points to generate an email.")
59
+
60
+ # If generated email exists in session state, display it
61
+ if 'generated_email' in st.session_state:
62
+ st.text_area("Generated Email", st.session_state.generated_email, height=300)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ streamlit