Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import smtplib, time, random
|
4 |
+
from email.mime.text import MIMEText
|
5 |
+
|
6 |
+
# -----------------------------
|
7 |
+
# 1) AI Email Generator
|
8 |
+
# -----------------------------
|
9 |
+
def generate_email(name, company, role, tone="professional"):
|
10 |
+
email_templates = {
|
11 |
+
"professional": f"""
|
12 |
+
Subject: Exploring {role} opportunities at {company}
|
13 |
+
|
14 |
+
Hi {name},
|
15 |
+
I admire {company}'s work in your industry. Based on my skills and experience,
|
16 |
+
I believe I can contribute meaningfully to your {role} team.
|
17 |
+
Would you be open to a quick chat?
|
18 |
+
|
19 |
+
Best regards,
|
20 |
+
[Your Name]
|
21 |
+
""",
|
22 |
+
"friendly": f"""
|
23 |
+
Subject: Love what {company} is building 🚀
|
24 |
+
|
25 |
+
Hey {name},
|
26 |
+
Just wanted to say I really like what you’re doing at {company}.
|
27 |
+
I’d love to explore if there’s a role for me to add value as {role}.
|
28 |
+
|
29 |
+
Cheers,
|
30 |
+
[Your Name]
|
31 |
+
"""
|
32 |
+
}
|
33 |
+
return email_templates.get(tone, email_templates["professional"])
|
34 |
+
|
35 |
+
# -----------------------------
|
36 |
+
# 2) Email Sender with Rotation
|
37 |
+
# -----------------------------
|
38 |
+
def send_email(sender_email, sender_password, receiver_email, email_body):
|
39 |
+
msg = MIMEText(email_body, "plain")
|
40 |
+
msg["From"] = sender_email
|
41 |
+
msg["To"] = receiver_email
|
42 |
+
msg["Subject"] = "Let's Connect"
|
43 |
+
|
44 |
+
try:
|
45 |
+
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
|
46 |
+
server.login(sender_email, sender_password)
|
47 |
+
server.sendmail(sender_email, receiver_email, msg.as_string())
|
48 |
+
return "✅ Sent!"
|
49 |
+
except Exception as e:
|
50 |
+
return f"❌ Error: {e}"
|
51 |
+
|
52 |
+
# -----------------------------
|
53 |
+
# 3) Bulk Campaign Handler
|
54 |
+
# -----------------------------
|
55 |
+
def run_campaign(file, sender_email, sender_password, tone):
|
56 |
+
leads = pd.read_csv(file.name)
|
57 |
+
logs = []
|
58 |
+
for _, row in leads.iterrows():
|
59 |
+
name, company, role, email = row["Name"], row["Company"], row["Role"], row["Email"]
|
60 |
+
email_text = generate_email(name, company, role, tone)
|
61 |
+
status = send_email(sender_email, sender_password, email, email_text)
|
62 |
+
logs.append([name, company, email, status])
|
63 |
+
time.sleep(random.randint(10,30)) # delay to avoid spam flags
|
64 |
+
log_df = pd.DataFrame(logs, columns=["Name","Company","Email","Status"])
|
65 |
+
return log_df
|
66 |
+
|
67 |
+
# -----------------------------
|
68 |
+
# 4) Gradio App
|
69 |
+
# -----------------------------
|
70 |
+
with gr.Blocks() as app:
|
71 |
+
gr.Markdown("## 📧 AI Cold Outreach Campaign Manager")
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
sender = gr.Textbox(label="Your Email")
|
75 |
+
password = gr.Textbox(label="Your Email Password", type="password")
|
76 |
+
|
77 |
+
file = gr.File(label="Upload Leads CSV (Name,Company,Role,Email)", file_types=[".csv"])
|
78 |
+
tone = gr.Radio(["professional", "friendly"], label="Tone", value="professional")
|
79 |
+
|
80 |
+
output = gr.Dataframe(label="Campaign Logs")
|
81 |
+
|
82 |
+
run_btn = gr.Button("🚀 Run Campaign")
|
83 |
+
|
84 |
+
run_btn.click(run_campaign, [file, sender, password, tone], output)
|
85 |
+
|
86 |
+
app.launch()
|