Vaibhav84 commited on
Commit
7cdbc2f
·
1 Parent(s): bac3644

Changes for Add and remove skills

Browse files
Files changed (1) hide show
  1. app.py +188 -4
app.py CHANGED
@@ -7,6 +7,7 @@ import pandas as pd
7
  from datetime import date
8
  import numpy as np
9
  import spacy
 
10
  from sentence_transformers import SentenceTransformer, util
11
  from sklearn.feature_extraction.text import CountVectorizer
12
  from sklearn.metrics.pairwise import cosine_similarity
@@ -192,7 +193,7 @@ def SkillExtract():
192
  conn.commit()
193
  print("Skill Identified : ", skill_name)
194
  #print("Skill inserted in SkillMaster and Inserted in JDSkillDetails")
195
-
196
  query = "update public.jdmaster set isskillsextracted = 1 where jdmasterid = (%s)"
197
 
198
  params = (id_value,)
@@ -200,6 +201,106 @@ def SkillExtract():
200
  conn.commit()
201
  print("Skills Updated for Skills Extraction for file ", filename_jd)
202
  print("Total Skills : ", len(skills_list))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
  def SkillExtraction(file):
205
  annotations = skill_extractor.annotate(file)
@@ -322,7 +423,12 @@ def Last20JD():
322
  conn = psycopg2.connect(**db_params)
323
  df = pd.read_sql_query(dbQuery, conn)
324
  st.dataframe(df,use_container_width = True, hide_index = True)
325
-
 
 
 
 
 
326
  def uploadFile(text,filePath):
327
  hostname = socket.gethostname()
328
  ## getting the IP address using socket.gethostbyname() method
@@ -341,13 +447,69 @@ def uploadFile(text,filePath):
341
  print(ip_address)
342
  print("File Uploaded...")
343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  def AppFlow(text,fName,query, IsUpload):
345
  profile=""
 
 
 
 
 
 
 
 
 
 
 
 
346
  if(IsUpload == False and len(query) > 10):
347
  text = query
348
  IsUpload = True
349
  query = ''
350
- fName = 'Open Text'
 
 
 
 
 
351
  with st.spinner('Processing...'):
352
  if(query.upper() == 'SKILLS'):
353
  LatestExtractedSkills()
@@ -355,6 +517,9 @@ def AppFlow(text,fName,query, IsUpload):
355
  elif(query.upper() == 'JD'):
356
  Last20JD()
357
  st.success('Recently uploaded JDs')
 
 
 
358
  else:
359
  if(IsUpload and query == ''):
360
  uploadFile(str(text),fName)
@@ -370,7 +535,26 @@ def AppFlow(text,fName,query, IsUpload):
370
  st.write(details[2] + " " + details[3])
371
 
372
  st.success('Profile Tagging - ' + profile)
373
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  def submit (uploaded_resume, query):
375
  text = ""
376
  fName = ""
 
7
  from datetime import date
8
  import numpy as np
9
  import spacy
10
+ import re
11
  from sentence_transformers import SentenceTransformer, util
12
  from sklearn.feature_extraction.text import CountVectorizer
13
  from sklearn.metrics.pairwise import cosine_similarity
 
193
  conn.commit()
194
  print("Skill Identified : ", skill_name)
195
  #print("Skill inserted in SkillMaster and Inserted in JDSkillDetails")
196
+ extractWords(description_value,id_value)
197
  query = "update public.jdmaster set isskillsextracted = 1 where jdmasterid = (%s)"
198
 
199
  params = (id_value,)
 
201
  conn.commit()
202
  print("Skills Updated for Skills Extraction for file ", filename_jd)
203
  print("Total Skills : ", len(skills_list))
