Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
if user_input:
|
| 12 |
-
result = sentiment_pipeline(user_input)
|
| 13 |
-
sentiment = result[0]["label"]
|
| 14 |
-
confidence = result[0]["score"]
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
# Stage 5: Streamlit Application for Resume Screening
|
| 3 |
+
|
| 4 |
import streamlit as st
|
| 5 |
+
from transformers import BertTokenizer, BertForSequenceClassification, pipeline
|
| 6 |
+
import torch
|
| 7 |
+
import re
|
| 8 |
+
|
| 9 |
+
# Set page configuration
|
| 10 |
+
st.set_page_config(page_title="Resume Screening Application", page_icon="📄")
|
| 11 |
+
|
| 12 |
+
# Title and description
|
| 13 |
+
st.title("Resume Screening Application")
|
| 14 |
+
st.markdown("""
|
| 15 |
+
This application classifies a resume-job pair as **Relevant** or **Irrelevant** and generates a concise summary of the resume's skills.
|
| 16 |
|
| 17 |
+
**Classification Criteria**:
|
| 18 |
+
- **Skill Overlap**: At least 80% of the job's required skills must be in the resume.
|
| 19 |
+
- **Experience Match**: The resume's experience must meet or exceed the job's requirement.
|
| 20 |
+
- **Outcome**: Relevant if both conditions are met; otherwise, Irrelevant.
|
| 21 |
+
""")
|
| 22 |
|
| 23 |
+
# Load models
|
| 24 |
+
@st.cache_resource
|
| 25 |
+
def load_models():
|
| 26 |
+
bert_model_path = 'scmlewis/bert-finetuned-isom5240'
|
| 27 |
+
bert_tokenizer = BertTokenizer.from_pretrained(bert_model_path)
|
| 28 |
+
bert_model = BertForSequenceClassification.from_pretrained(bert_model_path, num_labels=2)
|
| 29 |
+
t5_generator = pipeline('text2text-generation', model='t5-small')
|
| 30 |
+
return bert_tokenizer, bert_model, t5_generator
|
| 31 |
|
| 32 |
+
bert_tokenizer, bert_model, t5_generator = load_models()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# Input fields
|
| 35 |
+
st.subheader("Enter Resume and Job Description")
|
| 36 |
+
resume = st.text_area("Resume", placeholder="e.g., Skilled in Python, SQL, 3 years experience")
|
| 37 |
+
job_description = st.text_area("Job Description", placeholder="e.g., Data analyst requires Python, SQL, 3 years+")
|
| 38 |
|
| 39 |
+
# Process inputs
|
| 40 |
+
if st.button("Screen Resume"):
|
| 41 |
+
if resume and job_description:
|
| 42 |
+
# Classification
|
| 43 |
+
input_text = f"resume: {resume} [sep] job: {job_description}"
|
| 44 |
+
inputs = bert_tokenizer(input_text, return_tensors='pt', padding=True, truncation=True, max_length=128)
|
| 45 |
+
with torch.no_grad():
|
| 46 |
+
outputs = bert_model(**inputs)
|
| 47 |
+
suitability = "Relevant" if outputs.logits.argmax().item() == 1 else "Irrelevant"
|
| 48 |
+
|
| 49 |
+
# Summary
|
| 50 |
+
simplified_resume = re.sub(r'(versed in leveraging|designed applications for|created solutions with|led projects involving|collaborated in agile teams over)', 'proficient in', resume).strip()
|
| 51 |
+
simplified_resume = re.sub(r'\s+', ' ', simplified_resume)
|
| 52 |
+
prompt = f"summarize: {simplified_resume}"
|
| 53 |
+
summary = t5_generator(
|
| 54 |
+
prompt,
|
| 55 |
+
max_length=20,
|
| 56 |
+
min_length=5,
|
| 57 |
+
num_beams=15,
|
| 58 |
+
no_repeat_ngram_size=3,
|
| 59 |
+
length_penalty=0.5,
|
| 60 |
+
early_stopping=True
|
| 61 |
+
)[0]['generated_text']
|
| 62 |
+
|
| 63 |
+
# Display results
|
| 64 |
+
st.subheader("Results")
|
| 65 |
+
st.write(f"**Suitability**: {suitability}")
|
| 66 |
+
st.write(f"**Summary**: {summary}")
|
| 67 |
+
else:
|
| 68 |
+
st.error("Please enter both a resume and a job description.")
|