monster07 commited on
Commit
cbd22d0
Β·
verified Β·
1 Parent(s): 6ad0cf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -69
app.py CHANGED
@@ -1,70 +1,54 @@
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
- import io
7
-
8
- # Load Hugging Face FLAN-T5 Model
9
- email_generator = pipeline("text2text-generation", model="google/flan-t5-base")
10
-
11
- # Email Sending Function
12
- def send_email(to_email, subject, body, from_email, from_password):
13
- msg = MIMEText(body, "plain")
14
- msg["Subject"] = subject
15
- msg["From"] = from_email
16
- msg["To"] = to_email
17
-
18
- try:
19
- server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
20
- server.login(from_email, from_password)
21
- server.sendmail(from_email, [to_email], msg.as_string())
22
- server.quit()
23
- return f"βœ… Email sent to {to_email}"
24
- except Exception as e:
25
- return f"❌ Failed to send to {to_email}: {str(e)}"
26
-
27
- # Main Processing Function
28
- def process_and_send(csv_file, sender_email, sender_pass):
29
- try:
30
- # Decode CSV file from bytes to string
31
- df = pd.read_csv(io.StringIO(csv_file.decode("utf-8")))
32
- except Exception as e:
33
- return f"❌ Failed to read CSV: {e}"
34
-
35
- logs = []
36
-
37
- for index, row in df.iterrows():
38
- name = row["Name"]
39
- email = row["Email"]
40
- status = row["Status"]
41
- internship_title = row["Internship_Title"]
42
- company_name = row["Company_Name"]
43
-
44
- 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}."
45
-
46
- try:
47
- mail_body = email_generator(prompt, max_length=200)[0]["generated_text"]
48
- subject = f"Regarding your application for {internship_title} at {company_name}"
49
- result = send_email(email, subject, mail_body, sender_email, sender_pass)
50
- except Exception as e:
51
- result = f"❌ Error for {email}: {str(e)}"
52
-
53
- logs.append(result)
54
-
55
- return "\n".join(logs)
56
-
57
- # Gradio UI
58
- iface = gr.Interface(
59
- fn=process_and_send,
60
- inputs=[
61
- gr.File(label="πŸ“‚ Upload CSV of Applicants", file_types=[".csv"]),
62
- gr.Text(label="πŸ“§ Your Email (Gmail)", placeholder="example@gmail.com"),
63
- gr.Text(label="πŸ” Your Email Password or App Password", type="password"),
64
- ],
65
- outputs="text",
66
- title="AI-Powered Mailing System (No API Key Needed)",
67
- description="Upload your applicant CSV and send personalized emails using Hugging Face FLAN-T5 model.",
68
- )
69
-
70
- iface.launch()
 
1
  import gradio as gr
2
+ import base64
3
+ import pdfkit
4
+ from jinja2 import Template
5
+
6
+ # Load HTML template
7
+ with open("template.html", "r", encoding="utf-8") as f:
8
+ template_html = f.read()
9
+
10
+ def generate_resume(name, job_title, email, phone, summary, skills, education, experience, photo):
11
+ photo_base64 = ""
12
+ if photo is not None:
13
+ photo_base64 = base64.b64encode(photo.read()).decode('utf-8')
14
+
15
+ data = {
16
+ "name": name,
17
+ "job_title": job_title,
18
+ "email": email,
19
+ "phone": phone,
20
+ "summary": summary,
21
+ "skills": [s.strip() for s in skills.split(",")],
22
+ "education": [e.strip() for e in education.split(";")],
23
+ "experience": [x.strip() for x in experience.split(";")],
24
+ "photo_base64": photo_base64
25
+ }
26
+
27
+ template = Template(template_html)
28
+ rendered_html = template.render(**data)
29
+
30
+ with open("resume_output.html", "w", encoding="utf-8") as f:
31
+ f.write(rendered_html)
32
+
33
+ pdfkit.from_file("resume_output.html", "resume.pdf")
34
+ return "resume.pdf"
35
+
36
+ inputs = [
37
+ gr.Text(label="Full Name"),
38
+ gr.Text(label="Job Title"),
39
+ gr.Text(label="Email"),
40
+ gr.Text(label="Phone"),
41
+ gr.Textbox(label="Professional Summary", lines=4),
42
+ gr.Textbox(label="Skills (comma-separated)"),
43
+ gr.Textbox(label="Education (separate with ; )"),
44
+ gr.Textbox(label="Experience (separate with ; )"),
45
+ gr.File(label="Upload Profile Photo (Optional)", type="binary")
46
+ ]
47
+
48
+ gr.Interface(
49
+ fn=generate_resume,
50
+ inputs=inputs,
51
+ outputs=gr.File(label="πŸ“„ Download Resume PDF"),
52
+ title="🧠 AI Resume Builder",
53
+ description="Enter your details and generate a polished PDF resume instantly."
54
+ ).launch()