DreamStream-1 commited on
Commit
3597928
·
verified ·
1 Parent(s): d9c753f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -5,7 +5,7 @@ import PyPDF2 as pdf
5
  import io
6
  import re
7
  import streamlit as st
8
- from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
9
  from sklearn.feature_extraction.text import TfidfVectorizer
10
  from sklearn.metrics.pairwise import cosine_similarity
11
 
@@ -15,18 +15,20 @@ if not api_key:
15
  st.error("API key not found. Please set GOOGLE_API_KEY in your environment variables.")
16
  st.stop()
17
 
18
- # Configure the generative AI client
19
  genai.configure(api_key=api_key)
 
20
 
21
- # Initialize pre-trained Hugging Face pipelines
22
- skill_extractor = pipeline("ner", model="dslim/bert-base-NER", aggregation_strategy="simple")
23
- education_extractor = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english", aggregation_strategy="simple")
24
 
25
- # Define the Hugging Face sentiment analysis model
26
  task = "sentiment-analysis"
27
- model_name = "roberta-base"
28
  tokenizer = AutoTokenizer.from_pretrained(model_name)
29
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
 
30
 
31
  # Extract text from uploaded PDF file
32
  def input_pdf_text(uploaded_file):
@@ -58,21 +60,21 @@ def extract_contact_info(resume_text):
58
  def extract_skills(resume_text):
59
  try:
60
  ner_results = skill_extractor(resume_text)
61
- skills = [entity['word'] for entity in ner_results if 'skill' in entity['entity_group'].lower()]
62
  return ", ".join(skills) if skills else "Not Available"
63
  except Exception:
64
  return "Not Available"
65
 
66
- # Extract education information using NER model
67
  def extract_education(resume_text):
68
  try:
69
  ner_results = education_extractor(resume_text)
70
- education_entities = [entity['word'] for entity in ner_results if 'education' in entity['entity_group'].lower()]
71
  return ", ".join(education_entities) if education_entities else "Not Available"
72
  except Exception:
73
  return "Not Available"
74
 
75
- # Extract years of experience using regex
76
  def extract_experience_years(text):
77
  patterns = [
78
  r"(\d{4})\s?[–\-to]+\s?(\d{4})",
@@ -84,10 +86,10 @@ def extract_experience_years(text):
84
  for pattern in patterns:
85
  matches = re.findall(pattern, text)
86
  for match in matches:
87
- if len(match) >= 2 and match[0].isdigit() and match[1].isdigit():
88
- start_year, end_year = int(match[0]), int(match[1])
89
  years += max(0, end_year - start_year)
90
- elif "years" in match or "yrs" in match:
91
  years += int(match[0])
92
  return years
93
 
@@ -117,8 +119,8 @@ def get_gemini_response(input_text, job_description):
117
  - Leadership experience (years)
118
  - Match percentage
119
  """
120
- response = genai.generate_text(prompt=prompt)
121
- return response.candidates[0]['content'] # Parse response based on the API's response structure
122
  except Exception as e:
123
  st.error(f"Error generating response from Gemini model: {str(e)}")
124
  return ""
 
5
  import io
6
  import re
7
  import streamlit as st
8
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
9
  from sklearn.feature_extraction.text import TfidfVectorizer
10
  from sklearn.metrics.pairwise import cosine_similarity
11
 
 
15
  st.error("API key not found. Please set GOOGLE_API_KEY in your environment variables.")
16
  st.stop()
17
 
18
+ # Initialize the generative AI model
19
  genai.configure(api_key=api_key)
20
+ gemini_model = genai.generate # Use the correct method for text generation
21
 
22
+ # Load updated pre-trained models
23
+ skill_extractor = pipeline("ner", model="Jean-Baptiste/roberta-large-ner-english", aggregation_strategy="simple")
24
+ education_extractor = pipeline("ner", model="Jean-Baptiste/roberta-large-ner-english", aggregation_strategy="simple")
25
 
26
+ # Sentiment analysis model
27
  task = "sentiment-analysis"
28
+ model_name = "cardiffnlp/twitter-roberta-base-sentiment"
29
  tokenizer = AutoTokenizer.from_pretrained(model_name)
30
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
31
+ sentiment_analysis = pipeline(task, model=model, tokenizer=tokenizer)
32
 
33
  # Extract text from uploaded PDF file
34
  def input_pdf_text(uploaded_file):
 
60
  def extract_skills(resume_text):
61
  try:
62
  ner_results = skill_extractor(resume_text)
63
+ skills = [entity['word'] for entity in ner_results if entity['entity_group'].lower() == 'skill']
64
  return ", ".join(skills) if skills else "Not Available"
65
  except Exception:
66
  return "Not Available"
67
 
68
+ # Extract education using NER model
69
  def extract_education(resume_text):
70
  try:
71
  ner_results = education_extractor(resume_text)
72
+ education_entities = [entity['word'] for entity in ner_results if entity['entity_group'].lower() == 'education']
73
  return ", ".join(education_entities) if education_entities else "Not Available"
74
  except Exception:
75
  return "Not Available"
76
 
77
+ # Extract experience years
78
  def extract_experience_years(text):
79
  patterns = [
80
  r"(\d{4})\s?[–\-to]+\s?(\d{4})",
 
86
  for pattern in patterns:
87
  matches = re.findall(pattern, text)
88
  for match in matches:
89
+ if len(match) == 2 and match[1].isdigit():
90
+ start_year, end_year = map(int, match[:2])
91
  years += max(0, end_year - start_year)
92
+ elif len(match) == 1 and match[0].isdigit():
93
  years += int(match[0])
94
  return years
95
 
 
119
  - Leadership experience (years)
120
  - Match percentage
121
  """
122
+ response = gemini_model(prompt=prompt, max_output_tokens=100)
123
+ return response['text'].strip()
124
  except Exception as e:
125
  st.error(f"Error generating response from Gemini model: {str(e)}")
126
  return ""