monster07 commited on
Commit
e27f422
·
verified ·
1 Parent(s): 4b1f92f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -41
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 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()
 
 
 
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()