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: # Only add image and personal details on the first page 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) # Set text color to the specific blue from the template self.cell(0, 10, 'Katrin Winter', ln=True, align='L') self.set_text_color(0, 0, 0) # Reset text color to black 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) # Regular font for dates # Clean up the text to ensure no excessive spaces dates = self.clean_text(dates) role_company = self.clean_text(role_company) description = self.clean_text(description) # Print the dates in template-specific blue color and move the cursor 5 cm from the left margin self.set_text_color(31, 73, 125) # Set text color to the specific blue from the template self.cell(40, 8, dates, ln=False) self.set_text_color(0, 0, 0) # Reset text color to black self.set_x(70) # Move to 5 cm (50 mm) from the left margin self.set_font("Arial", 'B', 12) # Bold for role and company self.cell(0, 8, role_company, ln=True) self.set_x(70) # Move to 5 cm (50 mm) from the left margin for the description self.set_font("Arial", '', 12) # Regular font for description self.multi_cell(0, 8, description) self.ln(3) def add_education(self, dates, degree_institution, details): self.set_font("Arial", '', 12) # Regular font for dates # Clean up the text to ensure no excessive spaces dates = self.clean_text(dates) degree_institution = self.clean_text(degree_institution) details = self.clean_text(details) self.set_text_color(31, 73, 125) # Set text color to the specific blue from the template self.cell(40, 8, dates, ln=False) self.set_text_color(0, 0, 0) # Reset text color to black self.set_x(70) self.set_font("Arial", 'B', 12) # Bold for degree and institution self.cell(0, 8, degree_institution, ln=True) self.set_font("Arial", '', 12) # Regular font for details 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) # Regular font for dates # Clean up the text to ensure no excessive spaces year = self.clean_text(year) qualification_institution = self.clean_text(qualification_institution) details = self.clean_text(details) self.set_text_color(31, 73, 125) # Set text color to the specific blue from the template self.cell(40, 8, year, ln=False) self.set_text_color(0, 0, 0) # Reset text color to black self.set_x(70) self.set_font("Arial", 'B', 12) # Bold for qualification and institution self.cell(0, 8, qualification_institution, ln=True) self.set_font("Arial", '', 12) # Regular font for details 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): # Replace multiple spaces with a single space and strip the text text = re.sub(r'\s+', ' ', text).strip() return text def replace_special_characters(text): # Replace problematic characters with simpler ones 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): # Create PDF 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() # Replace special characters in all fields 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) # Experience 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) # Education 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) # Qualifications 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) # Skills pdf.section_title('Kenntnisse') pdf.add_skills(["Microsoft Office: Ausgezeichnet", "Adobe Creative Suite: Ausgezeichnet", "HTML / CSS / CMS: Fortgeschritten"]) # Languages pdf.section_title('Sprachen') pdf.add_languages(["Englisch: C1", "Spanisch: B2", "Italienisch: B2"]) # Interests pdf.section_title('Interessen') pdf.add_interests("Fotografie, Reisen, Bergsteigen, Höhlentauchen") # Save the PDF to a file pdf_file = "resume_with_image.pdf" pdf.output(pdf_file) # Create Word Document doc = Document() doc.add_heading(name, 0).alignment = WD_ALIGN_PARAGRAPH.LEFT # Add contact info p = doc.add_paragraph() p.add_run(contact_info) # Add sections with content 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 # Gradio Interface 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"), # Experience 1 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"), # Experience 2 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"), # Education 1 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"), # Education 2 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=""), # Qualification 1 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=""), # Qualification 2 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=""), # Other sections 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") ] examples = [ [ "profile_picture.jpg", "Alexander Meyer", "15. März 1985\nLeopoldstraße 45, 80333 München\nT +49 89 123 45 67\nE alexander.meyer@email.de", "03/2017 - jetzt", "Senior Marketing Manager\nTechSolutions AG, München", "Führung des Marketing-Teams, Entwicklung und Implementierung von Marketingstrategien, Budgetverwaltung und Performance-Analyse.", "05/2014 - 02/2017", "Marketing Specialist\nMedia Group GmbH, München", "Durchführung von Marktforschung, Unterstützung bei der Planung und Durchführung von Marketingkampagnen, Erstellung von Content und Werbematerialien.", "10/2005 - 07/2010", "Betriebswirtschaftslehre, LMU München", "Schwerpunkt Marketing, Abschlussarbeit: 'Die Rolle von Social Media im modernen Marketing.'", "09/2000 - 06/2005", "Wirtschaftsgymnasium, München", "Allgemeine Hochschulreife mit Schwerpunkt Wirtschaft.", "2018", "Google Analytics Zertifizierung, Google", "", "2016", "Projektmanagement, IHK München", "", "Microsoft Office: Ausgezeichnet\nGoogle Ads: Ausgezeichnet\nSEO/SEM: Fortgeschritten", "Englisch: C2\nFranzösisch: B1", "Laufen, Lesen, Reisen" ], [ "profile_picture2.jpg", "Lena Schmidt", "02. Februar 1990\nFriedrichstraße 10, 10117 Berlin\nT +49 30 765 4321\nE lena.schmidt@email.de", "06/2018 - jetzt", "Art Director\nCreative Agency Berlin", "Leitung des Design-Teams, Entwicklung visueller Konzepte, enge Zusammenarbeit mit Kunden zur Umsetzung kreativer Projekte.", "08/2015 - 05/2018", "Grafikdesignerin\nDesign Studio GmbH, Berlin", "Gestaltung von Print- und Digitalmedien, Erstellung von Logos, Layouts und Branding-Materialien.", "10/2008 - 07/2012", "Kommunikationsdesign, Universität der Künste Berlin", "Schwerpunkt Grafikdesign, Abschlussarbeit: 'Visuelle Kommunikation in der digitalen Ära.'", "09/2004 - 06/2008", "Gymnasium, Berlin", "Allgemeine Hochschulreife.", "2017", "UX/UI Design Kurs, Interaction Design Foundation", "", "2014", "Adobe Certified Expert, Adobe", "", "Adobe Creative Suite: Ausgezeichnet\nSketch: Fortgeschritten\nHTML/CSS: Grundkenntnisse", "Englisch: C1\nSpanisch: A2", "Fotografie, Zeichnen, Reisen" ], [ "profile_picture3.jpg", "Jonas Müller", "12. Dezember 1988\nAm Seestern 24, 40219 Düsseldorf\nT +49 211 987 6543\nE jonas.mueller@email.de", "01/2016 - jetzt", "IT Systems Engineer\nDataTech Solutions, Düsseldorf", "Verwaltung und Wartung von IT-Systemen, Netzwerkadministration, Sicherstellung der IT-Sicherheit, Betreuung der IT-Infrastruktur.", "09/2012 - 12/2015", "IT Support Specialist\nInfoTech GmbH, Düsseldorf", "Technischer Support für Mitarbeiter, Fehlerbehebung und Systemupdates, Betreuung der internen IT-Systeme.", "10/2007 - 07/2011", "Informatik, Heinrich-Heine-Universität Düsseldorf", "Schwerpunkt Netzwerkadministration, Abschlussarbeit: 'Sicherheitslösungen in modernen Netzwerken.'", "09/2002 - 06/2007", "Fachoberschule für Technik, Düsseldorf", "Allgemeine Fachhochschulreife mit Schwerpunkt Informationstechnik.", "2018", "Cisco Certified Network Associate (CCNA), Cisco", "", "2017", "ITIL Foundation, AXELOS", "", "Netzwerkadministration: Ausgezeichnet\nVirtualisierung (VMware, Hyper-V): Fortgeschritten\nLinux: Fortgeschritten", "Englisch: C1\nDeutsch: Muttersprache", "Programmieren, Wandern, Gaming" ] ] gr_interface = gr.Interface( fn=create_resume, inputs=inputs, outputs=outputs, title="Resume Creator", description="Create a resume similar to the provided template.", examples=examples ) gr_interface.launch()