AI-powered Resume Builder Python, HTML, CSS

👤 Sharing: AI
```python
import json
from collections import defaultdict

# --- Data Structures ---
class Section:
    def __init__(self, title, items=None):
        self.title = title
        self.items = items or []

    def add_item(self, item):
        self.items.append(item)

    def to_dict(self):
        return {"title": self.title, "items": self.items}


class Resume:
    def __init__(self, name="Your Name", email="your.email@example.com", phone="123-456-7890", linkedin="", github="", summary=""):
        self.name = name
        self.email = email
        self.phone = phone
        self.linkedin = linkedin
        self.github = github
        self.summary = summary
        self.sections = []

    def add_section(self, section):
        self.sections.append(section)

    def to_dict(self):
        return {
            "name": self.name,
            "email": self.email,
            "phone": self.phone,
            "linkedin": self.linkedin,
            "github": self.github,
            "summary": self.summary,
            "sections": [section.to_dict() for section in self.sections],
        }


# --- Core Functions ---
def create_resume(name, email, phone, linkedin, github, summary):
    resume = Resume(name, email, phone, linkedin, github, summary)
    return resume


def add_section_to_resume(resume, section_title):
    section = Section(section_title)
    resume.add_section(section)
    return section


def add_item_to_section(section, item_text):
    section.add_item(item_text)


# --- Resume Suggestion/Analysis (Simple placeholder - needs actual AI) ---
def suggest_skills(job_description):
    """
    Placeholder for AI-powered skill suggestion.  This just returns some
    dummy skills based on keywords in the job description.
    """
    job_description = job_description.lower()
    skills = []
    if "python" in job_description:
        skills.append("Python")
    if "javascript" in job_description:
        skills.append("JavaScript")
    if "data science" in job_description:
        skills.append("Data Science")
    if "machine learning" in job_description:
        skills.append("Machine Learning")
    if "cloud" in job_description:
        skills.append("Cloud Computing (AWS, Azure, GCP)")
    if "communication" in job_description:
        skills.append("Excellent Communication Skills")
    if "teamwork" in job_description:
        skills.append("Teamwork and Collaboration")
    return skills

def analyze_resume(resume, job_description):
    """
    Placeholder for AI-powered resume analysis.  Currently just returns
    a basic comparison of keywords.
    """
    resume_text = resume.name + " " + resume.summary
    for section in resume.sections:
        resume_text += " " + section.title + " " + " ".join(section.items)
    resume_text = resume_text.lower()
    job_description = job_description.lower()

    resume_keywords = set(resume_text.split())
    job_keywords = set(job_description.split())

    missing_keywords = job_keywords - resume_keywords
    matching_keywords = job_keywords.intersection(resume_keywords)

    analysis = {
        "missing_keywords": list(missing_keywords),
        "matching_keywords": list(matching_keywords),
    }
    return analysis


# --- HTML Generation ---
def generate_html(resume):
    html = f"""
    <!DOCTYPE html>
    <html>
    <head>
        <title>Resume - {resume.name}</title>
        <style>
            body {{
                font-family: Arial, sans-serif;
                margin: 20px;
            }}
            h1 {{
                color: #333;
            }}
            h2 {{
                color: #555;
                border-bottom: 1px solid #ccc;
                padding-bottom: 5px;
                margin-top: 20px;
            }}
            p {{
                line-height: 1.6;
            }}
            ul {{
                list-style-type: disc;
                padding-left: 20px;
            }}
            .contact-info {{
                margin-bottom: 20px;
            }}
        </style>
    </head>
    <body>
        <h1>{resume.name}</h1>
        <div class="contact-info">
            <p>Email: {resume.email}</p>
            <p>Phone: {resume.phone}</p>
            {"<p>LinkedIn: <a href='" + resume.linkedin + "'>" + resume.linkedin + "</a></p>" if resume.linkedin else ""}
            {"<p>GitHub: <a href='" + resume.github + "'>" + resume.github + "</a></p>" if resume.github else ""}
        </div>

        <h2>Summary</h2>
        <p>{resume.summary}</p>
    """

    for section in resume.sections:
        html += f"""
        <h2>{section.title}</h2>
        <ul>
        """
        for item in section.items:
            html += f"<li>{item}</li>"
        html += """
        </ul>
        """

    html += """
    </body>
    </html>
    """
    return html

# --- CSS Generation ---
def generate_css():
    css = """
    body {
        font-family: Arial, sans-serif;
        margin: 20px;
    }
    h1 {
        color: #333;
    }
    h2 {
        color: #555;
        border-bottom: 1px solid #ccc;
        padding-bottom: 5px;
        margin-top: 20px;
    }
    p {
        line-height: 1.6;
    }
    ul {
        list-style-type: disc;
        padding-left: 20px;
    }
    .contact-info {
        margin-bottom: 20px;
    }

    /* Add more styles here for enhanced visual appearance */
    """
    return css


# --- Example Usage (Illustrative) ---
if __name__ == "__main__":
    # 1. Create a resume
    my_resume = create_resume(
        name="Alice Smith",
        email="alice.smith@example.com",
        phone="555-123-4567",
        linkedin="linkedin.com/in/alicesmith",
        github="github.com/alicesmith",
        summary="Enthusiastic and detail-oriented software engineer with a passion for building innovative applications."
    )

    # 2. Add sections and items
    experience_section = add_section_to_resume(my_resume, "Experience")
    add_item_to_section(
        experience_section,
        "Software Engineer, Acme Corp (2020-2023): Developed and maintained web applications using Python and JavaScript."
    )
    add_item_to_section(
        experience_section,
        "Intern, Beta Inc (Summer 2019): Assisted with data analysis and machine learning projects."
    )

    education_section = add_section_to_resume(my_resume, "Education")
    add_item_to_section(
        education_section,
        "Bachelor of Science in Computer Science, University X (2016-2020)"
    )

    skills_section = add_section_to_resume(my_resume, "Skills")
    add_item_to_section(skills_section, "Python, JavaScript, HTML, CSS, SQL, Git")


    # 3. (Simulated) AI-powered skill suggestion
    job_description = "We are looking for a skilled Python developer with experience in web development and data analysis. Strong communication skills are a must."
    suggested_skills = suggest_skills(job_description)
    print("Suggested Skills based on job description:", suggested_skills)


    # 4. (Simulated) AI-powered resume analysis
    analysis_result = analyze_resume(my_resume, job_description)
    print("\nResume Analysis:")
    print("Missing Keywords:", analysis_result["missing_keywords"])
    print("Matching Keywords:", analysis_result["matching_keywords"])

    # 5. Generate HTML
    html_output = generate_html(my_resume)

    # 6. Save the HTML to a file (optional)
    with open("resume.html", "w") as f:
        f.write(html_output)

    print("\nResume generated in HTML format and saved to resume.html")

    # 7. Generate CSS (optional) and save it to a file
    css_output = generate_css()
    with open("style.css", "w") as f:
        f.write(css_output)

    print("CSS styling generated and saved to style.css")
```
👁️ Viewed: 19

Comments