|
import gradio as gr |
|
from fpdf import FPDF |
|
import re |
|
from docx import Document |
|
from docx.shared import Pt, RGBColor |
|
from docx.enum.text import WD_ALIGN_PARAGRAPH |
|
|
|
class CustomPDF(FPDF): |
|
def header(self): |
|
if self.page_no() == 1: |
|
if self.image_path: |
|
self.image(self.image_path, x=150, y=20, w=40) |
|
|
|
self.set_font("Arial", 'B', 20) |
|
self.set_text_color(31, 73, 125) |
|
self.cell(0, 10, 'Katrin Winter', ln=True, align='L') |
|
self.set_text_color(0, 0, 0) |
|
self.set_font("Arial", '', 12) |
|
self.cell(0, 8, '10. Oktober 1991', ln=True, align='L') |
|
self.cell(0, 8, 'Kaiserstraße 1, 1010 Wien', ln=True, align='L') |
|
self.cell(0, 8, 'T +43 650 123 45 67', ln=True, align='L') |
|
self.cell(0, 8, 'E katrin.winter@email.at', ln=True, align='L') |
|
self.ln(10) |
|
|
|
def section_title(self, title): |
|
self.set_font("Arial", 'B', 14) |
|
self.cell(0, 10, title, ln=True) |
|
self.ln(2) |
|
|
|
def add_experience(self, dates, role_company, description): |
|
self.set_font("Arial", '', 12) |
|
|
|
|
|
dates = self.clean_text(dates) |
|
role_company = self.clean_text(role_company) |
|
description = self.clean_text(description) |
|
|
|
|
|
self.set_text_color(31, 73, 125) |
|
self.cell(40, 8, dates, ln=False) |
|
self.set_text_color(0, 0, 0) |
|
self.set_x(70) |
|
self.set_font("Arial", 'B', 12) |
|
self.cell(0, 8, role_company, ln=True) |
|
|
|
self.set_x(70) |
|
self.set_font("Arial", '', 12) |
|
self.multi_cell(0, 8, description) |
|
self.ln(3) |
|
|
|
def add_education(self, dates, degree_institution, details): |
|
self.set_font("Arial", '', 12) |
|
|
|
|
|
dates = self.clean_text(dates) |
|
degree_institution = self.clean_text(degree_institution) |
|
details = self.clean_text(details) |
|
|
|
self.set_text_color(31, 73, 125) |
|
self.cell(40, 8, dates, ln=False) |
|
self.set_text_color(0, 0, 0) |
|
self.set_x(70) |
|
self.set_font("Arial", 'B', 12) |
|
self.cell(0, 8, degree_institution, ln=True) |
|
self.set_font("Arial", '', 12) |
|
self.set_x(70) |
|
self.multi_cell(0, 8, details) |
|
self.ln(3) |
|
|
|
def add_qualification(self, year, qualification_institution, details): |
|
self.set_font("Arial", '', 12) |
|
|
|
|
|
year = self.clean_text(year) |
|
qualification_institution = self.clean_text(qualification_institution) |
|
details = self.clean_text(details) |
|
|
|
self.set_text_color(31, 73, 125) |
|
self.cell(40, 8, year, ln=False) |
|
self.set_text_color(0, 0, 0) |
|
self.set_x(70) |
|
self.set_font("Arial", 'B', 12) |
|
self.cell(0, 8, qualification_institution, ln=True) |
|
self.set_font("Arial", '', 12) |
|
self.set_x(70) |
|
self.multi_cell(0, 8, details) |
|
self.ln(2) |
|
|
|
def add_skills(self, skills): |
|
self.set_font("Arial", '', 12) |
|
for skill in skills: |
|
self.set_x(70) |
|
self.cell(0, 8, f"{skill}", ln=True) |
|
self.ln(3) |
|
|
|
def add_languages(self, languages): |
|
self.set_font("Arial", '', 12) |
|
for language in languages: |
|
self.set_x(70) |
|
self.cell(0, 8, f"{language}", ln=True) |
|
self.ln(3) |
|
|
|
def add_interests(self, interests): |
|
self.set_font("Arial", '', 12) |
|
self.set_x(70) |
|
self.multi_cell(0, 8, f"{interests}") |
|
self.ln(3) |
|
|
|
def set_image(self, image_path): |
|
self.image_path = image_path |
|
|
|
def clean_text(self, text): |
|
|
|
text = re.sub(r'\s+', ' ', text).strip() |
|
return text |
|
|
|
def replace_special_characters(text): |
|
|
|
return text.replace("–", "-").replace("’", "'").replace("‘", "'").replace("“", '"').replace("”", '"') |
|
|
|
def create_resume(image, name, contact_info, |
|
experience_dates_1, experience_role_company_1, experience_description_1, |
|
experience_dates_2, experience_role_company_2, experience_description_2, |
|
education_dates_1, education_degree_institution_1, education_details_1, |
|
education_dates_2, education_degree_institution_2, education_details_2, |
|
qualification_year_1, qualification_institution_1, qualification_details_1, |
|
qualification_year_2, qualification_institution_2, qualification_details_2, |
|
skills, languages, interests): |
|
|
|
|
|
pdf = CustomPDF(orientation='P', unit='mm', format='A4') |
|
pdf.set_left_margin(20) |
|
pdf.set_right_margin(20) |
|
pdf.set_top_margin(20) |
|
pdf.set_auto_page_break(auto=True, margin=20) |
|
|
|
pdf.set_image(image) |
|
pdf.add_page() |
|
|
|
|
|
name = replace_special_characters(name) |
|
contact_info = replace_special_characters(contact_info) |
|
experience_dates_1 = replace_special_characters(experience_dates_1) |
|
experience_role_company_1 = replace_special_characters(experience_role_company_1) |
|
experience_description_1 = replace_special_characters(experience_description_1) |
|
experience_dates_2 = replace_special_characters(experience_dates_2) |
|
experience_role_company_2 = replace_special_characters(experience_role_company_2) |
|
experience_description_2 = replace_special_characters(experience_description_2) |
|
education_dates_1 = replace_special_characters(education_dates_1) |
|
education_degree_institution_1 = replace_special_characters(education_degree_institution_1) |
|
education_details_1 = replace_special_characters(education_details_1) |
|
education_dates_2 = replace_special_characters(education_dates_2) |
|
education_degree_institution_2 = replace_special_characters(education_degree_institution_2) |
|
education_details_2 = replace_special_characters(education_details_2) |
|
qualification_year_1 = replace_special_characters(qualification_year_1) |
|
qualification_institution_1 = replace_special_characters(qualification_institution_1) |
|
qualification_details_1 = replace_special_characters(qualification_details_1) |
|
qualification_year_2 = replace_special_characters(qualification_year_2) |
|
qualification_institution_2 = replace_special_characters(qualification_institution_2) |
|
qualification_details_2 = replace_special_characters(qualification_details_2) |
|
skills = replace_special_characters(skills) |
|
languages = replace_special_characters(languages) |
|
interests = replace_special_characters(interests) |
|
|
|
|
|
pdf.section_title('Berufserfahrung') |
|
pdf.add_experience(experience_dates_1, experience_role_company_1, experience_description_1) |
|
pdf.add_experience(experience_dates_2, experience_role_company_2, experience_description_2) |
|
|
|
|
|
pdf.section_title('Ausbildung') |
|
pdf.add_education(education_dates_1, education_degree_institution_1, education_details_1) |
|
pdf.add_education(education_dates_2, education_degree_institution_2, education_details_2) |
|
|
|
|
|
pdf.section_title('Qualifikationen') |
|
pdf.add_qualification(qualification_year_1, qualification_institution_1, qualification_details_1) |
|
pdf.add_qualification(qualification_year_2, qualification_institution_2, qualification_details_2) |
|
|
|
|
|
pdf.section_title('Kenntnisse') |
|
pdf.add_skills(["Microsoft Office: Ausgezeichnet", "Adobe Creative Suite: Ausgezeichnet", "HTML / CSS / CMS: Fortgeschritten"]) |
|
|
|
|
|
pdf.section_title('Sprachen') |
|
pdf.add_languages(["Englisch: C1", "Spanisch: B2", "Italienisch: B2"]) |
|
|
|
|
|
pdf.section_title('Interessen') |
|
pdf.add_interests("Fotografie, Reisen, Bergsteigen, Höhlentauchen") |
|
|
|
|
|
pdf_file = "resume_with_image.pdf" |
|
pdf.output(pdf_file) |
|
|
|
|
|
doc = Document() |
|
doc.add_heading('Katrin Winter', 0).alignment = WD_ALIGN_PARAGRAPH.LEFT |
|
|
|
|
|
p = doc.add_paragraph() |
|
p.add_run('10. Oktober 1991\nKaiserstraße 1, 1010 Wien\nT +43 650 123 45 67\nE katrin.winter@email.at') |
|
|
|
|
|
doc.add_heading('Berufserfahrung', level=1) |
|
doc.add_paragraph(f'{experience_dates_1} - {experience_role_company_1}\n{experience_description_1}') |
|
doc.add_paragraph(f'{experience_dates_2} - {experience_role_company_2}\n{experience_description_2}') |
|
|
|
doc.add_heading('Ausbildung', level=1) |
|
doc.add_paragraph(f'{education_dates_1} - {education_degree_institution_1}\n{education_details_1}') |
|
doc.add_paragraph(f'{education_dates_2} - {education_degree_institution_2}\n{education_details_2}') |
|
|
|
doc.add_heading('Qualifikationen', level=1) |
|
doc.add_paragraph(f'{qualification_year_1} - {qualification_institution_1}\n{qualification_details_1}') |
|
doc.add_paragraph(f'{qualification_year_2} - {qualification_institution_2}\n{qualification_details_2}') |
|
|
|
doc.add_heading('Kenntnisse', level=1) |
|
doc.add_paragraph(skills) |
|
|
|
doc.add_heading('Sprachen', level=1) |
|
doc.add_paragraph(languages) |
|
|
|
doc.add_heading('Interessen', level=1) |
|
doc.add_paragraph(interests) |
|
|
|
doc_file = "resume_with_image.docx" |
|
doc.save(doc_file) |
|
|
|
return pdf_file, doc_file |
|
|
|
|
|
inputs = [ |
|
gr.Image(type="filepath", label="Profile Picture"), |
|
gr.Textbox(label="Name", placeholder="Katrin Winter", value="Katrin Winter"), |
|
gr.Textbox(label="Contact Information", placeholder="Address, Phone, Email", lines=4, value="10. Oktober 1991\nKaiserstraße 1, 1010 Wien\nT +43 650 123 45 67\nE katrin.winter@email.at"), |
|
|
|
|
|
gr.Textbox(label="Experience 1 Dates", placeholder="02/2019 - jetzt", value="02/2019 - jetzt"), |
|
gr.Textbox(label="Experience 1 Role & Company", placeholder="B2B Marketing Manager\nStepcompany, Wien", value="B2B Marketing Manager\nStepcompany, Wien"), |
|
gr.Textbox(label="Experience 1 Description", placeholder="Selbstständige Organisation und Betreuung von Messen und Kundenevents, Aufbereitung von Sales- und Marketing-Materialien", lines=3, value="Selbstständige Organisation und Betreuung von Messen und Kundenevents, Aufbereitung von Sales- und Marketing-Materialien"), |
|
|
|
|
|
gr.Textbox(label="Experience 2 Dates", placeholder="02/2018 - 01/2019", value="02/2018 - 01/2019"), |
|
gr.Textbox(label="Experience 2 Role & Company", placeholder="Marketing Assistenz\nStepcompany, Wien", value="Marketing Assistenz\nStepcompany, Wien"), |
|
gr.Textbox(label="Experience 2 Description", placeholder="Abwicklung und Durchführung diverser Kundenprojekte, Einholung von Angeboten und Recherche von Give-Aways", lines=3, value="Abwicklung und Durchführung diverser Kundenprojekte, Einholung von Angeboten und Recherche von Give-Aways"), |
|
|
|
|
|
gr.Textbox(label="Education 1 Dates", placeholder="02/2011 - 09/2016", value="02/2011 - 09/2016"), |
|
gr.Textbox(label="Education 1 Degree & Institution", placeholder="Wirtschafts- und Sozialwissenschaften, WU Wien", value="Wirtschafts- und Sozialwissenschaften, WU Wien"), |
|
gr.Textbox(label="Education 1 Details", placeholder="Schwerpunkt Marketing, Abschlussarbeit: Marktorientiertes Business Development", lines=3, value="Schwerpunkt Marketing, Abschlussarbeit: Marktorientiertes Business Development"), |
|
|
|
|
|
gr.Textbox(label="Education 2 Dates", placeholder="02/2006 - 05/2011", value="02/2006 - 05/2011"), |
|
gr.Textbox(label="Education 2 Degree & Institution", placeholder="Marketingmanagement, HAK I, Vienna Business School", value="Marketingmanagement, HAK I, Vienna Business School"), |
|
gr.Textbox(label="Education 2 Details", placeholder="Details about this degree", lines=3, value=""), |
|
|
|
|
|
gr.Textbox(label="Qualification 1 Year", placeholder="2019", value="2019"), |
|
gr.Textbox(label="Qualification 1 Institution", placeholder="Ausbildung Grafikdesign, Webeakademie Wien", value="Ausbildung Grafikdesign, Webeakademie Wien"), |
|
gr.Textbox(label="Qualification 1 Details", placeholder="Details about this qualification", lines=3, value=""), |
|
|
|
|
|
gr.Textbox(label="Qualification 2 Year", placeholder="2018", value="2018"), |
|
gr.Textbox(label="Qualification 2 Institution", placeholder="Online-Marketing Basis-Lehrgang, Online Marketing Forum, Wien", value="Online-Marketing Basis-Lehrgang, Online Marketing Forum, Wien"), |
|
gr.Textbox(label="Qualification 2 Details", placeholder="Details about this qualification", lines=3, value=""), |
|
|
|
|
|
gr.TextArea(label="Kenntnisse", placeholder="Enter skills here", lines=3, value=""" |
|
Microsoft Office: Ausgezeichnet |
|
Adobe Creative Suite: Ausgezeichnet |
|
HTML / CSS / CMS: Fortgeschritten |
|
"""), |
|
gr.TextArea(label="Sprachen", placeholder="Enter languages here", lines=3, value=""" |
|
Englisch: C1 |
|
Spanisch: B2 |
|
Italienisch: B2 |
|
"""), |
|
gr.TextArea(label="Interessen", placeholder="Enter interests here", lines=2, value="Fotografie, Reisen, Bergsteigen, Höhlentauchen") |
|
] |
|
|
|
outputs = [ |
|
gr.File(label="Download Your Resume as PDF"), |
|
gr.File(label="Download Your Resume as DOCX") |
|
] |
|
|
|
gr_interface = gr.Interface( |
|
fn=create_resume, |
|
inputs=inputs, |
|
outputs=outputs, |
|
title="Resume Creator", |
|
description="Create a resume similar to the provided template.", |
|
) |
|
|
|
gr_interface.launch() |
|
|