DreamStream-1 commited on
Commit
1cf7d5f
·
verified ·
1 Parent(s): 3a9f7f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -24
app.py CHANGED
@@ -5,46 +5,46 @@ import PyPDF2
5
  import io
6
  import re
7
  import streamlit as st
8
- from transformers import pipeline
9
  from sklearn.feature_extraction.text import TfidfVectorizer
10
  from sklearn.metrics.pairwise import cosine_similarity
11
 
12
- # Configure API Key
13
  api_key = os.getenv("GOOGLE_API_KEY")
14
  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
  genai.configure(api_key=api_key)
19
 
20
- # Text Generation Function
21
- def generate_response(prompt, model="text-bison-001", max_output_tokens=256):
22
  """
23
- Generate text response using Google Generative AI.
24
 
25
  Args:
26
- prompt (str): Input prompt for AI.
27
- model (str): Model to use for generation.
28
- max_output_tokens (int): Maximum token limit.
29
 
30
  Returns:
31
- str: Generated text or error message.
32
  """
33
  try:
34
- response = genai.chat(
35
  model=model,
36
- messages=[{"role": "user", "content": prompt}],
37
  temperature=0.7,
38
  max_output_tokens=max_output_tokens
39
  )
40
- return response.result['content']
41
  except Exception as e:
42
  return f"Error generating text: {str(e)}"
43
 
44
- # PDF Text Extraction
45
  def extract_text_from_pdf(file):
46
  """
47
- Extract text from uploaded PDF.
48
 
49
  Args:
50
  file (UploadedFile): PDF file uploaded via Streamlit.
@@ -77,7 +77,7 @@ def extract_contact_info(text):
77
  return (email.group(0) if email else "Not Available",
78
  phone.group(0) if phone else "Not Available")
79
 
80
- # Management Experience Extraction
81
  def extract_management_experience(text):
82
  """
83
  Extract management and leadership keywords and years.
@@ -99,7 +99,7 @@ def extract_management_experience(text):
99
 
100
  return years, ", ".join(found_keywords) if found_keywords else "Not Available"
101
 
102
- # TF-IDF Match Percentage
103
  def calculate_match_percentage(resume_text, job_description):
104
  """
105
  Calculate similarity between resume and job description using TF-IDF.
@@ -120,43 +120,63 @@ def calculate_match_percentage(resume_text, job_description):
120
  st.error(f"Error calculating match percentage: {str(e)}")
121
  return 0.0
122
 
123
- # Streamlit Interface
124
- st.title("Resume Analysis Tool: Management & Leadership Focus")
125
- st.markdown("### Upload Resume PDF and Enter Job Description")
126
 
127
  uploaded_file = st.file_uploader("Upload Resume PDF", type=["pdf"])
128
  job_description = st.text_area("Job Description", height=200)
129
 
130
  if uploaded_file and job_description.strip():
131
  if st.button("Analyze"):
 
132
  resume_text = extract_text_from_pdf(uploaded_file)
133
  if not resume_text:
134
  st.error("Failed to extract text from PDF. Ensure the file is valid.")
135
  st.stop()
136
 
 
137
  email, phone = extract_contact_info(resume_text)
 
 
138
  management_years, management_keywords = extract_management_experience(resume_text)
 
 
139
  match_percentage = calculate_match_percentage(resume_text, job_description)
140
 
 
141
  prompt = f"""
142
  Analyze the resume with respect to the job description.
143
  Resume Text: {resume_text}
144
  Job Description: {job_description}
145
- Include: Name, Skills, Education, Experience, and Match Percentage.
 
 
 
 
 
146
  """
147
- gemini_response = generate_response(prompt)
148
 
 
149
  results = {
150
  "Email": email,
151
  "Contact": phone,
152
  "Management Experience (Years)": management_years,
153
- "Keywords": management_keywords,
154
  "Match Percentage": match_percentage,
155
  "AI Summary": gemini_response
156
  }
157
 
158
  st.write(pd.DataFrame([results]))
 
 
159
  csv = pd.DataFrame([results]).to_csv(index=False)
160
- st.download_button("Download Results", data=csv, file_name="resume_analysis.csv", mime="text/csv")
 
 
 
 
 
161
  else:
162
- st.info("Upload a resume and provide a job description to begin analysis.")
 
5
  import io
6
  import re
7
  import streamlit as st
 
8
  from sklearn.feature_extraction.text import TfidfVectorizer
9
  from sklearn.metrics.pairwise import cosine_similarity
10
 
11
+ # Set API Key
12
  api_key = os.getenv("GOOGLE_API_KEY")
13
  if not api_key:
14
  st.error("API key not found. Please set GOOGLE_API_KEY in your environment variables.")
15
  st.stop()
16
 
17
+ # Configure Generative AI client
18
  genai.configure(api_key=api_key)
19
 
20
+ # Generate Response using Gemini Flash 1.5
21
+ def generate_with_gemini(prompt, model="gemini-1p5", max_output_tokens=256):
22
  """
