Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,60 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import base64
|
| 3 |
-
import pdfkit
|
| 4 |
from jinja2 import Template
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
with open("template.html", "r", encoding="utf-8") as f:
|
| 8 |
template_html = f.read()
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 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 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
return "resume.pdf"
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
fn=generate_resume,
|
| 50 |
-
inputs=inputs,
|
| 51 |
outputs=gr.File(label="📄 Download Resume PDF"),
|
| 52 |
-
title="
|
| 53 |
-
description="
|
| 54 |
-
)
|
|
|
|
|
|
|
|
|
| 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"),
|
| 48 |
+
gr.Text(label="Email"),
|
| 49 |
+
gr.Text(label="Phone"),
|
| 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()
|