204
+
205
+ def GetSkillId(skillname,jdmasterid):
206
+ #Fetching skill id from skillmaster
207
+ conn = psycopg2.connect(**db_params)
208
+ cursor = conn.cursor()
209
+ query = "select skillid from skillmaster where upper(skilldetails) = (%s)"
210
+ params = (skillname.upper(),)
211
+ cursor.execute(query, params)
212
+ generated_skill_id = cursor.fetchone()[0]
213
+ #jdmasterid = 912
214
+ #print(generated_skill_id)
215
+ #checking if skill id already in skilldetails
216
+ query = "SELECT skillid FROM jdSkilldetails WHERE skillid IN (%s) and jdMasterid in (%s)"
217
+ params = (generated_skill_id,jdmasterid,)
218
+ cursor.execute(query, params)
219
+ if cursor.rowcount > 0:
220
+ #print("Already")
221
+ query =''
222
+ else:
223
+ #print("Updating in DB")
224
+ insert_query = sql.SQL("""INSERT INTO jdSkilldetails (Skillid, jdMasterid) VALUES (%s, %s)""")
225
+ cursor.execute(insert_query, (generated_skill_id, jdmasterid))
226
+ conn.commit()
227
+
228
+ cursor.close()
229
+ # Close the connection
230
+ conn.close()
231
+ return generated_skill_id
232
+
233
+ def getNewSkills():
234
+ query = "select skillid,skilldetails,skilltype,skill_score from skillmaster where weightage = -2"
235
+ conn = psycopg2.connect(**db_params)
236
+ cursor = conn.cursor()
237
+ df_skill_master = pd.read_sql_query(query, conn)
238
+ df_skill_master['skilldetails'] = df_skill_master['skilldetails'].str.upper()
239
+ cursor.close()
240
+ # Close the connection
241
+ conn.close()
242
+
243
+ #print(df_skill_master)
244
+ return df_skill_master
245
+ def skill_Validate(df, skill):
246
+ skill = skill.upper()
247
+ if (len(skill.split()) < 2 and len(skill) < 3) or len(skill.split())==1:
248
+ df['skill_present'] = df['skilldetails'].apply(lambda x: re.match(rf'^{skill}$', x))
249
+ if any(df['skill_present']):
250
+ #print("Valid Skill")
251
+ return 1
252
+ else:
253
+ #print("Not a Skill")
254
+ return 0
255
+ elif df['skilldetails'].str.contains(skill.upper()).any():
256
+ #print("Valid Skill")
257
+ return 1
258
+ else:
259
+ # print("Not a Skill")
260
+ return 0
261
+ def extractWords(job_description,JdMasterid):
262
+ job_roles = []
263
+ job_description = job_description.replace(')',' ')
264
+ delimiters = ",", " ", " , ", ";","\n","/","\\"
265
+ regex_pattern = '|'.join(map(re.escape, delimiters))
266
+ df = getNewSkills()
267
+ data = re.split(regex_pattern, job_description)
268
+ #data = job_description.split(',')
269
+ for ds in data:
270
+ #print(ds)
271
+ try:
272
+ if(skill_Validate(df,ds.strip())):
273
+ job_roles.append(ds)
274
+ GetSkillId(ds.strip(),JdMasterid)
275
+ print("Skills Identified* : " + ds)
276
+ except Exception as error:
277
+ test = 1
278
+ return job_roles
279
+
280
+ def extract_job_role(job_description):
281
+ # Process the job description text
282
+ doc = nlp(job_description)
283
+ df = getNewSkills()
284
+ # Define keywords related to job roles
285
+ job_role_keywords = ["role", "responsibilities", "duties", "position", "job title", "experience", "skills", "location", "tecnologies", "soft skills"]
286
+ #job_role_keywords = ["location"]
287
+
288
+ # Initialize an empty list to store extracted job roles
289
+ job_roles = []
290
+
291
+ # Iterate through the sentences in the document
292
+ for sent in doc.sents:
293
+ # Check if any of the job role keywords are present in the sentence
294
+ if any(keyword in sent.text.lower() for keyword in job_role_keywords):
295
+ # Extract noun phrases that represent job roles
296
+ for chunk in sent.noun_chunks:
297
+ print("NLP-" + chunk.text)
298
+ if(skill_Validate(df,chunk.text)):
299
+ job_roles.append(chunk.text)
300
+ print("Skills Identified* : " + chunk.text)
301
+
302
+ # Return the extracted job roles
303
+ return job_roles
304
 
305
  def SkillExtraction(file):
306
  annotations = skill_extractor.annotate(file)
 
423
  conn = psycopg2.connect(**db_params)
424
  df = pd.read_sql_query(dbQuery, conn)
425
  st.dataframe(df,use_container_width = True, hide_index = True)
426
+ def Executequery(dbquery):
427
+ conn = psycopg2.connect(**db_params)
428
+ cursor_obj = conn.cursor()
429
+ cursor_obj.execute(dbquery)
430
+ cursor_obj.close()
431
+ conn.close()
432
  def uploadFile(text,filePath):
