Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from sentence_transformers import SentenceTransformer
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
from keyphrasetransformer import KeyPhraseTransformer
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
import torch
|
| 8 |
|
| 9 |
kp = KeyPhraseTransformer()
|
| 10 |
|
|
@@ -19,101 +18,49 @@ def calculate_similarity(model, text1, text2):
|
|
| 19 |
return cosine_similarity(embedding1, embedding2)[0][0]
|
| 20 |
|
| 21 |
def generate_wordcloud(text, title):
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def __call__(self, batch):
|
| 30 |
-
return batch
|
| 31 |
|
| 32 |
st.title("Resume Match Calculator")
|
| 33 |
|
| 34 |
model = load_model()
|
| 35 |
-
|
| 36 |
-
# Load your labeled dataset using the datasets library
|
| 37 |
-
dataset = load_dataset("Unknown92/Resume_dataset") # Replace with your actual dataset name
|
| 38 |
-
|
| 39 |
-
# Access the training set
|
| 40 |
-
train_data = dataset['train']
|
| 41 |
-
|
| 42 |
-
# Create InputExamples from the 'Resume' column
|
| 43 |
-
train_examples = []
|
| 44 |
-
|
| 45 |
-
# For agility, let's use only a portion of the data
|
| 46 |
-
n_examples = len(train_data) // 2
|
| 47 |
-
|
| 48 |
-
for i in range(n_examples):
|
| 49 |
-
example = train_data[i]
|
| 50 |
-
resume_text = example['Resume']
|
| 51 |
-
train_examples.append(InputExample(texts=[resume_text]))
|
| 52 |
-
|
| 53 |
-
# Now train_examples contains InputExample instances with 'Resume' as text
|
| 54 |
-
# You can use train_examples for training your sentence embedding model
|
| 55 |
-
|
| 56 |
-
# Create a DataLoader for training examples with custom collate function
|
| 57 |
-
batch_size = 16
|
| 58 |
-
train_dataloader = DataLoader(train_examples, shuffle=True, batch_size=batch_size, collate_fn=CustomCollate())
|
| 59 |
-
|
| 60 |
-
# Create a TripletLoss instance for training
|
| 61 |
-
train_loss = losses.TripletLoss(model=model)
|
| 62 |
-
|
| 63 |
-
# Training loop with manual loss and accuracy calculation
|
| 64 |
-
optimizer = torch.optim.AdamW(model.parameters(), lr=2e-5)
|
| 65 |
-
epochs = 10 # Adjust the number of epochs as needed
|
| 66 |
-
|
| 67 |
-
for epoch in range(epochs):
|
| 68 |
-
model.train()
|
| 69 |
-
total_loss = 0
|
| 70 |
-
total_batches = 0
|
| 71 |
-
|
| 72 |
-
for batch in train_dataloader:
|
| 73 |
-
optimizer.zero_grad()
|
| 74 |
-
embeddings = model.encode(batch[0]['texts'])
|
| 75 |
-
loss_value = train_loss.compute_loss(embeddings, torch.zeros_like(embeddings))
|
| 76 |
-
loss_value.backward()
|
| 77 |
-
optimizer.step()
|
| 78 |
-
|
| 79 |
-
total_loss += loss_value.item()
|
| 80 |
-
total_batches += 1
|
| 81 |
-
|
| 82 |
-
average_loss = total_loss / total_batches
|
| 83 |
-
|
| 84 |
-
# Print loss for the epoch
|
| 85 |
-
print(f"Epoch {epoch + 1}, Average Loss: {average_loss}")
|
| 86 |
-
|
| 87 |
# Set the font size for the "Paste the Job Description" text
|
| 88 |
st.markdown("<style>#fc1{font-size: 20px !important;}</style>", unsafe_allow_html=True)
|
| 89 |
|
| 90 |
jd = st.text_area("Paste the Job Description:", height=100)
|
| 91 |
resume = st.text_area("Paste Your the Resume:", height=100)
|
| 92 |
|
|
|
|
| 93 |
if st.button("Calculate Match Score"):
|
| 94 |
if jd and resume:
|
| 95 |
score = calculate_similarity(model, jd, resume)
|
| 96 |
-
jp
|
| 97 |
-
rp
|
| 98 |
-
|
| 99 |
# Find missing keywords in rp with respect to jp
|
|
|
|
| 100 |
missing_keywords = set(jp) - set(rp)
|
| 101 |
|
| 102 |
-
|
| 103 |
generate_wordcloud(' '.join(jp), 'Word Cloud for JD Keywords')
|
| 104 |
generate_wordcloud(' '.join(rp), 'Word Cloud for Resume Keywords')
|
| 105 |
-
|
|
|
|
| 106 |
st.write("The match score is:")
|
| 107 |
st.write(score)
|
| 108 |
-
|
| 109 |
-
st.write("JD Keywords:")
|
| 110 |
st.write(jp)
|
| 111 |
-
|
| 112 |
-
st.write("Resume Keywords:")
|
| 113 |
st.write(rp)
|
| 114 |
|
| 115 |
-
st.write("Missing Keywords in Resume:")
|
| 116 |
st.write(list(missing_keywords))
|
| 117 |
-
|
| 118 |
else:
|
| 119 |
-
st.write("Please enter both the job description and resume.")
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from sentence_transformers import SentenceTransformer
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
from keyphrasetransformer import KeyPhraseTransformer
|
| 5 |
+
from wordcloud import WordCloud
|
| 6 |
+
import matplotlib.pyplot as plt
|
|
|
|
| 7 |
|
| 8 |
kp = KeyPhraseTransformer()
|
| 9 |
|
|
|
|
| 18 |
return cosine_similarity(embedding1, embedding2)[0][0]
|
| 19 |
|
| 20 |
def generate_wordcloud(text, title):
|
| 21 |
+
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
|
| 22 |
+
plt.figure(figsize=(10, 5))
|
| 23 |
+
plt.imshow(wordcloud, interpolation='bilinear')
|
| 24 |
+
plt.axis('off')
|
| 25 |
+
plt.title(title)
|
| 26 |
+
st.pyplot(plt)
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
st.title("Resume Match Calculator")
|
| 29 |
|
| 30 |
model = load_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Set the font size for the "Paste the Job Description" text
|
| 32 |
st.markdown("<style>#fc1{font-size: 20px !important;}</style>", unsafe_allow_html=True)
|
| 33 |
|
| 34 |
jd = st.text_area("Paste the Job Description:", height=100)
|
| 35 |
resume = st.text_area("Paste Your the Resume:", height=100)
|
| 36 |
|
| 37 |
+
|
| 38 |
if st.button("Calculate Match Score"):
|
| 39 |
if jd and resume:
|
| 40 |
score = calculate_similarity(model, jd, resume)
|
| 41 |
+
jp=kp.get_key_phrases(jd)
|
| 42 |
+
rp=kp.get_key_phrases(resume)
|
| 43 |
+
|
| 44 |
# Find missing keywords in rp with respect to jp
|
| 45 |
+
|
| 46 |
missing_keywords = set(jp) - set(rp)
|
| 47 |
|
| 48 |
+
# Generate word clouds for JD and Resume
|
| 49 |
generate_wordcloud(' '.join(jp), 'Word Cloud for JD Keywords')
|
| 50 |
generate_wordcloud(' '.join(rp), 'Word Cloud for Resume Keywords')
|
| 51 |
+
|
| 52 |
+
# st.write(f"The match score is: {score}", )
|
| 53 |
st.write("The match score is:")
|
| 54 |
st.write(score)
|
| 55 |
+
|
| 56 |
+
st.write("JD Keywords:" )
|
| 57 |
st.write(jp)
|
| 58 |
+
|
| 59 |
+
st.write("Resume Keywords:" )
|
| 60 |
st.write(rp)
|
| 61 |
|
| 62 |
+
st.write("Missing Keywords in Resume:" )
|
| 63 |
st.write(list(missing_keywords))
|
|
|
|
| 64 |
else:
|
| 65 |
+
st.write("Please enter both the job description and resume.", )
|
| 66 |
+
|