CV / app.py
atifsial123's picture
Update app.py
b54ceac verified
import gradio as gr
from fpdf import FPDF
from PIL import Image
# Function to generate the CV PDF with an uploaded photo
def generate_pdf(full_name, phone, email, linkedin, address, summary, degree, university, graduation, courses, work_title, work_company, work_dates, work_responsibility, skills, achievements, extracurricular, certifications, photo):
pdf = FPDF()
pdf.add_page()
# Add Title
pdf.set_font("Arial", 'B', 16)
pdf.cell(200, 10, txt="CV", ln=True, align='C')
# Add photo if provided
if photo:
pdf.image(photo, x=10, y=10, w=30)
# Move the cursor below the image
pdf.ln(40)
# Personal Information
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Personal Information", ln=True)
pdf.set_font("Arial", '', 12)
pdf.cell(200, 10, txt=f"Full Name: {full_name}", ln=True)
pdf.cell(200, 10, txt=f"Phone: {phone}", ln=True)
pdf.cell(200, 10, txt=f"Email: {email}", ln=True)
pdf.cell(200, 10, txt=f"LinkedIn: {linkedin}", ln=True)
pdf.cell(200, 10, txt=f"Address: {address}", ln=True)
# Professional Summary/Objective
pdf.cell(200, 10, txt="", ln=True)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Professional Summary/Objective", ln=True)
pdf.set_font("Arial", '', 12)
pdf.multi_cell(200, 10, txt=summary)
# Education
pdf.cell(200, 10, txt="", ln=True)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Education", ln=True)
pdf.set_font("Arial", '', 12)
pdf.cell(200, 10, txt=f"Degree: {degree}", ln=True)
pdf.cell(200, 10, txt=f"University: {university}", ln=True)
pdf.cell(200, 10, txt=f"Graduation Date: {graduation}", ln=True)
if courses:
pdf.multi_cell(200, 10, txt=f"Relevant Courses or Specializations: {courses}")
# Work Experience
pdf.cell(200, 10, txt="", ln=True)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Work Experience", ln=True)
pdf.set_font("Arial", '', 12)
pdf.cell(200, 10, txt=f"Job Title: {work_title}", ln=True)
pdf.cell(200, 10, txt=f"Company: {work_company}", ln=True)
pdf.cell(200, 10, txt=f"Dates: {work_dates}", ln=True)
pdf.multi_cell(200, 10, txt=f"Responsibilities and Achievements: {work_responsibility}")
# Skills
pdf.cell(200, 10, txt="", ln=True)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Skills", ln=True)
pdf.set_font("Arial", '', 12)
pdf.multi_cell(200, 10, txt=skills)
# Achievements
pdf.cell(200, 10, txt="", ln=True)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Achievements", ln=True)
pdf.set_font("Arial", '', 12)
pdf.multi_cell(200, 10, txt=achievements)
# Volunteer/Extracurricular Activities
pdf.cell(200, 10, txt="", ln=True)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Volunteer/Relevant Extracurricular Activities", ln=True)
pdf.set_font("Arial", '', 12)
pdf.multi_cell(200, 10, txt=extracurricular)
# Certifications/Licenses
pdf.cell(200, 10, txt="", ln=True)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="Certifications/Licenses", ln=True)
pdf.set_font("Arial", '', 12)
pdf.multi_cell(200, 10, txt=certifications)
# Save the PDF
pdf_file = "generated_cv_with_photo.pdf"
pdf.output(pdf_file)
return pdf_file
# Gradio interface to get input from user and generate CV with photo
def create_cv_with_photo(full_name, phone, email, linkedin, address, summary, degree, university, graduation, courses, work_title, work_company, work_dates, work_responsibility, skills, achievements, extracurricular, certifications, photo):
# Save the uploaded photo temporarily
if photo:
photo.save("uploaded_photo.jpg")
pdf_file = generate_pdf(full_name, phone, email, linkedin, address, summary, degree, university, graduation, courses, work_title, work_company, work_dates, work_responsibility, skills, achievements, extracurricular, certifications, "uploaded_photo.jpg")
else:
pdf_file = generate_pdf(full_name, phone, email, linkedin, address, summary, degree, university, graduation, courses, work_title, work_company, work_dates, work_responsibility, skills, achievements, extracurricular, certifications, None)
return pdf_file
# Gradio interface with photo upload
iface = gr.Interface(
fn=create_cv_with_photo,
inputs=[
gr.Textbox(label="Full Name"),
gr.Textbox(label="Phone Number"),
gr.Textbox(label="Email"),
gr.Textbox(label="LinkedIn Profile"),
gr.Textbox(label="Address"),
gr.Textbox(label="Professional Summary/Objective", lines=2),
gr.Textbox(label="Degree"),
gr.Textbox(label="University/Institution"),
gr.Textbox(label="Graduation Date"),
gr.Textbox(label="Relevant Courses or Specializations", lines=2),
gr.Textbox(label="Work Title"),
gr.Textbox(label="Company Name"),
gr.Textbox(label="Dates of Employment"),
gr.Textbox(label="Work Responsibilities and Achievements", lines=4),
gr.Textbox(label="Skills", lines=3),
gr.Textbox(label="Achievements", lines=2),
gr.Textbox(label="Volunteer/Extracurricular Activities", lines=2),
gr.Textbox(label="Certifications/Licenses", lines=2),
gr.Image(type="pil", label="Upload Photo (optional)"),
],
outputs=gr.File(label="Download PDF CV"),
title="CV Generator with Photo",
description="Fill in the fields to generate your PDF CV. You can also upload a photo to be included."
)
# Launch the interface
iface.launch()