File size: 11,575 Bytes
ff2a7ca
 
 
 
 
 
 
 
c1dbcdd
ff2a7ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c16581
 
 
 
 
 
 
c1dbcdd
4a6a007
 
0c16581
4a6a007
ff2a7ca
 
 
c1dbcdd
ff2a7ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39d2255
 
 
80b5209
 
 
 
 
 
 
39d2255
 
 
 
 
 
80b5209
39d2255
 
 
 
 
 
 
 
 
 
80b5209
 
 
39d2255
 
 
80b5209
39d2255
 
 
 
 
 
 
 
 
 
 
 
 
80b5209
 
39d2255
80b5209
39d2255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80b5209
 
39d2255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff2a7ca
 
416b9d4
ff2a7ca
 
 
 
 
 
 
 
 
 
39d2255
ff2a7ca
c1dbcdd
ff2a7ca
 
39d2255
 
 
 
 
 
 
 
 
 
ff2a7ca
80b5209
 
ff2a7ca
80b5209
 
ff2a7ca
80b5209
 
ff2a7ca
80b5209
 
ff2a7ca
80b5209
 
ff2a7ca
80b5209
 
0f4c610
80b5209
 
 
 
ff2a7ca
 
 
80b5209
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import pickle
import numpy as np
import spacy
import re
import string
import streamlit as st
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
import os

abbreviations = {
    "mgr": "manager",
    "sr": "senior",
    "jr": "junior",
    "asst": "assistant",
    "assoc": "associate",
    "dept": "department",
    "exp": "experience",
    "hr": "human resources",
    "acct": "account",
    "acctg": "accounting",
    "fin": "finance",
    "eng": "engineer",
    "engg": "engineering",
    "it": "information technology",
    "qa": "quality assurance",
    "dev": "development",
    "devops": "development operations",
    "proj": "project",
    "mktg": "marketing",
    "biz": "business",
    "comm": "communication",
    "adm": "administration",
    "sec": "secretary",
    "exec": "executive",
    "corp": "corporation",
    "intl": "international",
    "rep": "representative",
    "mfg": "manufacturing",
    "prod": "production",
    "purch": "purchasing",
    "sales": "sales",
    "cust": "customer",
    "svc": "service",
    "tech": "technical",
    "sup": "supervisor",
    "supv": "supervision",
    "log": "logistics",
    "inv": "inventory",
    "sch": "schedule",
    "edu": "education",
    "lang": "language",
    "pr": "public relations",
    "hrd": "human resources development",
    "cfo": "chief financial officer",
    "ceo": "chief executive officer",
    "coo": "chief operating officer",
    "cmo": "chief marketing officer",
    "cto": "chief technology officer",
    "cio": "chief information officer",
    "pmo": "project management office",
    "pmp": "project management professional",
    "ba": "business analyst",
    "bpm": "business process management",
    "ui": "user interface",
    "ux": "user experience",
    "svp": "senior vice president",
    "vp": "vice president",
    "gm": "general manager",
    "doe": "depends on experience",
    "r&d": "research and development",
    "seo": "search engine optimization",
    "sem": "search engine marketing",
    "smm": "social media marketing",
    "b2b": "business to business",
    "b2c": "business to consumer",
    "kpi": "key performance indicator",
    "roi": "return on investment",
    "saas": "software as a service",
    "paas": "platform as a service",
    "iaas": "infrastructure as a service",
    "crm": "customer relationship management",
    "erp": "enterprise resource planning",
    "sd": "software development",
    "pm": "project manager",
    "pa": "personal assistant",
    "exec": "executive",
    "fin": "finance",
    "hrm": "human resources management",
    "it": "information technology",
    "pr": "public relations",
    "qa": "quality assurance",
    "r&d": "research and development",
    "scm": "supply chain management",
    "seo": "search engine optimization",
    "smm": "social media marketing",
    "ux": "user experience",
    "ui": "user interface",
    "bi": "business intelligence",
    "dev": "development",
    "ops": "operations"
}

