hruday96 commited on
Commit
ead6755
·
verified ·
1 Parent(s): 853f4a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -33
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  from docx import Document
3
  import PyPDF2
4
  import google.generativeai as genai # Correct package for Gemini
 
5
 
6
  # Title of the app
7
  st.title("JD-Resume Fit Check App")
@@ -20,22 +21,18 @@ with col1:
20
  st.subheader('Upload your Resume')
21
  uploaded_file = st.file_uploader('Upload your Resume (PDF or DOCX)', type=['pdf', 'docx'])
22
  resume_text = ""
23
-
24
- try:
25
- if uploaded_file:
26
- if uploaded_file.type == 'application/pdf':
27
- pdf_reader = PyPDF2.PdfReader(uploaded_file)
28
- for page in pdf_reader.pages:
29
- text = page.extract_text()
30
- if text:
31
- resume_text += text
32
- st.success("Resume uploaded and processed!")
33
- elif uploaded_file.type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
34
- doc = Document(uploaded_file)
35
- resume_text = '\n'.join([paragraph.text for paragraph in doc.paragraphs if paragraph.text])
36
- st.success("Resume uploaded and processed!")
37
- except Exception as e:
38
- st.error(f"Error processing file: {e}")
39
 
40
  # Right column: JD input
41
  with col2:
@@ -57,9 +54,8 @@ if resume_text and job_description:
57
  # Truncate input if too large
58
  max_input_tokens = 4000 # Example limit
59
  combined_input = f"{resume_text}\n{job_description}"
60
- words = combined_input.split()
61
- if len(words) > max_input_tokens:
62
- combined_input = ' '.join(words[:max_input_tokens])
63
  st.warning("Input text truncated to fit the model's token limit.")
64
 
65
  # Display a "Generate" button
@@ -68,14 +64,13 @@ if resume_text and job_description:
68
 
69
  # Construct the prompt for analysis
70
  prompt = f"""
71
- You are an expert recruiter and hiring manager assistant. Analyze the following details and provide a structured response in the specified format:
72
 
 
73
  1. Resume: {resume_text}
74
-
75
  2. Job Description: {job_description}
76
 
77
  ### Tasks:
78
-
79
  1. Identify the key skills, experiences, and qualifications mentioned in the Job Description.
80
  2. Compare the above with the details provided in the Resume.
81
  3. Provide a match score (out of 10) based on how well the Resume aligns with the Job Description.
@@ -84,22 +79,36 @@ if resume_text and job_description:
84
  6. Recommend relevant topics for interview preparation based on the Job Description.
85
 
86
  ### Response Format:
87
- 1. Match Score: [Provide a score out of 10]
88
- 2. Justification: [Provide a detailed analysis of how well the resume matches the job description]
89
- 3. Resume Suggestions: [List actionable changes to align the resume with the job description]
90
- 4. Interview Preparation Topics: [List relevant topics for interview preparation]
 
 
 
 
 
 
91
  """
92
 
93
  try:
94
- # Initialize the generative model
95
- model = genai.GenerativeModel('gemini-pro')
96
-
97
  # Generate content using the Gemini API
98
- response = model.generate_content(prompt)
99
-
100
- # Ensure response contains text
 
 
 
 
 
 
 
101
  if response and hasattr(response, "text"):
102
- st.write(response.text) # Display the generated response
 
 
 
 
103
  else:
104
  st.error("No response received from the API.")
105
 
 
2
  from docx import Document
3
  import PyPDF2
4
  import google.generativeai as genai # Correct package for Gemini
5
+ import re # For output validation
6
 
7
  # Title of the app
8
  st.title("JD-Resume Fit Check App")
 
21
  st.subheader('Upload your Resume')
22
  uploaded_file = st.file_uploader('Upload your Resume (PDF or DOCX)', type=['pdf', 'docx'])
23
  resume_text = ""
24
+ if uploaded_file is not None:
25
+ if uploaded_file.type == 'application/pdf':
26
+ # Extract text from PDF
27
+ pdf_reader = PyPDF2.PdfReader(uploaded_file)
28
+ for page in pdf_reader.pages:
29
+ resume_text += page.extract_text()
30
+ st.success("Resume uploaded and processed!")
31
+ elif uploaded_file.type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
32
+ # Extract text from DOCX
33
+ doc = Document(uploaded_file)
34
+ resume_text = '\n'.join([paragraph.text for paragraph in doc.paragraphs])
35
+ st.success("Resume uploaded and processed!")
 
 
 
 
36
 
37
  # Right column: JD input
38
  with col2:
 
54
  # Truncate input if too large
55
  max_input_tokens = 4000 # Example limit
56
  combined_input = f"{resume_text}\n{job_description}"
57
+ if len(combined_input.split()) > max_input_tokens:
58
+ combined_input = ' '.join(combined_input.split()[:max_input_tokens])
 
59
  st.warning("Input text truncated to fit the model's token limit.")
60
 
61
  # Display a "Generate" button
 
64
 
65
  # Construct the prompt for analysis
66
  prompt = f"""
67
+ You are an expert recruiter and hiring manager assistant. Analyze the following details and strictly provide the response in the specified format:
68
 
69
+ ### Input:
70
  1. Resume: {resume_text}
 
71
  2. Job Description: {job_description}
72
 
73
  ### Tasks:
 
74
  1. Identify the key skills, experiences, and qualifications mentioned in the Job Description.
75
  2. Compare the above with the details provided in the Resume.
76
  3. Provide a match score (out of 10) based on how well the Resume aligns with the Job Description.
 
79
  6. Recommend relevant topics for interview preparation based on the Job Description.
80
 
81
  ### Response Format:
82
+ 1. **Match Score:** [Provide a score out of 10]
83
+ 2. **Justification:** [Detailed analysis of how well the resume matches the job description]
84
+ 3. **Resume Suggestions:** [Actionable changes to align the resume with the job description]
85
+ 4. **Interview Preparation Topics:** [Relevant topics for interview preparation]
86
+
87
+ Example:
88
+ 1. **Match Score:** 8/10
89
+ 2. **Justification:** The resume covers 80% of the key skills but lacks specific cloud experience.
90
+ 3. **Resume Suggestions:** Add certifications in cloud platforms and mention specific cloud-related projects.
91
+ 4. **Interview Preparation Topics:** Cloud computing, project management, and teamwork.
92
  """
93
 
94
  try:
 
 
 
95
  # Generate content using the Gemini API
96
+ response = genai.generate_content(
97
+ model='gemini-pro',
98
+ prompt=prompt,
99
+ temperature=0.1, # Lower value for deterministic output
100
+ top_p=0.9, # Wider range of tokens considered
101
+ max_output_tokens=500
102
+ )
103
+
104
+ # Validate and enforce format consistency
105
+ expected_format = r"(1\. \*\*Match Score:\*\* .+\n2\. \*\*Justification:\*\* .+\n3\. \*\*Resume Suggestions:\*\* .+\n4\. \*\*Interview Preparation Topics:\*\* .+)"
106
  if response and hasattr(response, "text"):
107
+ output_text = response.text
108
+ if re.match(expected_format, output_text):
109
+ st.write(output_text) # Display the generated response
110
+ else:
111
+ st.error("The response does not match the expected format. Please try again.")
112
  else:
113
  st.error("No response received from the API.")
114