Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
|
|
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,18 +20,22 @@ with col1:
|
|
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 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Right column: JD input
|
38 |
with col2:
|
@@ -54,8 +57,9 @@ if resume_text and job_description:
|
|
54 |
# Truncate input if too large
|
55 |
max_input_tokens = 4000 # Example limit
|
56 |
combined_input = f"{resume_text}\n{job_description}"
|
57 |
-
|
58 |
-
|
|
|
59 |
st.warning("Input text truncated to fit the model's token limit.")
|
60 |
|
61 |
# Display a "Generate" button
|
@@ -64,13 +68,14 @@ if resume_text and job_description:
|
|
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
|
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,23 +84,17 @@ if resume_text and job_description:
|
|
79 |
6. Recommend relevant topics for interview preparation based on the Job Description.
|
80 |
|
81 |
### Response Format:
|
82 |
-
1.
|
83 |
-
2.
|
84 |
-
3.
|
85 |
-
4.
|
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 |
-
# Initialize the
|
96 |
-
#model = genai.GenerativeModel(model='gemini-pro')
|
97 |
model = genai.GenerativeModel("gemini-pro")
|
98 |
-
|
|
|
99 |
response = model.generate_content(
|
100 |
prompt,
|
101 |
generation_config=genai.types.GenerationConfig(
|
@@ -106,14 +105,9 @@ if resume_text and job_description:
|
|
106 |
)
|
107 |
|
108 |
|
109 |
-
#
|
110 |
-
expected_format = r"(1\. \*\*Match Score:\*\* .+\n2\. \*\*Justification:\*\* .+\n3\. \*\*Resume Suggestions:\*\* .+\n4\. \*\*Interview Preparation Topics:\*\* .+)"
|
111 |
if response and hasattr(response, "text"):
|
112 |
-
|
113 |
-
if re.match(expected_format, output_text):
|
114 |
-
st.write(output_text) # Display the generated response
|
115 |
-
else:
|
116 |
-
st.error("The response does not match the expected format. Please try again.")
|
117 |
else:
|
118 |
st.error("No response received from the API.")
|
119 |
|
|
|
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 |
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 |
# 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 |
|
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 |
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(
|
99 |
prompt,
|
100 |
generation_config=genai.types.GenerationConfig(
|
|
|
105 |
)
|
106 |
|
107 |
|
108 |
+
# Ensure response contains text
|
|
|
109 |
if response and hasattr(response, "text"):
|
110 |
+
st.write(response.text) # Display the generated response
|
|
|
|
|
|
|
|
|
111 |
else:
|
112 |
st.error("No response received from the API.")
|
113 |
|