def ensure_model_installed():
    try:
        spacy.load('en_core_web_sm')
    except OSError:
        from spacy.cli import download
        download('en_core_web_sm')
        spacy.load('en_core_web_sm')

# Ensure the model is installed
ensure_model_installed()

nlp = spacy.load("en_core_web_sm")

def expand_abbreviations(text, abbreviations):
    for abbr, expanded in abbreviations.items():
        text = re.sub(r'\b{}\b'.format(abbr), expanded, text, flags=re.IGNORECASE)
    return text

def clean_and_preprocess(text):
    text = expand_abbreviations(text, abbreviations)
    text = text.lower()
    text = re.sub(r'\d+', '', text)
    text = text.translate(str.maketrans('', '', string.punctuation))
    text = re.sub(r'\s+', ' ', text).strip()
    doc = nlp(text)
    tokens = [token.lemma_ for token in doc if token.is_alpha and not token.is_stop]
    return ' '.join(tokens)

def extract_nouns(text):
    doc = nlp(text)
    nouns = [token.lemma_ for token in doc if token.pos_ == "NOUN"]
    return nouns

def load_model_and_tokenizers_for_hr():
    model_path = 'modelfile/bighr2.keras'
    tokenizer_path = 'tokernizer/tokenizershr.pkl'
    if not os.path.isfile(model_path):
        raise FileNotFoundError(f"Model file not found: {model_path}")
    if not os.path.isfile(tokenizer_path):
        raise FileNotFoundError(f"Tokenizer file not found: {tokenizer_path}")
    model = load_model(model_path)
    with open(tokenizer_path, 'rb') as f:
        tokenizers = pickle.load(f)
    resume_tokenizer = tokenizers.get('resume_tokenizer')
    description_tokenizer = tokenizers.get('description_tokenizer')
    common_nouns_tokenizer = tokenizers.get('common_nouns_tokenizer')
    if not (resume_tokenizer and description_tokenizer and common_nouns_tokenizer):
        raise ValueError("Tokenizer components are missing from the file.")
    return model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer

def load_model_and_tokenizers_for_it():
    model_path = 'modelfile/bigit2.keras'
    tokenizer_path = 'tokernizer/tokenizersit.pkl'
    if not os.path.isfile(model_path):
        raise FileNotFoundError(f"Model file not found: {model_path}")
    if not os.path.isfile(tokenizer_path):
        raise FileNotFoundError(f"Tokenizer file not found: {tokenizer_path}")
    model = load_model(model_path)
    with open(tokenizer_path, 'rb') as f:
        tokenizers = pickle.load(f)
    resume_tokenizer = tokenizers.get('resume_tokenizer')
    description_tokenizer = tokenizers.get('description_tokenizer')
    common_nouns_tokenizer = tokenizers.get('common_nouns_tokenizer')
    if not (resume_tokenizer and description_tokenizer and common_nouns_tokenizer):
        raise ValueError("Tokenizer components are missing from the file.")
    return model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer

def load_model_and_tokenizers_for_sales():
    model_path = 'modelfile/bigrsales2.keras'
    tokenizer_path = 'tokernizer/tokenizerssales.pkl'
    if not os.path.isfile(model_path):
        raise FileNotFoundError(f"Model file not found: {model_path}")
    if not os.path.isfile(tokenizer_path):
        raise FileNotFoundError(f"Tokenizer file not found: {tokenizer_path}")
    model = load_model(model_path)
    with open(tokenizer_path, 'rb') as f:
        tokenizers = pickle.load(f)
    resume_tokenizer = tokenizers.get('resume_tokenizer')
    description_tokenizer = tokenizers.get('description_tokenizer')
    common_nouns_tokenizer = tokenizers.get('common_nouns_tokenizer')
    if not (resume_tokenizer and description_tokenizer and common_nouns_tokenizer):
        raise ValueError("Tokenizer components are missing from the file.")
    return model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer

