Ley_Fill7 commited on
Commit
5b779b8
·
1 Parent(s): 0468261

Added the app file

Browse files
Files changed (1) hide show
  1. app.py +81 -0
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+ import schedule
4
+ import time
5
+ from datetime import datetime
6
+
7
+ # Function to Generate Email Content
8
+ def generate_email(template, customer, product):
9
+ try:
10
+ email_content = template.format(
11
+ name=customer['name'],
12
+ product_name=product['name'],
13
+ features=product['features'],
14
+ benefits=product['benefits']
15
+ )
16
+ except KeyError as e:
17
+ st.error(f"KeyError: {e} in template: {template}")
18
+ raise
19
+ return email_content
20
+
21
+ # Function to Send Email (for demonstration purposes, it just prints the email)
22
+ def send_email(email):
23
+ st.write(f"Subject: {email['subject']}")
24
+ st.write(email['content'])
25
+ st.write("\n---\n")
26
+
27
+ # Streamlit UI
28
+ st.title(" Cold Email Sequence Generator")
29
+
30
+ uploaded_file = st.file_uploader("Upload a JSON file input structured like the 'example.json' in this App's files section", type="json")
31
+
32
+ if uploaded_file is not None:
33
+ # Parse JSON Input
34
+ data = json.load(uploaded_file)
35
+
36
+ customer = data['customer']
37
+ product = data['product']
38
+ sequence = data['sequence']
39
+
40
+ emails = []
41
+
42
+ # Generate Emails Based on the Sequence
43
+ for email in sequence:
44
+ email_content = generate_email(email['template'], customer, product)
45
+ emails.append({
46
+ "day": email['day'],
47
+ "subject": email['subject'],
48
+ "content": email_content
49
+ })
50
+
51
+ # Display Generated Emails
52
+ st.subheader("Generated Emails")
53
+ for email in emails:
54
+ send_email(email)
55
+
56
+ # Schedule Emails (for demonstration purposes, it just prints the emails)
57
+ start_time = datetime.now()
58
+ emails_sent = set()
59
+ emails_sent_count = 0
60
+ max_emails_to_send = len(emails)
61
+
62
+ def get_email_identifier(email):
63
+ return (email['subject'], email['content'])
64
+
65
+ def schedule_email(e=email):
66
+ global emails_sent_count
67
+ if emails_sent_count < max_emails_to_send:
68
+ if get_email_identifier(e) not in emails_sent:
69
+ send_email(e)
70
+ emails_sent.add(get_email_identifier(e))
71
+ emails_sent_count += 1
72
+ if emails_sent_count >= max_emails_to_send:
73
+ return schedule.CancelJob
74
+
75
+ if st.button("Start Email Scheduling"):
76
+ for i, email in enumerate(emails):
77
+ schedule.every(10 * (i + 1)).seconds.do(schedule_email, e=email)
78
+
79
+ while emails_sent_count < max_emails_to_send:
80
+ schedule.run_pending()
81
+ time.sleep(1)