Upload app.py
Browse files
app.py
CHANGED
|
@@ -135,9 +135,33 @@ def extract_nouns(text):
|
|
| 135 |
nouns = [token.lemma_ for token in doc if token.pos_ == "NOUN"]
|
| 136 |
return nouns
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
# Define the sector options and their corresponding model and tokenizer paths
|
| 139 |
sectors = {
|
| 140 |
-
|
| 141 |
'model': r'modelfile\bighr2.keras',
|
| 142 |
'tokenizer': r'tokernizer\tokenizershr.pkl'
|
| 143 |
},
|
|
@@ -176,45 +200,31 @@ sector = st.selectbox("Select Sector:", list(sectors.keys()))
|
|
| 176 |
if st.button("Calculate ATS Score"):
|
| 177 |
if resume and job_description:
|
| 178 |
try:
|
| 179 |
-
|
| 180 |
-
tokenizer_path = sectors[sector]['tokenizer']
|
| 181 |
-
|
| 182 |
-
if not os.path.isfile(model_path):
|
| 183 |
-
st.error(f"Model file not found: {model_path}")
|
| 184 |
-
elif not os.path.isfile(tokenizer_path):
|
| 185 |
-
st.error(f"Tokenizer file not found: {tokenizer_path}")
|
| 186 |
-
else:
|
| 187 |
-
model = load_model(model_path)
|
| 188 |
-
|
| 189 |
-
with open(tokenizer_path, 'rb') as f:
|
| 190 |
-
tokenizers = pickle.load(f)
|
| 191 |
-
|
| 192 |
-
resume_tokenizer = tokenizers.get('resume_tokenizer')
|
| 193 |
-
description_tokenizer = tokenizers.get('description_tokenizer')
|
| 194 |
-
common_nouns_tokenizer = tokenizers.get('common_nouns_tokenizer')
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
else:
|
| 199 |
-
processed_resume = clean_and_preprocess(resume)
|
| 200 |
-
processed_description = clean_and_preprocess(job_description)
|
| 201 |
|
| 202 |
-
|
| 203 |
-
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
|
| 208 |
-
|
| 209 |
-
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
except Exception as e:
|
| 218 |
st.error(f"An error occurred: {e}")
|
| 219 |
else:
|
| 220 |
-
st.error("Please paste both your resume and job description before analyzing.")
|
|
|
|
| 135 |
nouns = [token.lemma_ for token in doc if token.pos_ == "NOUN"]
|
| 136 |
return nouns
|
| 137 |
|
| 138 |
+
def load_model_and_tokenizer(sector):
|
| 139 |
+
model_path = sectors[sector]['model']
|
| 140 |
+
tokenizer_path = sectors[sector]['tokenizer']
|
| 141 |
+
|
| 142 |
+
if not os.path.isfile(model_path):
|
| 143 |
+
raise FileNotFoundError(f"Model file not found: {model_path}")
|
| 144 |
+
|
| 145 |
+
if not os.path.isfile(tokenizer_path):
|
| 146 |
+
raise FileNotFoundError(f"Tokenizer file not found: {tokenizer_path}")
|
| 147 |
+
|
| 148 |
+
model = load_model(model_path)
|
| 149 |
+
|
| 150 |
+
with open(tokenizer_path, 'rb') as f:
|
| 151 |
+
tokenizers = pickle.load(f)
|
| 152 |
+
|
| 153 |
+
resume_tokenizer = tokenizers.get('resume_tokenizer')
|
| 154 |
+
description_tokenizer = tokenizers.get('description_tokenizer')
|
| 155 |
+
common_nouns_tokenizer = tokenizers.get('common_nouns_tokenizer')
|
| 156 |
+
|
| 157 |
+
if not (resume_tokenizer and description_tokenizer and common_nouns_tokenizer):
|
| 158 |
+
raise ValueError("Tokenizer components are missing from the file.")
|
| 159 |
+
|
| 160 |
+
return model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer
|
| 161 |
+
|
| 162 |
# Define the sector options and their corresponding model and tokenizer paths
|
| 163 |
sectors = {
|
| 164 |
+
'HR': {
|
| 165 |
'model': r'modelfile\bighr2.keras',
|
| 166 |
'tokenizer': r'tokernizer\tokenizershr.pkl'
|
| 167 |
},
|
|
|
|
| 200 |
if st.button("Calculate ATS Score"):
|
| 201 |
if resume and job_description:
|
| 202 |
try:
|
| 203 |
+
model, resume_tokenizer, description_tokenizer, common_nouns_tokenizer = load_model_and_tokenizer(sector)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
+
processed_resume = clean_and_preprocess(resume)
|
| 206 |
+
processed_description = clean_and_preprocess(job_description)
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
+
resume_sequence = resume_tokenizer.texts_to_sequences([processed_resume])
|
| 209 |
+
resume_data_padded = pad_sequences(resume_sequence, maxlen=1500)
|
| 210 |
|
| 211 |
+
description_sequence = description_tokenizer.texts_to_sequences([processed_description])
|
| 212 |
+
description_data_padded = pad_sequences(description_sequence, maxlen=1500)
|
| 213 |
|
| 214 |
+
common_nouns = set(extract_nouns(processed_resume))
|
| 215 |
+
common_nouns_str = ' '.join(common_nouns)
|
| 216 |
|
| 217 |
+
common_nouns_sequence = common_nouns_tokenizer.texts_to_sequences([common_nouns_str])
|
| 218 |
+
common_nouns_data = pad_sequences(common_nouns_sequence, maxlen=10)
|
| 219 |
|
| 220 |
+
prediction = model.predict([resume_data_padded, description_data_padded, common_nouns_data])
|
| 221 |
+
st.success(f"Your predicted ATS Score is: {prediction[0][0]:.2f}")
|
| 222 |
|
| 223 |
+
except FileNotFoundError as fnf_error:
|
| 224 |
+
st.error(str(fnf_error))
|
| 225 |
+
except ValueError as val_error:
|
| 226 |
+
st.error(str(val_error))
|
| 227 |
except Exception as e:
|
| 228 |
st.error(f"An error occurred: {e}")
|
| 229 |
else:
|
| 230 |
+
st.error("Please paste both your resume and job description before analyzing.")
|