Smart-mailing / app.py
monster07's picture
Update app.py
48b8a9c verified
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()