433
  hostname = socket.gethostname()
434
  ## getting the IP address using socket.gethostbyname() method
 
447
  print(ip_address)
448
  print("File Uploaded...")
449
 
450
+ def RemoveSkills(data):
451
+ conn = psycopg2.connect(**db_params)
452
+ cursor = conn.cursor()
453
+ skill_rm = data.split(':')[1]
454
+ print("Removing Skills " + skill_rm)
455
+ query = "update skillmaster set weightage = 0 where skilldetails = (%s)"
456
+ params = (skill_rm,)
457
+ cursor.execute(query, params)
458
+ conn.commit()
459
+ cursor.close()
460
+ conn.close()
461
+ def insert_skill(skills):
462
+ details = skills.split(',')
463
+ skill_details = details[0]
464
+ skill_type = details [1]
465
+ skill_score1 = details[2]
466
+ weightage = -2
467
+ is_active = True
468
+ conn = psycopg2.connect(**db_params)
469
+ cursor = conn.cursor()
470
+ print("Adding Skill " + skill_details)
471
+ query = "SELECT skillid FROM skillmaster WHERE skillDetails IN (%s)"
472
+ params = (skill_details,) # Replace 'Test' with your actual variable or user input
473
+ cursor.execute(query, params)
474
+ if cursor.rowcount == 0:
475
+
476
+ insert_query = sql.SQL("""INSERT INTO SkillMaster (SkillDetails, SkillType, Weightage, IsActive, skill_score)
477
+ VALUES (%s, %s, %s, %s, %s) RETURNING SkillID""")
478
+ cursor.execute(insert_query, (skill_details, skill_type, weightage, is_active, skill_score1))
479
+ conn.commit()
480
+ else:
481
+ print("Skill Already in DB")
482
+ # Close the cursor and connection
483
+ cursor.close()
484
+ # Close the connection
485
+ conn.close()
486
+ def AddSkills(data):
487
+ skill_add = data.split(':')[1]
488
+ insert_skill(skill_add)
489
  def AppFlow(text,fName,query, IsUpload):
490
  profile=""
491
+ if(len(query) > 8):
492
+ profile = query[0:7]
493
+ print(profile)
494
+ if("@Remove" in profile):
495
+
496
+ RemoveSkills(query)
497
+ st.success('Skills removed')
498
+ return
499
+ elif("@Add" in profile):
500
+ AddSkills(query)
501
+ st.success('Skills added')
502
+ return
503
  if(IsUpload == False and len(query) > 10):
504
  text = query
505
  IsUpload = True
506
  query = ''
507
+ fName = 'Open Text'
508
+ elif(IsUpload == False and len(query) > 10):
509
+ text = query
510
+ IsUpload = True
511
+ query = ''
512
+ fName = 'Open Text'
513
  with st.spinner('Processing...'):
514
  if(query.upper() == 'SKILLS'):
515
  LatestExtractedSkills()
 
517
  elif(query.upper() == 'JD'):
518
  Last20JD()
519
  st.success('Recently uploaded JDs')
520
+ elif(query.upper() == 'JD'):
521
+ Last20JD()
522
+ st.success('Recently uploaded JDs')
523
  else:
524
  if(IsUpload and query == ''):
525
  uploadFile(str(text),fName)
 
535
  st.write(details[2] + " " + details[3])
536
 
537
  st.success('Profile Tagging - ' + profile)
538
+ def extract_Newjob_role(job_description):
539
+ # Process the job description text
540
+ doc = nlp(job_description)
541
+
542
+ # Define keywords related to job roles
543
+ job_role_keywords = ["role", "responsibilities", "duties", "position", "job title"]
544
+
545
+ # Initialize an empty list to store extracted job roles
546
+ job_roles = []
547
+
548
+ # Iterate through the sentences in the document
549
+ for sent in doc.sents:
550
+ # Check if any of the job role keywords are present in the sentence
551
+ if any(keyword in sent.text.lower() for keyword in job_role_keywords):
552
+ # Extract noun phrases that represent job roles
553
+ for chunk in sent.noun_chunks:
554
+ job_roles.append(chunk.text)
555
+
556
+ # Return the extracted job roles
557
+ return job_roles
558
  def submit (uploaded_resume, query):
559
  text = ""
560
  fName = ""