monster07 commited on
Commit
9b2f814
·
verified ·
1 Parent(s): 3800af1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -37
app.py CHANGED
@@ -1,47 +1,85 @@
1
  import gradio as gr
2
  import base64
3
- from jinja2 import Template
 
 
 
4
  from transformers import pipeline
5
- from weasyprint import HTML
6
 
7
- # Load template
8
- with open("template.html", "r", encoding="utf-8") as f:
9
- template_html = f.read()
10
 
11
- # Load model for summary generation
12
- summary_gen = pipeline("text2text-generation", model="google/flan-t5-base")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- def build_resume(name, job_title, email, phone, skills, education, experience, photo):
15
- # Convert photo to base64
16
- photo_b64 = ""
17
  if photo:
18
- photo_b64 = base64.b64encode(photo.read()).decode("utf-8")
19
-
20
- # AI-generated summary
21
- prompt = f"Write a professional and passionate summary for {name}, applying as a {job_title}, with skills {skills}, and experience in {experience}."
22
- summary = summary_gen(prompt, max_length=200)[0]["generated_text"]
23
-
24
- # Prepare template data
25
- template = Template(template_html)
26
- html_resume = template.render(
27
- name=name,
28
- job_title=job_title,
29
- email=email,
30
- phone=phone,
31
- summary=summary,
32
- skills=[s.strip() for s in skills.split(",")],
33
- education=[e.strip() for e in education.split(";")],
34
- experience=[e.strip() for e in experience.split(";")],
35
- photo_base64=photo_b64
36
- )
37
-
38
- # Generate PDF
39
- HTML(string=html_resume).write_pdf("resume.pdf")
40
- return "resume.pdf"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # Gradio UI
43
  iface = gr.Interface(
44
- fn=build_resume,
45
  inputs=[
46
  gr.Text(label="Full Name"),
47
  gr.Text(label="Job Title"),
@@ -50,11 +88,11 @@ iface = gr.Interface(
50
  gr.Textbox(label="Skills (comma-separated)"),
51
  gr.Textbox(label="Education (use ; to separate items)"),
52
  gr.Textbox(label="Experience (use ; to separate items)"),
53
- gr.File(label="Profile Photo (optional)", type="binary"),
54
  ],
55
  outputs=gr.File(label="📄 Download Resume PDF"),
56
- title="AI Resume Builder",
57
- description="Build a beautiful resume with auto-generated professional summary using Hugging Face FLAN-T5."
58
  )
59
 
60
  iface.launch()
 
1
  import gradio as gr
2
  import base64
3
+ import io
4
+ from reportlab.lib.pagesizes import A4
5
+ from reportlab.pdfgen import canvas
6
+ from reportlab.lib.utils import ImageReader
7
  from transformers import pipeline
 
8
 
9
+ # Load FLAN-T5 model from Hugging Face
10
+ summary_generator = pipeline("text2text-generation", model="google/flan-t5-base")
 
11
 
12
+ def generate_resume(name, job_title, email, phone, skills, education, experience, photo):
13
+ # Generate a passionate summary
14
+ prompt = f"Write a passionate summary for a person named {name}, applying as a {job_title}, skilled in {skills}, with experience in {experience}."
15
+ summary = summary_generator(prompt, max_length=200)[0]["generated_text"]
16
+
17
+ # Create PDF buffer
18
+ buffer = io.BytesIO()
19
+ pdf = canvas.Canvas(buffer, pagesize=A4)
20
+ width, height = A4
21
+ y = height - 50
22
+
23
+ pdf.setFont("Helvetica-Bold", 20)
24
+ pdf.drawString(50, y, name)
25
+
26
+ y -= 25
27
+ pdf.setFont("Helvetica", 14)
28
+ pdf.drawString(50, y, job_title)
29
+
30
+ y -= 20
31
+ pdf.setFont("Helvetica", 12)
32
+ pdf.drawString(50, y, f"Email: {email}")
33
+ y -= 20
34
+ pdf.drawString(50, y, f"Phone: {phone}")
35
 
 
 
 
36
  if photo:
37
+ image = ImageReader(photo)
38
+ pdf.drawImage(image, width - 130, height - 130, width=80, height=80, mask='auto')
39
+
40
+ y -= 40
41
+ pdf.setFont("Helvetica-Bold", 16)
42
+ pdf.drawString(50, y, "Professional Summary")
43
+ y -= 20
44
+ pdf.setFont("Helvetica", 12)
45
+ for line in summary.split(". "):
46
+ pdf.drawString(50, y, f"- {line.strip()}")
47
+ y -= 18
48
+
49
+ y -= 20
50
+ pdf.setFont("Helvetica-Bold", 16)
51
+ pdf.drawString(50, y, "Skills")
52
+ y -= 20
53
+ pdf.setFont("Helvetica", 12)
54
+ for skill in skills.split(","):
55
+ pdf.drawString(50, y, f"- {skill.strip()}")
56
+ y -= 18
57
+
58
+ y -= 20
59
+ pdf.setFont("Helvetica-Bold", 16)
60
+ pdf.drawString(50, y, "Education")
61
+ y -= 20
62
+ pdf.setFont("Helvetica", 12)
63
+ for edu in education.split(";"):
64
+ pdf.drawString(50, y, f"- {edu.strip()}")
65
+ y -= 18
66
+
67
+ y -= 20
68
+ pdf.setFont("Helvetica-Bold", 16)
69
+ pdf.drawString(50, y, "Experience")
70
+ y -= 20
71
+ pdf.setFont("Helvetica", 12)
72
+ for exp in experience.split(";"):
73
+ pdf.drawString(50, y, f"- {exp.strip()}")
74
+ y -= 18
75
+
76
+ pdf.save()
77
+ buffer.seek(0)
78
+ return buffer
79
 
80
  # Gradio UI
81
  iface = gr.Interface(
82
+ fn=generate_resume,
83
  inputs=[
84
  gr.Text(label="Full Name"),
85
  gr.Text(label="Job Title"),
 
88
  gr.Textbox(label="Skills (comma-separated)"),
89
  gr.Textbox(label="Education (use ; to separate items)"),
90
  gr.Textbox(label="Experience (use ; to separate items)"),
91
+ gr.File(label="Profile Photo (optional)", type="binary")
92
  ],
93
  outputs=gr.File(label="📄 Download Resume PDF"),
94
+ title="🧠 AI Resume Builder (ReportLab + FLAN-T5)",
95
+ description="Generates a beautiful resume with AI-generated summary using FLAN-T5 and exports a working PDF (100% compatible with Hugging Face Spaces)."
96
  )
97
 
98
  iface.launch()