23
+ Generate a response using the Gemini Flash 1.5 model.
24
 
25
  Args:
26
+ prompt (str): Input prompt for the AI model.
27
+ model (str): Model to use (default: "gemini-1p5").
28
+ max_output_tokens (int): Limit for the generated output tokens.
29
 
30
  Returns:
31
+ str: Generated text response from the model.
32
  """
33
  try:
34
+ response = genai.generate_text(
35
  model=model,
36
+ prompt=prompt,
37
  temperature=0.7,
38
  max_output_tokens=max_output_tokens
39
  )
40
+ return response.result # Adjust this if response structure differs
41
  except Exception as e:
42
  return f"Error generating text: {str(e)}"
43
 
44
+ # Extract Text from Uploaded PDF
45
  def extract_text_from_pdf(file):
46
  """
47
+ Extract text from uploaded PDF file.
48
 
49
  Args:
50
  file (UploadedFile): PDF file uploaded via Streamlit.
 
77
  return (email.group(0) if email else "Not Available",
78
  phone.group(0) if phone else "Not Available")
79
 
80
+ # Extract Management Experience
81
  def extract_management_experience(text):
82
  """
83
  Extract management and leadership keywords and years.
 
99
 
100
  return years, ", ".join(found_keywords) if found_keywords else "Not Available"
101
 
102
+ # Calculate Match Percentage
103
  def calculate_match_percentage(resume_text, job_description):
104
  """
105
  Calculate similarity between resume and job description using TF-IDF.
 
120
  st.error(f"Error calculating match percentage: {str(e)}")
121
  return 0.0
122
 
123
+ # Streamlit User Interface
124
+ st.title("Resume ATS Analysis Tool: Powered by Gemini Flash 1.5")
125
+ st.markdown("### Upload a Resume PDF and Enter a Job Description")
126
 
127
  uploaded_file = st.file_uploader("Upload Resume PDF", type=["pdf"])
128
  job_description = st.text_area("Job Description", height=200)
129
 
130
  if uploaded_file and job_description.strip():
131
  if st.button("Analyze"):
132
+ # Extract resume text
133
  resume_text = extract_text_from_pdf(uploaded_file)
134
  if not resume_text:
135
  st.error("Failed to extract text from PDF. Ensure the file is valid.")
136
  st.stop()
137
 
138
+ # Extract contact information
139
  email, phone = extract_contact_info(resume_text)
140
+
141
+ # Extract management experience
142
  management_years, management_keywords = extract_management_experience(resume_text)
143
+
144
+ # Calculate match percentage
145
  match_percentage = calculate_match_percentage(resume_text, job_description)
146
 
147
+ # Generate AI analysis
148
  prompt = f"""
149
  Analyze the resume with respect to the job description.
150
  Resume Text: {resume_text}
151
  Job Description: {job_description}
152
+ Provide details:
153
+ - Key Skills
154
+ - Education
155
+ - Management Experience (Years)
156
+ - Leadership Keywords
157
+ - Match Percentage
158
  """
159
+ gemini_response = generate_with_gemini(prompt)
160
 
161
+ # Display results
162
  results = {
163
  "Email": email,
164
  "Contact": phone,
165
  "Management Experience (Years)": management_years,
166
+ "Leadership Keywords": management_keywords,
167
  "Match Percentage": match_percentage,
168
  "AI Summary": gemini_response
169
  }
170
 
171
  st.write(pd.DataFrame([results]))
172
+
173
+ # Allow CSV download
174
  csv = pd.DataFrame([results]).to_csv(index=False)
175
+ st.download_button(
176
+ "Download Results",
177
+ data=csv,
178
+ file_name="resume_analysis_results.csv",
179
+ mime="text/csv"
180
+ )
181
  else:
182
+ st.info("Please upload a resume and enter a job description to proceed.")