Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fpdf import FPDF
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Function to generate the CV PDF with an uploaded photo
|
6 |
+
def generate_pdf(full_name, phone, email, linkedin, address, title, summary, degree, university, graduation, gpa, work_title, work_company, work_dates, work_responsibility, skills, certifications, projects, awards, references, photo):
|
7 |
+
pdf = FPDF()
|
8 |
+
pdf.add_page()
|
9 |
+
|
10 |
+
# Add Title
|
11 |
+
pdf.set_font("Arial", 'B', 16)
|
12 |
+
pdf.cell(200, 10, txt="CV", ln=True, align='C') # Changed title to "CV"
|
13 |
+
|
14 |
+
# Add photo if provided
|
15 |
+
if photo:
|
16 |
+
pdf.image(photo, x=10, y=10, w=30) # Adjust image placement and size
|
17 |
+
|
18 |
+
# Move the cursor below the image
|
19 |
+
pdf.ln(40)
|
20 |
+
|
21 |
+
# Personal Information
|
22 |
+
pdf.set_font("Arial", 'B', 12)
|
23 |
+
pdf.cell(200, 10, txt="Personal Information", ln=True)
|
24 |
+
pdf.set_font("Arial", '', 12)
|
25 |
+
pdf.cell(200, 10, txt=f"Full Name: {full_name}", ln=True)
|
26 |
+
pdf.cell(200, 10, txt=f"Phone: {phone}", ln=True)
|
27 |
+
pdf.cell(200, 10, txt=f"Email: {email}", ln=True)
|
28 |
+
pdf.cell(200, 10, txt=f"LinkedIn: {linkedin}", ln=True)
|
29 |
+
pdf.cell(200, 10, txt=f"Address: {address}", ln=True)
|
30 |
+
pdf.cell(200, 10, txt=f"Professional Title: {title}", ln=True)
|
31 |
+
|
32 |
+
# Professional Summary
|
33 |
+
pdf.cell(200, 10, txt="", ln=True) # Empty line
|
34 |
+
pdf.set_font("Arial", 'B', 12)
|
35 |
+
pdf.cell(200, 10, txt="Professional Summary", ln=True)
|
36 |
+
pdf.set_font("Arial", '', 12)
|
37 |
+
pdf.multi_cell(200, 10, txt=summary)
|
38 |
+
|
39 |
+
# Education
|
40 |
+
pdf.cell(200, 10, txt="", ln=True)
|
41 |
+
pdf.set_font("Arial", 'B', 12)
|
42 |
+
pdf.cell(200, 10, txt="Education", ln=True)
|
43 |
+
pdf.set_font("Arial", '', 12)
|
44 |
+
pdf.cell(200, 10, txt=f"Degree: {degree}", ln=True)
|
45 |
+
pdf.cell(200, 10, txt=f"University: {university}", ln=True)
|
46 |
+
pdf.cell(200, 10, txt=f"Graduation Date: {graduation}", ln=True)
|
47 |
+
if gpa:
|
48 |
+
pdf.cell(200, 10, txt=f"GPA: {gpa}", ln=True)
|
49 |
+
|
50 |
+
# Work Experience
|
51 |
+
pdf.cell(200, 10, txt="", ln=True)
|
52 |
+
pdf.set_font("Arial", 'B', 12)
|
53 |
+
pdf.cell(200, 10, txt="Work Experience", ln=True)
|
54 |
+
pdf.set_font("Arial", '', 12)
|
55 |
+
pdf.cell(200, 10, txt=f"Job Title: {work_title}", ln=True)
|
56 |
+
pdf.cell(200, 10, txt=f"Company: {work_company}", ln=True)
|
57 |
+
pdf.cell(200, 10, txt=f"Dates: {work_dates}", ln=True)
|
58 |
+
pdf.multi_cell(200, 10, txt=f"Responsibilities: {work_responsibility}")
|
59 |
+
|
60 |
+
# Skills
|
61 |
+
pdf.cell(200, 10, txt="", ln=True)
|
62 |
+
pdf.set_font("Arial", 'B', 12)
|
63 |
+
pdf.cell(200, 10, txt="Skills", ln=True)
|
64 |
+
pdf.set_font("Arial", '', 12)
|
65 |
+
pdf.multi_cell(200, 10, txt=skills)
|
66 |
+
|
67 |
+
# Certifications
|
68 |
+
pdf.cell(200, 10, txt="", ln=True)
|
69 |
+
pdf.set_font("Arial", 'B', 12)
|
70 |
+
pdf.cell(200, 10, txt="Certifications", ln=True)
|
71 |
+
pdf.set_font("Arial", '', 12)
|
72 |
+
pdf.multi_cell(200, 10, txt=certifications)
|
73 |
+
|
74 |
+
# Projects
|
75 |
+
pdf.cell(200, 10, txt="", ln=True)
|
76 |
+
pdf.set_font("Arial", 'B', 12)
|
77 |
+
pdf.cell(200, 10, txt="Projects", ln=True)
|
78 |
+
pdf.set_font("Arial", '', 12)
|
79 |
+
pdf.multi_cell(200, 10, txt=projects)
|
80 |
+
|
81 |
+
# Awards
|
82 |
+
pdf.cell(200, 10, txt="", ln=True)
|
83 |
+
pdf.set_font("Arial", 'B', 12)
|
84 |
+
pdf.cell(200, 10, txt="Awards and Achievements", ln=True)
|
85 |
+
pdf.set_font("Arial", '', 12)
|
86 |
+
pdf.multi_cell(200, 10, txt=awards)
|
87 |
+
|
88 |
+
# References
|
89 |
+
pdf.cell(200, 10, txt="", ln=True)
|
90 |
+
pdf.set_font("Arial", 'B', 12)
|
91 |
+
pdf.cell(200, 10, txt="References", ln=True)
|
92 |
+
pdf.set_font("Arial", '', 12)
|
93 |
+
pdf.multi_cell(200, 10, txt=references)
|
94 |
+
|
95 |
+
# Save the PDF
|
96 |
+
pdf_file = "generated_cv_with_photo.pdf"
|
97 |
+
pdf.output(pdf_file)
|
98 |
+
|
99 |
+
return pdf_file
|
100 |
+
|
101 |
+
# Gradio interface to get input from user and generate CV with photo
|
102 |
+
def create_cv_with_photo(full_name, phone, email, linkedin, address, title, summary, degree, university, graduation, gpa, work_title, work_company, work_dates, work_responsibility, skills, certifications, projects, awards, references, photo):
|
103 |
+
# Save the uploaded photo temporarily
|
104 |
+
if photo:
|
105 |
+
photo.save("uploaded_photo.jpg")
|
106 |
+
pdf_file = generate_pdf(full_name, phone, email, linkedin, address, title, summary, degree, university, graduation, gpa, work_title, work_company, work_dates, work_responsibility, skills, certifications, projects, awards, references, "uploaded_photo.jpg")
|
107 |
+
else:
|
108 |
+
pdf_file = generate_pdf(full_name, phone, email, linkedin, address, title, summary, degree, university, graduation, gpa, work_title, work_company, work_dates, work_responsibility, skills, certifications, projects, awards, references, None)
|
109 |
+
|
110 |
+
return pdf_file
|
111 |
+
|
112 |
+
# Gradio interface with photo upload
|
113 |
+
iface = gr.Interface(
|
114 |
+
fn=create_cv_with_photo,
|
115 |
+
inputs=[
|
116 |
+
gr.Textbox(label="Full Name"),
|
117 |
+
gr.Textbox(label="Phone Number"),
|
118 |
+
gr.Textbox(label="Email"),
|
119 |
+
gr.Textbox(label="LinkedIn Profile"),
|
120 |
+
gr.Textbox(label="Address"),
|
121 |
+
gr.Textbox(label="Professional Title"),
|
122 |
+
gr.Textbox(label="Professional Summary"),
|
123 |
+
gr.Textbox(label="Degree"),
|
124 |
+
gr.Textbox(label="University/Institution"),
|
125 |
+
gr.Textbox(label="Graduation Date"),
|
126 |
+
gr.Textbox(label="GPA (optional)"),
|
127 |
+
gr.Textbox(label="Work Title"),
|
128 |
+
gr.Textbox(label="Company Name"),
|
129 |
+
gr.Textbox(label="Dates of Employment"),
|
130 |
+
gr.Textbox(label="Work Responsibilities", lines=4),
|
131 |
+
gr.Textbox(label="Skills", lines=3),
|
132 |
+
gr.Textbox(label="Certifications and Training", lines=2),
|
133 |
+
gr.Textbox(label="Projects", lines=2),
|
134 |
+
gr.Textbox(label="Awards", lines=2),
|
135 |
+
gr.Textbox(label="References", lines=2),
|
136 |
+
gr.Image(type="pil", label="Upload Photo (optional)"),
|
137 |
+
],
|
138 |
+
outputs=gr.File(label="Download PDF CV"),
|
139 |
+
title="CV Generator with Photo",
|
140 |
+
description="Fill in the fields to generate your PDF CV. You can also upload a photo to be included."
|
141 |
+
)
|
142 |
+
|
143 |
+
# Launch the interface
|
144 |
+
iface.launch()
|