Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from email.mime.text import MIMEText
|
| 5 |
+
import smtplib
|
| 6 |
+
|
| 7 |
+
# Load Hugging Face FLAN-T5 Model
|
| 8 |
+
email_generator = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 9 |
+
|
| 10 |
+
# Email Sending Function
|
| 11 |
+
def send_email(to_email, subject, body, from_email, from_password):
|
| 12 |
+
msg = MIMEText(body, "plain")
|
| 13 |
+
msg["Subject"] = subject
|
| 14 |
+
msg["From"] = from_email
|
| 15 |
+
msg["To"] = to_email
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
|
| 19 |
+
server.login(from_email, from_password)
|
| 20 |
+
server.sendmail(from_email, [to_email], msg.as_string())
|
| 21 |
+
server.quit()
|
| 22 |
+
return f"β
Email sent to {to_email}"
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"β Failed to send to {to_email}: {str(e)}"
|
| 25 |
+
|
| 26 |
+
# Main Function
|
| 27 |
+
def process_and_send(csv_file, sender_email, sender_pass):
|
| 28 |
+
df = pd.read_csv(csv_file.name)
|
| 29 |
+
logs = []
|
| 30 |
+
|
| 31 |
+
for index, row in df.iterrows():
|
| 32 |
+
name = row["Name"]
|
| 33 |
+
email = row["Email"]
|
| 34 |
+
status = row["Status"]
|
| 35 |
+
internship_title = row["Internship_Title"]
|
| 36 |
+
company_name = row["Company_Name"]
|
| 37 |
+
|
| 38 |
+
prompt = f"Write a short and professional email to {name} who applied for the {internship_title} internship at {company_name}. Their application status is: {status}."
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
mail_body = email_generator(prompt, max_length=200)[0]["generated_text"]
|
| 42 |
+
subject = f"Regarding your application for {internship_title} at {company_name}"
|
| 43 |
+
result = send_email(email, subject, mail_body, sender_email, sender_pass)
|
| 44 |
+
except Exception as e:
|
| 45 |
+
result = f"β Error for {email}: {str(e)}"
|
| 46 |
+
|
| 47 |
+
logs.append(result)
|
| 48 |
+
|
| 49 |
+
return "\n".join(logs)
|
| 50 |
+
|
| 51 |
+
# Gradio UI
|
| 52 |
+
iface = gr.Interface(
|
| 53 |
+
fn=process_and_send,
|
| 54 |
+
inputs=[
|
| 55 |
+
gr.File(label="π Upload CSV of Applicants"),
|
| 56 |
+
gr.Text(label="π§ Your Email (Gmail)", placeholder="example@gmail.com"),
|
| 57 |
+
gr.Text(label="π Your Email Password or App Password", type="password"),
|
| 58 |
+
],
|
| 59 |
+
outputs="text",
|
| 60 |
+
title="AI-Powered Mailing System (No API Key Needed)",
|
| 61 |
+
description="Send personalized internship emails to all applicants using Hugging Face FLAN-T5 model.",
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
iface.launch()
|