File size: 5,605 Bytes
5302799
 
b89bba2
66bf5cc
 
5302799
 
 
 
66bf5cc
c9c2072
 
97ad829
66bf5cc
c9052ff
 
66bf5cc
 
331c146
 
 
 
 
 
66bf5cc
 
 
 
 
 
 
 
 
c9c2072
66bf5cc
331c146
66bf5cc
288df6b
 
 
 
 
 
5302799
 
66bf5cc
 
 
 
 
 
 
 
 
288df6b
66bf5cc
 
 
 
 
 
c9c2072
66bf5cc
331c146
288df6b
 
 
 
 
 
 
 
5302799
66bf5cc
 
c9c2072
66bf5cc
 
 
 
 
 
c9c2072
66bf5cc
c9c2072
331c146
c9c2072
288df6b
 
 
 
 
 
c9c2072
5302799
 
66bf5cc
 
 
 
 
 
 
c9c2072
66bf5cc
 
5302799
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66bf5cc
5302799
288df6b
 
5302799
 
 
 
 
c9c2072
 
5302799
 
 
 
 
 
 
 
 
 
c9c2072
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import gradio as gr
from huggingface_hub import InferenceClient
from PyPDF2 import PdfReader
import requests
from bs4 import BeautifulSoup

# Initialize the Inference Client
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")

def extract_text_from_pdf(file):
    if file is None:
        return ""
    reader = PdfReader(file)
    text = ""
    for page in reader.pages:
        text += page.extract_text()
    return text

def parse_score(score_text):
    try:
        return float(score_text.strip('%').strip()) / 100
    except ValueError:
        return None

def ats_friendly_checker(file):
    resume_text = extract_text_from_pdf(file)
    system_message = "Evaluate the following resume for ATS-friendliness and provide a score and feedback."
    message = resume_text
    response = client.chat_completion(
        [{"role": "system", "content": system_message}, {"role": "user", "content": message}],
        max_tokens=512,
        temperature=0.7,
        top_p=0.95
    ).choices[0].message.content
    
    score_text = response.split("\n")[0].split(":")[-1].strip()
    feedback = "\n".join(response.split("\n")[1:])
    score = parse_score(score_text)
    if score is not None:
        score *= 100  # Convert to percentage
    else:
        score = 0
        feedback = "Error parsing score from the response."
    return score, feedback

def scrape_job_description(url):
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'html.parser')
    job_description = soup.get_text(separator=" ", strip=True)
    return job_description

def resume_match_checker(file, job_url):
    resume_text = extract_text_from_pdf(file)
    job_description = scrape_job_description(job_url)
    system_message = "Compare the following resume with the job description and provide a match score and feedback."
    message = f"Resume: {resume_text}\n\nJob Description: {job_description}"
    response = client.chat_completion(
        [{"role": "system", "content": system_message}, {"role": "user", "content": message}],
        max_tokens=512,
        temperature=0.7,
        top_p=0.95
    ).choices[0].message.content

    match_score_text = response.split(":")[-1].strip()
    feedback = "\n".join(response.split("\n")[1:])
    match_score = parse_score(match_score_text)
    if match_score is not None:
        match_score *= 100  # Convert to percentage
    else:
        match_score = 0
        feedback = "Error parsing match score from the response."
    return match_score, feedback

def resume_quality_score(file):
    resume_text = extract_text_from_pdf(file)
    system_message = "Evaluate the following resume for overall quality and provide a score and interpretation."
    message = resume_text
    response = client.chat_completion(
        [{"role": "system", "content": system_message}, {"role": "user", "content": message}],
        max_tokens=512,
        temperature=0.7,
        top_p=0.95
    ).choices[0].message.content

    score_lines = response.split("\n")
    quality_score_text = score_lines[0].split(":")[-1].strip()
    interpretation = "\n".join(score_lines[1:])
    quality_score = parse_score(quality_score_text)
    if quality_score is not None:
        quality_score *= 100  # Convert to percentage
    else:
        quality_score = 0
        interpretation = "Error parsing quality score from the response."
    return quality_score, interpretation

def text_to_overleaf(resume_text):
    system_message = "Convert the following resume text to Overleaf code."
    message = resume_text
    response = client.chat_completion(
        [{"role": "system", "content": system_message}, {"role": "user", "content": message}],
        max_tokens=512,
        temperature=0.7,
        top_p=0.95
    ).choices[0].message.content
    
    overleaf_code = response
    return overleaf_code

# Define the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Resume Enhancement Tool\nEnhance your resume with the following features.")
    
    with gr.Tab("ATS-Friendly Checker"):
        with gr.Row():
            resume = gr.File(label="Upload your Resume (PDF)")
            score = gr.Number(label="ATS Score", interactive=False)
            feedback = gr.Textbox(label="Feedback", interactive=False)
        resume.upload(ats_friendly_checker, resume, [score, feedback])
    
    with gr.Tab("Resume Match Checker"):
        with gr.Row():
            resume = gr.File(label="Upload your Resume (PDF)")
            job_url = gr.Textbox(label="Job Description URL")
            match_score = gr.Number(label="Match Score", interactive=False)
            feedback = gr.Textbox(label="Feedback", interactive=False)
        gr.Button("Check Match").click(resume_match_checker, [resume, job_url], [match_score, feedback])
    
    with gr.Tab("Resume Quality Score"):
        with gr.Row():
            resume = gr.File(label="Upload your Resume (PDF)")
            quality_score = gr.Number(label="Quality Score", interactive=False)
            interpretation = gr.Textbox(label="Interpretation", interactive=False)
        resume.upload(resume_quality_score, resume, [quality_score, interpretation])
    
    with gr.Tab("Text to Overleaf Code"):
        with gr.Row():
            resume_text = gr.Textbox(label="Resume Text")
            overleaf_code = gr.Textbox(label="Overleaf Code", interactive=False)
        resume_text.submit(text_to_overleaf, resume_text, overleaf_code)

    gr.Markdown("---\nBuilt with love by [Bahae Eddine HALIM](https://www.linkedin.com/in/halimbahae/)")

if __name__ == "__main__":
    demo.launch(share=True)