File size: 2,120 Bytes
a645179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95e9edd
a645179
 
6032d94
95e9edd
a645179
 
95e9edd
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
import json
import os
import fitz  # PyMuPDF for PDF parsing
import docx

from google import genai
from google.genai import types

# API key as envirnomental varibale
api_key = os.environ.get("GOOGLE_API_KEY")


# Function to extract text from PDFs
def extract_text_from_pdf(file_path):
    text = ""
    with fitz.open(file_path) as doc:
        for page in doc:
            text += page.get_text()
    return text


# Function to extract text from DOCX files
def extract_text_from_docx(file_path):
    doc = docx.Document(file_path)
    return "\n".join([para.text for para in doc.paragraphs])


def process_resume(file_path):
    if file_path.endswith(".pdf"):
        resume_text = extract_text_from_pdf(file_path)
    elif file_path.endswith(".docx"):
        resume_text = extract_text_from_docx(file_path)
    else:
        print(f"Skipping unsupported file: {file_path}")
        return None

    # Extract structured resume data
    structured_data = extract_resume_data(resume_text)
    return structured_data


# Function to parse resume and extract structured data using Gemini
def extract_resume_data(resume_text):
    prompt = f"""
    Extract the following details from the resume:
    - Full Name(first word capital, eg: "Krish Bakshi", "Uzumaki Naruto")
    - Email
    - Phone Number
    - Work Experience (Company, Role, Contribution and work)
    - Projects(Project, Tech Stack/Tehnology)
    - Education (Degree, University, Year) /(Only first word capital)/
    - Skills
    Provide the data in a structured JSON format.
    
    Resume:
    {resume_text}
    """

    client = genai.Client(api_key=api_key)
    response = client.models.generate_content(
        model="gemini-2.0-flash",
        contents=prompt,
    )
    return response.text  # Gemini will return structured JSON


# Response Pipeline
def generate_email(prompt, template):
    client = genai.Client(api_key=api_key)
    response = client.models.generate_content(
        model="gemini-2.0-flash",
        config=types.GenerateContentConfig(system_instruction=template),
        contents=[prompt],
    )
    return response.text