import gradio as gr import pandas as pd import smtplib, time, random from email.mime.text import MIMEText # ----------------------------- # 1) AI Email Generator # ----------------------------- def generate_email(name, company, role, tone="professional"): email_templates = { "professional": f""" Subject: Exploring {role} opportunities at {company} Hi {name}, I admire {company}'s work in your industry. Based on my skills and experience, I believe I can contribute meaningfully to your {role} team. Would you be open to a quick chat? Best regards, [Your Name] """, "friendly": f""" Subject: Love what {company} is building 🚀 Hey {name}, Just wanted to say I really like what you’re doing at {company}. I’d love to explore if there’s a role for me to add value as {role}. Cheers, [Your Name] """ } return email_templates.get(tone, email_templates["professional"]) # ----------------------------- # 2) Email Sender with Rotation # ----------------------------- def send_email(sender_email, sender_password, receiver_email, email_body): msg = MIMEText(email_body, "plain") msg["From"] = sender_email msg["To"] = receiver_email msg["Subject"] = "Let's Connect" try: with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server: server.login(sender_email, sender_password) server.sendmail(sender_email, receiver_email, msg.as_string()) return "✅ Sent!" except Exception as e: return f"❌ Error: {e}" # ----------------------------- # 3) Bulk Campaign Handler # ----------------------------- def run_campaign(file, sender_email, sender_password, tone): leads = pd.read_csv(file.name) logs = [] for _, row in leads.iterrows(): name, company, role, email = row["Name"], row["Company"], row["Role"], row["Email"] email_text = generate_email(name, company, role, tone) status = send_email(sender_email, sender_password, email, email_text) logs.append([name, company, email, status]) time.sleep(random.randint(10,30)) # delay to avoid spam flags log_df = pd.DataFrame(logs, columns=["Name","Company","Email","Status"]) return log_df # ----------------------------- # 4) Gradio App # ----------------------------- with gr.Blocks() as app: gr.Markdown("## 📧 AI Cold Outreach Campaign Manager") with gr.Row(): sender = gr.Textbox(label="Your Email") password = gr.Textbox(label="Your Email Password", type="password") file = gr.File(label="Upload Leads CSV (Name,Company,Role,Email)", file_types=[".csv"]) tone = gr.Radio(["professional", "friendly"], label="Tone", value="professional") output = gr.Dataframe(label="Campaign Logs") run_btn = gr.Button("🚀 Run Campaign") run_btn.click(run_campaign, [file, sender, password, tone], output) app.launch()