def load_model_and_tokenizers_for_health():
    model_path = 'modelfile/bighealth2.keras'
    tokenizer_path = 'tokernizer/tokenizershealth.pkl'
    if not os.path.isfile(model_path):
        raise FileNotFoundError(f"Model file not found: {model_path}")
    if not os.path.isfile(tokenizer_path):
        raise FileNotFoundError(f"Tokenizer file not found: {tokenizer_path}")
    model = load_model(model_path)
    with open(tokenizer_path, 'rb') as f:
        tokenizers = pickle.load(f)
    resume_tokenizer = tokenizers.get('resume_tokenizer')
    description_tokenizer = tokenizers.get('description_tokenizer')
    common_nouns_tokenizer = tokenizers.get('common_nouns_tokenizer')
    if not (resume_tokenizer and description_tokenizer and common_nouns_tokenizer):
        raise ValueError("Tokenizer components are missing from the file.")
    return model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer

def load_model_and_tokenizers_for_other():
    model_path = 'modelfile/bigothers2.keras'
    tokenizer_path = 'tokernizer/tokenizersothers.pkl'
    if not os.path.isfile(model_path):
        raise FileNotFoundError(f"Model file not found: {model_path}")
    if not os.path.isfile(tokenizer_path):
        raise FileNotFoundError(f"Tokenizer file not found: {tokenizer_path}")
    model = load_model(model_path)
    with open(tokenizer_path, 'rb') as f:
        tokenizers = pickle.load(f)
    resume_tokenizer = tokenizers.get('resume_tokenizer')
    description_tokenizer = tokenizers.get('description_tokenizer')
    common_nouns_tokenizer = tokenizers.get('common_nouns_tokenizer')
    if not (resume_tokenizer and description_tokenizer and common_nouns_tokenizer):
        raise ValueError("Tokenizer components are missing from the file.")
    return model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer

# Streamlit UI
st.title("ATS")

st.write("Upload your resume and job description, then select the job sector to analyze how well the resume fits the job description.")

# Resume input
resume = st.text_area("Paste your Resume:", height=150)

# Job description input
job_description = st.text_area("Paste Job Description:", height=150)

# Sector selection
sector = st.selectbox("Select Sector:", ['HR', 'IT', 'Sales', 'Health', 'Other'])

if st.button("Calculate ATS Score"):
    if resume and job_description:
        try:
            if sector == 'HR':
                model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer = load_model_and_tokenizers_for_hr()
            elif sector == 'IT':
                model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer = load_model_and_tokenizers_for_it()
            elif sector == 'Sales':
                model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer = load_model_and_tokenizers_for_sales()
            elif sector == 'Health':
                model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer = load_model_and_tokenizers_for_health()
            elif sector == 'Other':
                model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer = load_model_and_tokenizers_for_other()

            processed_resume = clean_and_preprocess(resume)
            processed_description = clean_and_preprocess(job_description)

            resume_sequence = resume_tokenizer.texts_to_sequences([processed_resume])
            resume_data_padded = pad_sequences(resume_sequence, maxlen=1500)

            description_sequence = description_tokenizer.texts_to_sequences([processed_description])
            description_data_padded = pad_sequences(description_sequence, maxlen=1500)

            common_nouns = set(extract_nouns(processed_resume))
            common_nouns_str = ' '.join(common_nouns)

            common_nouns_sequence = common_nouns_tokenizer.texts_to_sequences([common_nouns_str])
            common_nouns_data = pad_sequences(common_nouns_sequence, maxlen=10)

            prediction = model.predict([resume_data_padded, description_data_padded, common_nouns_data])
            st.success(f"Your predicted ATS Score is: {prediction[0][0]:.2f}")

        except FileNotFoundError as fnf_error:
            st.error(str(fnf_error))
        except ValueError as val_error:
            st.error(str(val_error))
        except Exception as e:
            st.error(f"An error occurred: {e}")
    else:
        st.error("Please paste both your resume and job description before analyzing.")