DreamStream-1 commited on
Commit
04c3909
·
verified ·
1 Parent(s): 9ee0a98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -39
app.py CHANGED
@@ -70,7 +70,7 @@ def system_prompt_to_extract_info(resume_text):
70
  """
71
  return prompt
72
 
73
- # Function to extract candidate information from resume text using Gemini API
74
  def extract_entities_via_gemini(resume_text):
75
  api_key = get_google_api_key() # Fetch the API key from environment variables
76
  endpoint = "https://gemini.googleapis.com/v1/documents:analyzeEntities" # Placeholder API endpoint (adjust as necessary)
@@ -86,50 +86,27 @@ def extract_entities_via_gemini(resume_text):
86
  "content": resume_text
87
  }
88
  }
89
-
90
  # Send request to Gemini or another NLP API
91
  response = requests.post(endpoint, headers=headers, json=document)
92
 
93
- # Debugging: Log raw response
94
- print(f"Response Status Code: {response.status_code}")
95
- print(f"Response Content: {response.text}") # Log the raw response content
96
-
97
  if response.status_code != 200:
98
  return {"error": "Failed to extract entities from resume", "status_code": response.status_code, "response": response.text}
99
-
100
- # Use the raw text response (instead of parsing as JSON)
101
- response_text = response.text
102
-
103
- # You can now use `response_text` directly as you wish. For example, if you're extracting specific information:
104
  extracted_info = {"name": "Unknown Candidate", "email": "No Email", "contact": "No Contact"}
105
 
106
- # Check for keywords in the response text to extract candidate info
107
- if "name" in response_text:
108
- extracted_info['name'] = extract_info_from_text(response_text, 'name')
109
- if "email" in response_text:
110
- extracted_info['email'] = extract_info_from_text(response_text, 'email')
111
- if "contact" in response_text:
112
- extracted_info['contact'] = extract_info_from_text(response_text, 'contact')
113
-
114
  return extracted_info
115
 
116
- # Helper function to extract specific information from raw response text
117
- def extract_info_from_text(response_text, info_type):
118
- # Define simple patterns to match relevant information (you can improve this regex as needed)
119
- if info_type == 'name':
120
- match = re.search(r"Name: (\S+ \S+)", response_text)
121
- if match:
122
- return match.group(1)
123
- elif info_type == 'email':
124
- match = re.search(r"Email: (\S+@\S+)", response_text)
125
- if match:
126
- return match.group(1)
127
- elif info_type == 'contact':
128
- match = re.search(r"Contact: (\S+)", response_text)
129
- if match:
130
- return match.group(1)
131
- return f"No {info_type}"
132
-
133
  # Function to check similarity between resumes and job description
134
  def check_similarity(job_description, resume_files):
135
  results = []
@@ -148,7 +125,7 @@ def check_similarity(job_description, resume_files):
148
  # Convert similarity score to percentage
149
  similarity_percentage = similarity_score * 100
150
 
151
- # Extract leadership experience (make sure this function is implemented)
152
  leadership_experience = extract_leadership_experience(resume_text)
153
 
154
  # Extract name, email, and contact info using Google Gemini API
@@ -204,11 +181,10 @@ def download_results(results):
204
  interface = gr.Interface(
205
  fn=check_similarity,
206
  inputs=[job_desc_input, resumes_input],
207
- outputs=[results_output, gr.File(label="Download CSV", file=download_results)], # Updated here
208
  title="HR Assistant - Resume Screening & Leadership Experience",
209
  description="Upload job description and resumes to screen candidates for managerial and team leadership roles and extract candidate details.",
210
  allow_flagging="never"
211
  )
212
 
213
  interface.launch()
214
-
 
70
  """
71
  return prompt
72
 
73
+ # Function to extract candidate information from resume text
74
  def extract_entities_via_gemini(resume_text):
75
  api_key = get_google_api_key() # Fetch the API key from environment variables
76
  endpoint = "https://gemini.googleapis.com/v1/documents:analyzeEntities" # Placeholder API endpoint (adjust as necessary)
 
86
  "content": resume_text
87
  }
88
  }
89
+
90
  # Send request to Gemini or another NLP API
91
  response = requests.post(endpoint, headers=headers, json=document)
92
 
 
 
 
 
93
  if response.status_code != 200:
94
  return {"error": "Failed to extract entities from resume", "status_code": response.status_code, "response": response.text}
95
+
96
+ # Process the response from the Gemini API (or similar NLP API)
97
+ entities = response.json().get('entities', [])
 
 
98
  extracted_info = {"name": "Unknown Candidate", "email": "No Email", "contact": "No Contact"}
99
 
100
+ for entity in entities:
101
+ if entity['type'] == 'PERSON':
102
+ extracted_info['name'] = entity['name']
103
+ if entity['type'] == 'EMAIL':
104
+ extracted_info['email'] = entity['name']
105
+ if entity['type'] == 'PHONE_NUMBER':
106
+ extracted_info['contact'] = entity['name']
107
+
108
  return extracted_info
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  # Function to check similarity between resumes and job description
111
  def check_similarity(job_description, resume_files):
112
  results = []
 
125
  # Convert similarity score to percentage
126
  similarity_percentage = similarity_score * 100
127
 
128
+ # Extract leadership experience
129
  leadership_experience = extract_leadership_experience(resume_text)
130
 
131
  # Extract name, email, and contact info using Google Gemini API
 
181
  interface = gr.Interface(
182
  fn=check_similarity,
183
  inputs=[job_desc_input, resumes_input],
184
+ outputs=[results_output, gr.File(label="Download CSV", file_output=download_results)], # Updated here
185
  title="HR Assistant - Resume Screening & Leadership Experience",
186
  description="Upload job description and resumes to screen candidates for managerial and team leadership roles and extract candidate details.",
187
  allow_flagging="never"
188
  )
189
 
190
  interface.launch()