Elvan Selvano commited on
Commit
55c3ecb
β€’
1 Parent(s): b23b643

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -32,12 +32,11 @@ def get_similarity_score(model, data, query, corpus_embeddings):
32
  result.sort_values(by=['score', 'Last Day'], ascending=[False, True], inplace=True)
33
  return result
34
 
35
- @st.cache(ttl=24*3600)
36
  def create_embedding(model: SentenceTransformer, data: pd.DataFrame, key: str) -> Tuple[list, list]:
37
  """Create vector embeddings from the dataset"""
38
  corpus_sentences = data[key].astype(str).tolist()
39
  corpus_embeddings = model.encode(sentences=corpus_sentences,
40
- show_progress_bar=True,
41
  convert_to_tensor=True,
42
  normalize_embeddings=True)
43
  return corpus_embeddings
@@ -51,6 +50,14 @@ def load_dataset(columns: List) -> pd.DataFrame:
51
  data = data.iloc[: , :7]
52
  data.columns = columns
53
  data.insert(0, 'ID', range(len(data)))
 
 
 
 
 
 
 
 
54
  return data
55
 
56
  def show_aggrid_table(result: pd.DataFrame):
@@ -78,8 +85,8 @@ def show_aggrid_table(result: pd.DataFrame):
78
  allow_unsafe_jscode=True,
79
  )
80
 
81
- def main():
82
- """Main Function"""
83
  st.title('@ecommurz Talent Search Engine')
84
  st.markdown('''
85
  <div align="left">
@@ -92,32 +99,26 @@ def main():
92
  ''', unsafe_allow_html=True)
93
  st.write('This app lets you search and sort talent by job title or relevant job descriptions from ecommurz talent list in real-time.')
94
 
 
 
 
 
95
  columns = ['Timestamp', 'Full Name', 'Company', 'Previous Role',
96
  'Experience (months)', 'Last Day', 'LinkedIn Profile']
97
  data = load_dataset(columns)
98
 
99
- # Preprocess Data
100
- data['Full Name'] = data['Full Name'].str.title()
101
- data['LinkedIn Profile'] = data['LinkedIn Profile'].str.lower()
102
- data['LinkedIn Profile'] = np.where(data['LinkedIn Profile'].str.startswith('www.linkedin.com'),
103
- "https://" + data['LinkedIn Profile'],
104
- data['LinkedIn Profile'])
105
- data['LinkedIn Profile'] = np.where(data['LinkedIn Profile'].str.startswith('linkedin.com'),
106
- "https://www." + data['LinkedIn Profile'],
107
- data['LinkedIn Profile'])
108
-
109
-
110
- # model = load_model()
111
- # corpus_embeddings = create_embedding(model, data, 'Previous Role')
112
 
113
- # job_title = st.text_input('Insert the job title below:', '')
114
- # submitted = st.button('Submit')
115
 
116
- # if submitted:
117
- # st.info(f'Showing results for {job_title}')
118
- # result = get_similarity_score(model, data, job_title, corpus_embeddings)
119
- # result = result[columns]
120
- # show_aggrid_table(result)
121
 
122
  if __name__ == '__main__':
123
  main()
 
32
  result.sort_values(by=['score', 'Last Day'], ascending=[False, True], inplace=True)
33
  return result
34
 
35
+ @st.cache(ttl=4*3600)
36
  def create_embedding(model: SentenceTransformer, data: pd.DataFrame, key: str) -> Tuple[list, list]:
37
  """Create vector embeddings from the dataset"""
38
  corpus_sentences = data[key].astype(str).tolist()
39
  corpus_embeddings = model.encode(sentences=corpus_sentences,
 
40
  convert_to_tensor=True,
41
  normalize_embeddings=True)
42
  return corpus_embeddings
 
50
  data = data.iloc[: , :7]
51
  data.columns = columns
52
  data.insert(0, 'ID', range(len(data)))
53
+ data['Full Name'] = data['Full Name'].str.title()
54
+ data['LinkedIn Profile'] = data['LinkedIn Profile'].str.lower()
55
+ data['LinkedIn Profile'] = np.where(data['LinkedIn Profile'].str.startswith('www.linkedin.com'),
56
+ "https://" + data['LinkedIn Profile'],
57
+ data['LinkedIn Profile'])
58
+ data['LinkedIn Profile'] = np.where(data['LinkedIn Profile'].str.startswith('linkedin.com'),
59
+ "https://www." + data['LinkedIn Profile'],
60
+ data['LinkedIn Profile'])
61
  return data
62
 
63
  def show_aggrid_table(result: pd.DataFrame):
 
85
  allow_unsafe_jscode=True,
86
  )
87
 
88
+ def show_heading():
89
+ """Show heading made using streamlit"""
90
  st.title('@ecommurz Talent Search Engine')
91
  st.markdown('''
92
  <div align="left">
 
99
  ''', unsafe_allow_html=True)
100
  st.write('This app lets you search and sort talent by job title or relevant job descriptions from ecommurz talent list in real-time.')
101
 
102
+ def main():
103
+ """Main Function"""
104
+ show_heading()
105
+
106
  columns = ['Timestamp', 'Full Name', 'Company', 'Previous Role',
107
  'Experience (months)', 'Last Day', 'LinkedIn Profile']
108
  data = load_dataset(columns)
109
 
110
+ # Inference
111
+ model = load_model()
112
+ corpus_embeddings = create_embedding(model, data, 'Previous Role')
 
 
 
 
 
 
 
 
 
 
113
 
114
+ job_title = st.text_input('Insert the job title below:', '')
115
+ submitted = st.button('Submit')
116
 
117
+ if submitted:
118
+ st.info(f'Showing results for {job_title}')
119
+ result = get_similarity_score(model, data, job_title, corpus_embeddings)
120
+ result = result[columns]
121
+ show_aggrid_table(result)
122
 
123
  if __name__ == '__main__':
124
  main()