DreamStream-1 commited on
Commit
87c9974
·
verified ·
1 Parent(s): 917698d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -13
app.py CHANGED
@@ -1,10 +1,11 @@
1
  import gradio as gr
2
- import requests
3
  from sentence_transformers import SentenceTransformer, util
4
  import docx
5
  import os
6
  from PyPDF2 import PdfReader
7
  import re
 
 
8
 
9
  # Load pre-trained model for sentence embedding
10
  model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
@@ -52,15 +53,24 @@ def read_docx_file(file_path):
52
  text += para.text
53
  return text
54
 
55
- # Extract leadership experience (looking for keywords like manager, team lead, leadership)
56
- def extract_leadership_experience(resume_text):
57
- leadership_keywords = ['manager', 'management', 'team lead', 'supervised', 'leadership', 'head', 'coordinator']
58
- for keyword in leadership_keywords:
59
- if keyword.lower() in resume_text.lower():
60
- return "Has leadership experience"
61
- return "No leadership experience"
62
-
63
- # System prompt to extract candidate details using Gemini API
 
 
 
 
 
 
 
 
 
64
  def extract_entities_via_gemini(resume_text):
65
  api_key = get_google_api_key() # Fetch the API key from environment variables
66
  endpoint = "https://gemini.googleapis.com/v1/documents:analyzeEntities" # Placeholder API endpoint (adjust as necessary)
@@ -81,11 +91,11 @@ def extract_entities_via_gemini(resume_text):
81
  response = requests.post(endpoint, headers=headers, json=document)
82
 
83
  if response.status_code != 200:
84
- return {"error": "Failed to extract entities from resume"}
85
 
86
  # Process the response from the Gemini API (or similar NLP API)
87
  entities = response.json().get('entities', [])
88
- extracted_info = {}
89
 
90
  for entity in entities:
91
  if entity['type'] == 'PERSON':
@@ -162,13 +172,22 @@ results_output = gr.Dataframe(headers=[
162
  label="Analysis Results"
163
  )
164
 
 
 
 
 
 
165
  # Gradio Interface
166
  interface = gr.Interface(
167
  fn=check_similarity,
168
  inputs=[job_desc_input, resumes_input],
169
  outputs=[results_output],
170
  title="HR Assistant - Resume Screening & Leadership Experience",
171
- description="Upload job description and resumes to screen candidates for managerial and team leadership roles and extract candidate details."
 
172
  )
173
 
 
 
 
174
  interface.launch()
 
1
  import gradio as gr
 
2
  from sentence_transformers import SentenceTransformer, util
3
  import docx
4
  import os
5
  from PyPDF2 import PdfReader
6
  import re
7
+ import requests
8
+ import pandas as pd
9
 
10
  # Load pre-trained model for sentence embedding
11
  model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
 
53
  text += para.text
54
  return text
55
 
56
+ # System prompt to extract candidate details from the resume
57
+ def system_prompt_to_extract_info(resume_text):
58
+ prompt = f"""
59
+ Extract the following information from the resume:
60
+ 1. Candidate's Full Name
61
+ 2. Candidate's Email Address
62
+ 3. Candidate's Contact Number
63
+
64
+ Resume Text: {resume_text}
65
+
66
+ Return the results in the following format:
67
+ - Name: [Extracted Name]
68
+ - Email: [Extracted Email]
69
+ - Contact: [Extracted Contact Number]
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)
 
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.json()}
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':
 
172
  label="Analysis Results"
173
  )
174
 
175
+ # Function to allow CSV download
176
+ def download_results(results):
177
+ df = pd.DataFrame(results, columns=["Resume File", "Similarity Score (%)", "Eligibility", "Candidate Name", "Leadership Experience", "Email", "Contact"])
178
+ return df.to_csv(index=False)
179
+
180
  # Gradio Interface
181
  interface = gr.Interface(
182
  fn=check_similarity,
183
  inputs=[job_desc_input, resumes_input],
184
  outputs=[results_output],
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
+ # Adding the download button for CSV
191
+ interface.add_component(gr.File, "Download CSV", fn=download_results)
192
+
193
  interface.launch()