Spaces:
Sleeping
Sleeping
Second model version
Browse files- README.md +4 -4
- app.py +57 -0
- backend.py +26 -0
- lib/.DS_Store +0 -0
- lib/common/database_support.py +94 -0
- lib/support/generate_email_support.py +86 -0
- lib/support/template_email_support.py +145 -0
- lib/support/user_profile_support.py +44 -0
- llm.py +59 -0
- requirements.txt +6 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: pink
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
-
sdk_version: 1.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
1 |
---
|
2 |
+
title: Email Genie Part Two
|
3 |
+
emoji: 💻
|
4 |
colorFrom: pink
|
5 |
+
colorTo: pink
|
6 |
sdk: streamlit
|
7 |
+
sdk_version: 1.38.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import traceback
|
4 |
+
import backend
|
5 |
+
from lib.support.generate_email_support import render_gen_email
|
6 |
+
from lib.support.template_email_support import render_templates
|
7 |
+
from lib.support.user_profile_support import render_user_profile
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
st.set_page_config(page_title="Cold Email Generator", layout="wide")
|
13 |
+
|
14 |
+
# ------------------------------------- Custom CSS -------------------------------------------------------------
|
15 |
+
st.markdown(
|
16 |
+
"""
|
17 |
+
<style>
|
18 |
+
.css-1d391kg { /* Adjust this class based on your Streamlit version */
|
19 |
+
padding-left: 10px;
|
20 |
+
padding-right: 10px;
|
21 |
+
}
|
22 |
+
</style>
|
23 |
+
""",
|
24 |
+
unsafe_allow_html=True
|
25 |
+
)
|
26 |
+
# --------------------------------------------------------------------------------------------------
|
27 |
+
|
28 |
+
|
29 |
+
def main():
|
30 |
+
try:
|
31 |
+
|
32 |
+
if not st.session_state.get("excel_file"):
|
33 |
+
st.session_state.excel_file = "cold_email_data.xlsx"
|
34 |
+
|
35 |
+
st.title("Cold Email Generator")
|
36 |
+
|
37 |
+
if not st.session_state.get("user_id"):
|
38 |
+
render_user_profile()
|
39 |
+
else:
|
40 |
+
if not st.session_state.get("page"):
|
41 |
+
page = st.sidebar.radio("Navigate", ["Generate Email", "Template Emails", "User Profiles"])
|
42 |
+
else:
|
43 |
+
page = st.session_state.page
|
44 |
+
|
45 |
+
if page == "Generate Email":
|
46 |
+
render_gen_email()
|
47 |
+
elif page == "Template Emails":
|
48 |
+
render_templates()
|
49 |
+
elif page == "User Profiles":
|
50 |
+
render_user_profile()
|
51 |
+
|
52 |
+
except Exception as err:
|
53 |
+
traceback.print_exc()
|
54 |
+
print(err)
|
55 |
+
|
56 |
+
if __name__ == "__main__":
|
57 |
+
main()
|
backend.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import llm
|
3 |
+
import traceback
|
4 |
+
|
5 |
+
def collect_context_for_email(industry, role, tone, context, sender_details, rec_details):
|
6 |
+
|
7 |
+
try:
|
8 |
+
|
9 |
+
user_input = {
|
10 |
+
"industry": industry,
|
11 |
+
"recipient_role": rec_details["rec_name"],
|
12 |
+
"tone": tone,
|
13 |
+
"context": context,
|
14 |
+
"sender_name": sender_details["sender_name"],
|
15 |
+
"receiver_name": rec_details["rec_name"],
|
16 |
+
"receiver_designation": rec_details["rec_designation"],
|
17 |
+
"receiver_company_name": rec_details["rec_company_name"]
|
18 |
+
}
|
19 |
+
|
20 |
+
llm_output = llm.chat_with_groq(user_input)
|
21 |
+
|
22 |
+
return llm_output
|
23 |
+
except Exception as err:
|
24 |
+
traceback.print_exc()
|
25 |
+
print(err)
|
26 |
+
|
lib/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
lib/common/database_support.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from openpyxl import load_workbook, Workbook
|
4 |
+
from datetime import datetime
|
5 |
+
import uuid
|
6 |
+
|
7 |
+
|
8 |
+
def load_or_create_excel(file_path):
|
9 |
+
try:
|
10 |
+
wb = load_workbook(file_path)
|
11 |
+
except FileNotFoundError:
|
12 |
+
wb = Workbook()
|
13 |
+
wb.create_sheet("Users")
|
14 |
+
wb.create_sheet("GeneratedEmails")
|
15 |
+
wb.create_sheet("TemplateEmails")
|
16 |
+
|
17 |
+
users_sheet = wb["Users"]
|
18 |
+
users_sheet.append(["UserID", "Name", "Email", "Company", "Role"])
|
19 |
+
|
20 |
+
generated_emails_sheet = wb["GeneratedEmails"]
|
21 |
+
generated_emails_sheet.append(["EmailID", "UserID", "Subject", "Body", "Timestamp"])
|
22 |
+
|
23 |
+
template_emails_sheet = wb["TemplateEmails"]
|
24 |
+
template_emails_sheet.append(["TemplateID", "Name", "Subject", "Body"])
|
25 |
+
|
26 |
+
wb.save(file_path)
|
27 |
+
return wb
|
28 |
+
|
29 |
+
# Function to add user to Excel
|
30 |
+
def add_user_to_excel(file_path, user_data):
|
31 |
+
wb = load_or_create_excel(file_path)
|
32 |
+
sheet = wb["Users"]
|
33 |
+
user_id = str(uuid.uuid4())
|
34 |
+
sheet.append([user_id, user_data['name'], user_data['email'], user_data['company'], user_data['role']])
|
35 |
+
wb.save(file_path)
|
36 |
+
return user_id
|
37 |
+
|
38 |
+
# Function to save generated email
|
39 |
+
def save_email_to_excel(file_path, user_id, subject, body):
|
40 |
+
wb = load_or_create_excel(file_path)
|
41 |
+
sheet = wb["GeneratedEmails"]
|
42 |
+
email_id = str(uuid.uuid4())
|
43 |
+
sheet.append([email_id, user_id, subject, body, datetime.now().strftime("%Y-%m-%d %H:%M:%S")])
|
44 |
+
wb.save(file_path)
|
45 |
+
|
46 |
+
# Function to add template email
|
47 |
+
def add_template_email(file_path, name, subject, body):
|
48 |
+
wb = load_or_create_excel(file_path)
|
49 |
+
sheet = wb["TemplateEmails"]
|
50 |
+
template_id = str(uuid.uuid4())
|
51 |
+
sheet.append([template_id, name, subject, body])
|
52 |
+
wb.save(file_path)
|
53 |
+
|
54 |
+
# Function to get all template emails
|
55 |
+
def get_template_emails(file_path):
|
56 |
+
df = pd.read_excel(file_path, sheet_name="TemplateEmails")
|
57 |
+
return df.to_dict('records')
|
58 |
+
|
59 |
+
# Function to generate email using Groq LLM (placeholder)
|
60 |
+
def generate_email(prompt):
|
61 |
+
# Implement your Groq LLM email generation logic here
|
62 |
+
return f"Subject: Generated Email\n\nBody: {prompt}"
|
63 |
+
|
64 |
+
def get_user_by_id(file_path, user_id):
|
65 |
+
wb = load_workbook(file_path)
|
66 |
+
sheet = wb["Users"]
|
67 |
+
for row in sheet.iter_rows(min_row=2, values_only=True):
|
68 |
+
if row[0] == user_id:
|
69 |
+
return {'name': row[1], 'email': row[2], 'company': row[3], 'role': row[4]}
|
70 |
+
return None
|
71 |
+
|
72 |
+
def update_user_in_excel(file_path, user_id, user_data):
|
73 |
+
wb = load_workbook(file_path)
|
74 |
+
sheet = wb["Users"]
|
75 |
+
for row in sheet.iter_rows(min_row=2):
|
76 |
+
if row[0].value == user_id:
|
77 |
+
row[1].value = user_data['name']
|
78 |
+
row[2].value = user_data['email']
|
79 |
+
row[3].value = user_data['company']
|
80 |
+
row[4].value = user_data['role']
|
81 |
+
break
|
82 |
+
wb.save(file_path)
|
83 |
+
|
84 |
+
def store_sent_email(file_path, sender_email, receiver_email, subject, body):
|
85 |
+
wb = load_or_create_excel(file_path)
|
86 |
+
sheet = wb["GeneratedEmails"]
|
87 |
+
email_id = str(uuid.uuid4())
|
88 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
89 |
+
|
90 |
+
# Append the sent email details to the sheet
|
91 |
+
sheet.append([email_id, sender_email, receiver_email, subject, body, timestamp])
|
92 |
+
|
93 |
+
wb.save(file_path)
|
94 |
+
return email_id
|
lib/support/generate_email_support.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import traceback
|
4 |
+
import backend
|
5 |
+
from lib.common.database_support import save_email_to_excel
|
6 |
+
import time
|
7 |
+
|
8 |
+
def render_gen_email():
|
9 |
+
try:
|
10 |
+
|
11 |
+
st.title("Generate Email")
|
12 |
+
excel_file = st.session_state.get("excel_file", "Error Not Found")
|
13 |
+
|
14 |
+
if excel_file == "Error Not Found":
|
15 |
+
raise Exception("Error Not Found")
|
16 |
+
|
17 |
+
if not st.session_state.get("user_id"):
|
18 |
+
st.warning("Please fill in your profile information first.")
|
19 |
+
return
|
20 |
+
|
21 |
+
split_screen_col1, split_screen_col2 = st.columns(2)
|
22 |
+
# Input fields
|
23 |
+
with split_screen_col1:
|
24 |
+
industry_col, recipient_col = st.columns(2)
|
25 |
+
with industry_col:
|
26 |
+
industry = st.text_input("Industry")
|
27 |
+
with recipient_col:
|
28 |
+
role = st.text_input("Role")
|
29 |
+
|
30 |
+
details_col1, details_col2 = st.columns(2)
|
31 |
+
with details_col1:
|
32 |
+
sender_name = st.text_input("Senders Name")
|
33 |
+
|
34 |
+
with details_col2:
|
35 |
+
rec_name = st.text_input("Receivers Name")
|
36 |
+
rec_designation = st.text_input("Receivers Designation")
|
37 |
+
rec_company_name = st.text_input("Receivers Company Name")
|
38 |
+
|
39 |
+
sender_details = {
|
40 |
+
"sender_name": sender_name,
|
41 |
+
}
|
42 |
+
rec_details = {
|
43 |
+
"rec_name": rec_name,
|
44 |
+
"rec_designation": rec_designation,
|
45 |
+
"rec_company_name": rec_company_name
|
46 |
+
}
|
47 |
+
|
48 |
+
|
49 |
+
tone = st.selectbox("Tone", ["Formal", "Casual", "Friendly", "Professional"])
|
50 |
+
context = st.text_area("Context")
|
51 |
+
|
52 |
+
is_generate_clicked = st.button("Generate Email")
|
53 |
+
|
54 |
+
with split_screen_col2:
|
55 |
+
|
56 |
+
if is_generate_clicked:
|
57 |
+
|
58 |
+
generated_email = backend.collect_context_for_email(industry, role, tone, context, sender_details,rec_details )
|
59 |
+
st.session_state.generated_email = generated_email
|
60 |
+
st.text_area("Generated Email", value=generated_email, height=300, key="editable_email")
|
61 |
+
st.session_state.is_generate_clicked = True
|
62 |
+
else:
|
63 |
+
st.text_area("Generated Email", height=300, disabled=True)
|
64 |
+
|
65 |
+
# Save to templates button
|
66 |
+
if st.button("Save to templates"):
|
67 |
+
if st.session_state.get("generated_email"):
|
68 |
+
edited_email = st.session_state.editable_email
|
69 |
+
timestamp = int(time.time())
|
70 |
+
new_template = {
|
71 |
+
"Name": f"Generated Email {timestamp}",
|
72 |
+
"Subject": "New Generated Email",
|
73 |
+
"Body": edited_email
|
74 |
+
}
|
75 |
+
st.session_state.new_template = new_template # Store the new template in session state
|
76 |
+
st.session_state.show_new_template = True
|
77 |
+
st.session_state.page = "Template Emails"
|
78 |
+
st.rerun()
|
79 |
+
else:
|
80 |
+
st.warning("Please generate an email first.")
|
81 |
+
|
82 |
+
st.markdown("---")
|
83 |
+
|
84 |
+
except Exception as err:
|
85 |
+
traceback.print_exc()
|
86 |
+
print(err)
|
lib/support/template_email_support.py
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import traceback
|
3 |
+
import time
|
4 |
+
from lib.common.database_support import get_template_emails, add_template_email, store_sent_email, save_email_to_excel
|
5 |
+
|
6 |
+
def get_sample_emails():
|
7 |
+
return [
|
8 |
+
{
|
9 |
+
"Name": "Professional Introduction",
|
10 |
+
"Subject": "Introduction - [Your Name] from [Your Company]",
|
11 |
+
"Body": "Dear [Recipient],\n\nI hope this email finds you well. My name is [Your Name], and I am reaching out to introduce myself and [Your Company]. We specialize in [brief description of your services/products].\n\nI would love the opportunity to discuss how we might be able to collaborate. Would you be available for a brief call next week?\n\nBest regards,\n[Your Name]\n[Your Position]\n[Your Company]"
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"Name": "Friendly Invitation",
|
15 |
+
"Subject": "Let's catch up over coffee!",
|
16 |
+
"Body": "Hey [Friend's Name]!\n\nIt's been too long since we last caught up. How about we grab a coffee this weekend? I'd love to hear what you've been up to!\n\nLet me know if Saturday afternoon works for you.\n\nCheers,\n[Your Name]"
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"Name": "Customer Support",
|
20 |
+
"Subject": "Re: Your Recent Order #12345",
|
21 |
+
"Body": "Dear [Customer Name],\n\nThank you for contacting our support team regarding your recent order #12345. We apologize for any inconvenience you may have experienced.\n\nWe have reviewed your case and [explanation of the solution or next steps].\n\nIf you have any further questions, please don't hesitate to reach out.\n\nBest regards,\n[Your Name]\nCustomer Support Team"
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"Name": "Job Application",
|
25 |
+
"Subject": "Application for [Position] - [Your Name]",
|
26 |
+
"Body": "Dear Hiring Manager,\n\nI am writing to express my strong interest in the [Position] role at [Company Name], as advertised on [where you found the job posting].\n\nWith my background in [relevant skills/experience], I am confident that I would be a valuable addition to your team. [Brief highlight of your qualifications].\n\nPlease find attached my resume and portfolio. I look forward to the opportunity to discuss how my skills and experiences align with your needs.\n\nThank you for your time and consideration.\n\nSincerely,\n[Your Name]"
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"Name": "Event Invitation",
|
30 |
+
"Subject": "You're Invited: [Event Name]",
|
31 |
+
"Body": "Dear [Recipient],\n\nWe are delighted to invite you to [Event Name], taking place on [Date] at [Time] at [Location].\n\n[Brief description of the event and its purpose]\n\nPlease RSVP by [RSVP deadline] to [contact email/phone].\n\nWe look forward to seeing you there!\n\nBest regards,\n[Your Name]\n[Organization]"
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"Name": "Thank You Note",
|
35 |
+
"Subject": "Thank You for Your Support",
|
36 |
+
"Body": "Dear [Name],\n\nI wanted to take a moment to express my sincere gratitude for [reason for thanking - e.g., your recent donation, attending our event, your ongoing support].\n\n[Personalized message about the impact of their action/support]\n\nThank you again for your generosity and kindness.\n\nWarmest regards,\n[Your Name]"
|
37 |
+
},
|
38 |
+
{
|
39 |
+
"Name": "Business Proposal",
|
40 |
+
"Subject": "Business Proposal: [Brief Description]",
|
41 |
+
"Body": "Dear [Recipient],\n\nI hope this email finds you well. I am reaching out to propose a business opportunity that I believe would be mutually beneficial for [Your Company] and [Their Company].\n\n[Brief overview of the proposal]\n\nKey benefits of this partnership include:\n- [Benefit 1]\n- [Benefit 2]\n- [Benefit 3]\n\nI would welcome the opportunity to discuss this proposal in more detail. Are you available for a call next week?\n\nBest regards,\n[Your Name]\n[Your Position]\n[Your Company]"
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"Name": "Apology Email",
|
45 |
+
"Subject": "Our Sincere Apologies",
|
46 |
+
"Body": "Dear [Customer Name],\n\nOn behalf of [Company Name], I want to sincerely apologize for [description of the issue or mistake].\n\nWe understand the inconvenience this has caused you and take full responsibility for our error. We are taking the following steps to rectify the situation:\n\n[List of actions being taken]\n\nAs a gesture of our commitment to making this right, we would like to offer you [compensation or solution].\n\nWe value your business and hope to regain your trust.\n\nSincerely,\n[Your Name]\n[Your Position]\n[Company Name]"
|
47 |
+
}
|
48 |
+
]
|
49 |
+
|
50 |
+
def render_templates():
|
51 |
+
try:
|
52 |
+
excel_file = st.session_state.get("excel_file", "Error Not Found")
|
53 |
+
|
54 |
+
if excel_file == "Error Not Found":
|
55 |
+
raise Exception("Error Not Found")
|
56 |
+
|
57 |
+
if not st.session_state.get("user_id"):
|
58 |
+
st.warning("Please fill in your profile information first.")
|
59 |
+
return
|
60 |
+
|
61 |
+
st.title("Email Templates")
|
62 |
+
|
63 |
+
new_template = st.session_state.get("new_template", None)
|
64 |
+
show_only_new = st.session_state.get("show_new_template", False)
|
65 |
+
|
66 |
+
if show_only_new and new_template:
|
67 |
+
templates_to_show = [new_template]
|
68 |
+
else:
|
69 |
+
if "templates" not in st.session_state:
|
70 |
+
st.session_state.templates = get_sample_emails()
|
71 |
+
templates_to_show = st.session_state.templates
|
72 |
+
|
73 |
+
template_names = [template['Name'] for template in templates_to_show]
|
74 |
+
|
75 |
+
if not show_only_new:
|
76 |
+
template_names.insert(0, "Select a template")
|
77 |
+
|
78 |
+
selected_template_name = st.selectbox("Choose a template", template_names, index=0 if show_only_new else None)
|
79 |
+
|
80 |
+
if selected_template_name and selected_template_name != "Select a template":
|
81 |
+
selected_template = next((template for template in templates_to_show if template['Name'] == selected_template_name), None)
|
82 |
+
# print(selected_template)
|
83 |
+
print(selected_template, "\n\nselc\n\n")
|
84 |
+
if selected_template:
|
85 |
+
# Use session state to store editable fields
|
86 |
+
if 'current_template' not in st.session_state:
|
87 |
+
print("inside")
|
88 |
+
|
89 |
+
st.session_state.current_template = {
|
90 |
+
'sender_email': '',
|
91 |
+
'receiver_email': '',
|
92 |
+
'subject': selected_template['Subject'],
|
93 |
+
'body': selected_template['Body']
|
94 |
+
}
|
95 |
+
|
96 |
+
col1, col2 = st.columns(2)
|
97 |
+
with col1:
|
98 |
+
st.session_state.current_template['sender_email'] = st.text_input("Sender's Email", value=st.session_state.current_template['sender_email'])
|
99 |
+
st.session_state.current_template['subject'] = st.text_input("Subject", value=st.session_state.current_template['subject'])
|
100 |
+
with col2:
|
101 |
+
st.session_state.current_template['receiver_email'] = st.text_input("Receiver's Email", value=st.session_state.current_template['receiver_email'])
|
102 |
+
|
103 |
+
st.session_state.current_template['body'] = st.text_area("Email Body", value=st.session_state.current_template['body'], height=200)
|
104 |
+
|
105 |
+
col1, col2 = st.columns(2)
|
106 |
+
# with col1:
|
107 |
+
# if st.button("Save Template"):
|
108 |
+
# if st.session_state.current_template['subject'] and st.session_state.current_template['body']:
|
109 |
+
# save_email_to_excel(excel_file, st.session_state.user_id, st.session_state.current_template['subject'], st.session_state.current_template['body'])
|
110 |
+
# st.success("Template saved successfully!")
|
111 |
+
# else:
|
112 |
+
# st.warning("Please fill in the subject and body before saving.")
|
113 |
+
|
114 |
+
with col2:
|
115 |
+
if st.button("Send Email"):
|
116 |
+
if all(st.session_state.current_template.values()):
|
117 |
+
store_sent_email(excel_file, st.session_state.current_template['sender_email'], st.session_state.current_template['receiver_email'], st.session_state.current_template['subject'], st.session_state.current_template['body'])
|
118 |
+
st.success("Email sent successfully")
|
119 |
+
|
120 |
+
if st.session_state.get("new_template"):
|
121 |
+
st.session_state.pop("new_template")
|
122 |
+
if st.session_state.get("show_new_template"):
|
123 |
+
st.session_state.pop("show_new_template")
|
124 |
+
|
125 |
+
if 'current_template' in st.session_state:
|
126 |
+
st.session_state.pop("current_template")
|
127 |
+
time.sleep(1)
|
128 |
+
st.session_state.page = "Generate Email"
|
129 |
+
st.rerun()
|
130 |
+
else:
|
131 |
+
st.warning("Please fill in all fields before sending.")
|
132 |
+
else:
|
133 |
+
st.warning("Selected template not found. Please choose a valid template.")
|
134 |
+
|
135 |
+
if show_only_new:
|
136 |
+
if st.button("Back to All Templates"):
|
137 |
+
st.session_state.pop("new_template", None)
|
138 |
+
st.session_state.pop("show_new_template", None)
|
139 |
+
st.session_state.pop("current_template",None)
|
140 |
+
st.rerun()
|
141 |
+
|
142 |
+
except Exception as err:
|
143 |
+
traceback.print_exc()
|
144 |
+
print(err)
|
145 |
+
|
lib/support/user_profile_support.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import traceback
|
3 |
+
from lib.common.database_support import add_user_to_excel, get_user_by_id, update_user_in_excel
|
4 |
+
|
5 |
+
|
6 |
+
def render_user_profile():
|
7 |
+
try:
|
8 |
+
excel_file = st.session_state.get("excel_file", "Error Not Found")
|
9 |
+
|
10 |
+
if excel_file == "Error Not Found":
|
11 |
+
raise Exception("Error Not Found")
|
12 |
+
|
13 |
+
st.title("User Profile")
|
14 |
+
|
15 |
+
user_id = st.session_state.get("user_id")
|
16 |
+
if not user_id:
|
17 |
+
st.warning("Please fill in your profile information to continue.")
|
18 |
+
user_data = {'name': '', 'email': '', 'company': '', 'role': ''}
|
19 |
+
else:
|
20 |
+
user_data = get_user_by_id(excel_file, user_id)
|
21 |
+
|
22 |
+
with st.form("user_form"):
|
23 |
+
name = st.text_input("Name", value=user_data['name'])
|
24 |
+
email = st.text_input("Email", value=user_data['email'])
|
25 |
+
company = st.text_input("Company", value=user_data['company'])
|
26 |
+
role = st.text_input("Role", value=user_data['role'])
|
27 |
+
submitted = st.form_submit_button("Save Profile")
|
28 |
+
|
29 |
+
if submitted:
|
30 |
+
updated_user_data = {'name': name, 'email': email, 'company': company, 'role': role}
|
31 |
+
if user_id:
|
32 |
+
update_user_in_excel(excel_file, user_id, updated_user_data)
|
33 |
+
st.success("Profile updated successfully!")
|
34 |
+
else:
|
35 |
+
user_id = add_user_to_excel(excel_file, updated_user_data)
|
36 |
+
st.session_state['user_id'] = user_id
|
37 |
+
st.success("Profile saved! You can now access other features.")
|
38 |
+
st.session_state['user_email'] = email
|
39 |
+
st.rerun()
|
40 |
+
|
41 |
+
except Exception as err:
|
42 |
+
traceback.print_exc()
|
43 |
+
print(err)
|
44 |
+
|
llm.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Default
|
2 |
+
import os
|
3 |
+
from groq import Groq
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import traceback
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
client = Groq(
|
10 |
+
# This is the default and can be omitted
|
11 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
12 |
+
)
|
13 |
+
|
14 |
+
def chat_with_groq(user_input, additional_info=None):
|
15 |
+
|
16 |
+
try:
|
17 |
+
|
18 |
+
template_prompt = f"""
|
19 |
+
|
20 |
+
You are a professional email writer who specialises in writing cold email.
|
21 |
+
Generate a cold email to {user_input['recipient_role']} based on the following information:
|
22 |
+
|
23 |
+
Industry: {user_input['industry']}
|
24 |
+
Tone: {user_input['tone']}
|
25 |
+
Context: {user_input['context']}
|
26 |
+
Sender's Name: {user_input['sender_name']}
|
27 |
+
Receiver's Name: {user_input['receiver_name']}
|
28 |
+
Receiver's Designation: {user_input['receiver_designation']}
|
29 |
+
Receiver's Company Name: {user_input['receiver_company_name']}
|
30 |
+
|
31 |
+
Incorporate all information and write a compelling email.
|
32 |
+
|
33 |
+
"""
|
34 |
+
# test purposes:
|
35 |
+
# return template_prompt
|
36 |
+
chat_completion = client.chat.completions.create(
|
37 |
+
messages=[
|
38 |
+
{
|
39 |
+
"role": "system",
|
40 |
+
"content": "You are an expert email writer specializing in cold emails.",
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"role": "user",
|
44 |
+
"content": template_prompt,
|
45 |
+
}
|
46 |
+
],
|
47 |
+
model="mixtral-8x7b-32768",
|
48 |
+
)
|
49 |
+
|
50 |
+
generated_email = chat_completion.choices[0].message.content
|
51 |
+
return generated_email
|
52 |
+
|
53 |
+
|
54 |
+
except Exception as err:
|
55 |
+
traceback.print_exc()
|
56 |
+
print(err)
|
57 |
+
|
58 |
+
|
59 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
groq
|
4 |
+
python-dotenv
|
5 |
+
pandas
|
6 |
+
openpyxl
|