Unknown92 commited on
Commit
8bc65a3
·
1 Parent(s): 666e40b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -77
app.py CHANGED
@@ -1,10 +1,9 @@
1
  import streamlit as st
2
- from sentence_transformers import SentenceTransformer, InputExample, losses
3
  from sklearn.metrics.pairwise import cosine_similarity
4
  from keyphrasetransformer import KeyPhraseTransformer
5
- from datasets import load_dataset
6
- from torch.utils.data import DataLoader
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
- # Your existing code for generating word clouds
23
- pass
24
-
25
- class CustomCollate:
26
- def __init__(self):
27
- pass
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 = kp.get_key_phrases(jd)
97
- rp = kp.get_key_phrases(resume)
98
-
99
  # Find missing keywords in rp with respect to jp
 
100
  missing_keywords = set(jp) - set(rp)
101
 
102
- # Generate word clouds for JD and Resume
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
+