Spaces:
Running
Running
File size: 5,619 Bytes
ff73789 b54ceac ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae b54ceac ff73789 b54ceac ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 bd4baae ff73789 b54ceac ff73789 b54ceac ff73789 b54ceac ff73789 b54ceac ff73789 b54ceac ff73789 b54ceac ff73789 bd4baae ff73789 bd4baae b54ceac bd4baae |
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
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()
|