File size: 3,211 Bytes
2449223
cbd22d0
9b2f814
 
 
 
e27f422
cbd22d0
48b8a9c
 
cbd22d0
48b8a9c
 
 
 
 
 
 
9b2f814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbd22d0
e27f422
9b2f814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbd22d0
48b8a9c
e27f422
9b2f814
e27f422
 
 
 
 
 
 
 
48b8a9c
 
e27f422
cbd22d0
48b8a9c
 
 
e27f422
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gradio as gr
import base64
import io
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.lib.utils import ImageReader
from transformers import pipeline

# Load smaller faster model
summary_generator = pipeline("text2text-generation", model="google/flan-t5-small")

def generate_resume(name, job_title, email, phone, skills, education, experience, photo, use_ai):
    # Fast AI summary or fallback
    if use_ai:
        prompt = f"Write a passionate professional summary for {name}, applying as a {job_title}, skilled in {skills}, with experience in {experience}."
        summary = summary_generator(prompt, max_length=200)[0]["generated_text"]
    else:
        summary = f"{name} is a passionate {job_title} with skills in {skills}, and experience in {experience}."

    buffer = io.BytesIO()
    pdf = canvas.Canvas(buffer, pagesize=A4)
    width, height = A4
    y = height - 50

    pdf.setFont("Helvetica-Bold", 20)
    pdf.drawString(50, y, name)

    y -= 25
    pdf.setFont("Helvetica", 14)
    pdf.drawString(50, y, job_title)

    y -= 20
    pdf.setFont("Helvetica", 12)
    pdf.drawString(50, y, f"Email: {email}")
    y -= 20
    pdf.drawString(50, y, f"Phone: {phone}")

    if photo:
        image = ImageReader(photo)
        pdf.drawImage(image, width - 130, height - 130, width=80, height=80, mask='auto')

    y -= 40
    pdf.setFont("Helvetica-Bold", 16)
    pdf.drawString(50, y, "Professional Summary")
    y -= 20
    pdf.setFont("Helvetica", 12)
    for line in summary.split(". "):
        pdf.drawString(50, y, f"- {line.strip()}")
        y -= 18

    y -= 20
    pdf.setFont("Helvetica-Bold", 16)
    pdf.drawString(50, y, "Skills")
    y -= 20
    pdf.setFont("Helvetica", 12)
    for skill in skills.split(","):
        pdf.drawString(50, y, f"- {skill.strip()}")
        y -= 18

    y -= 20
    pdf.setFont("Helvetica-Bold", 16)
    pdf.drawString(50, y, "Education")
    y -= 20
    pdf.setFont("Helvetica", 12)
    for edu in education.split(";"):
        pdf.drawString(50, y, f"- {edu.strip()}")
        y -= 18

    y -= 20
    pdf.setFont("Helvetica-Bold", 16)
    pdf.drawString(50, y, "Experience")
    y -= 20
    pdf.setFont("Helvetica", 12)
    for exp in experience.split(";"):
        pdf.drawString(50, y, f"- {exp.strip()}")
        y -= 18

    pdf.save()
    buffer.seek(0)
    return buffer

# Launch Gradio App
iface = gr.Interface(
    fn=generate_resume,
    inputs=[
        gr.Text(label="Full Name"),
        gr.Text(label="Job Title"),
        gr.Text(label="Email"),
        gr.Text(label="Phone"),
        gr.Textbox(label="Skills (comma-separated)"),
        gr.Textbox(label="Education (use ; to separate items)"),
        gr.Textbox(label="Experience (use ; to separate items)"),
        gr.File(label="Profile Photo (optional)", type="binary"),
        gr.Checkbox(label="Use AI to auto-generate summary?", value=True)
    ],
    outputs=gr.File(label="๐Ÿ“„ Download Resume PDF"),
    title="๐Ÿš€ AI Resume Builder (Fast Edition)",
    description="Create a smart resume using FLAN-T5-Small for fast AI summary or manual fallback. Works great on Hugging Face Spaces!",
    live=True
)

iface.launch()