Vadhana's picture
Update app.py
d5402bf verified
import gradio as gr
import pandas as pd
from enrich import enrich_and_score
from llm_email import generate_email_templates
def process_leads(file):
if file is None:
return None, "❌ No file uploaded! Please upload a CSV."
try:
df = pd.read_csv(file.name)
enriched_df = enrich_and_score(df)
enriched_df = enriched_df.drop_duplicates(subset='Company Name', keep='first')
return enriched_df, "βœ… Leads enriched successfully!"
except Exception as e:
return None, f"❌ Error processing file: {str(e)}"
def generate_emails(file):
if file is None:
return "", "❌ No file uploaded! Please upload a CSV."
try:
df = pd.read_csv(file.name)
enriched_df = enrich_and_score(df)
email_templates = generate_email_templates(enriched_df)
return email_templates, "βœ… Email templates generated!"
except Exception as e:
return "", f"❌ Error generating emails: {str(e)}"
with gr.Blocks(css="""
body {background-color: #0f172a; color: #e2e8f0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}
.gradio-container {max-width: 1000px; margin: auto; padding: 20px;}
h1 {color: #38bdf8; font-weight: 700; font-size: 2.5em;}
p {color: #94a3b8;}
.tab {background-color: #1e293b; border-radius: 10px; padding: 20px; margin-top: 20px;}
.btn-primary {background-color: #2563eb !important; border: none !important; color: white !important;}
.btn-primary:hover {background-color: #1e40af !important;}
.gr-dataframe {border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.9); background-color: #334155;}
.gr-textbox {font-family: monospace; font-size: 14px; background-color: #334155; color: #e0e0e0;}
.full-width-btn {
width: 100% !important;
padding: 12px 0 !important;
font-weight: 600 !important;
font-size: 1.1em !important;
border-radius: 6px !important;
margin-top: 10px;
}
.file-info {
font-style: italic;
color: #94a3b8;
margin-bottom: 8px;
}
.message-success {
color: #22c55e;
font-weight: 600;
margin-top: 8px;
}
.message-error {
color: #ef4444;
font-weight: 600;
margin-top: 8px;
}
.gr-box {
background-color: #1e293b;
border-radius: 10px;
padding: 20px;
}
.analytics-box {
background-color: #0f172a;
padding: 10px;
margin-top: 10px;
border-left: 4px solid #38bdf8;
color: #cbd5e1;
}
""") as app:
gr.Markdown("""
<h1 style="text-align:center; margin-bottom: 0;">πŸš€ SmartLeadBoost</h1>
<p style="text-align:center; margin-top: 5px;">
Upload your leads CSV to get enriched data & AI-crafted outreach emails!</p>
""")
with gr.Tabs():
with gr.TabItem("πŸ“Š Enrich Leads", elem_classes="tab"):
lead_input = gr.File(label="Upload CSV (Company Name, Website)", file_types=['.csv'], interactive=True)
lead_file_info = gr.Markdown("", elem_classes="file-info")
lead_output = gr.Dataframe(label="Enriched Leads with Scores", interactive=False)
enrich_btn = gr.Button("✨ Enrich Leads", variant="primary", elem_classes="full-width-btn")
lead_message = gr.Markdown("", elem_classes="message-success")
def update_file_info(file):
if file is None:
return ""
return f"Uploaded file: **{file.name}** ({round(file.size/1024, 2)} KB)"
lead_input.upload(update_file_info, lead_input, lead_file_info)
enrich_btn.click(fn=process_leads, inputs=lead_input, outputs=[lead_output, lead_message], show_progress=True)
gr.Markdown("""
<div class="analytics-box">
βœ… Leads are automatically deduplicated.<br>
πŸ“ˆ Prioritized by relevance & enrichment score.<br>
πŸ“€ Export enriched data to CSV from top-right corner.
</div>
""")
with gr.TabItem("βœ‰οΈ AI Outreach Emails", elem_classes="tab"):
email_input = gr.File(label="Upload the Same CSV", file_types=['.csv'], interactive=True)
email_file_info = gr.Markdown("", elem_classes="file-info")
email_output = gr.Textbox(label="AI-Generated Email Templates", lines=18, interactive=False)
email_btn = gr.Button("πŸ“§ Generate Email Templates", variant="primary", elem_classes="full-width-btn")
email_message = gr.Markdown("", elem_classes="message-success")
email_input.upload(update_file_info, email_input, email_file_info)
email_btn.click(fn=generate_emails, inputs=email_input, outputs=[email_output, email_message], show_progress=True)
gr.Markdown("""
<div class="analytics-box">
πŸ’¬ Emails generated using GPT-based models.<br>
🌍 Support for multiple tones, languages, and sender info coming soon.<br>
πŸ”’ No emails are stored. 100% safe!
</div>
""")
if __name__ == "__main__":
app.launch()