Spaces:
Sleeping
Sleeping
File size: 4,957 Bytes
adf260f 19731f7 6249bdd 19731f7 4dd644a 19731f7 17d8c9a 19731f7 69555d4 19731f7 395704e 17d8c9a 395704e 4dd644a 853f4a9 4dd644a 17d8c9a 594c8cf 17d8c9a 594c8cf 17d8c9a 594c8cf 853f4a9 594c8cf 17d8c9a 4dd644a 69555d4 4dd644a 17d8c9a 22b0e65 17d8c9a 22b0e65 98cbf1e 22b0e65 bc209fd ead6755 17d8c9a 395704e 17d8c9a 395704e 853f4a9 4dd644a 395704e cb3a946 19731f7 4dd644a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
import streamlit as st
from docx import Document
import PyPDF2
import google.generativeai as genai # Correct package for Gemini
# Title of the app
st.title("JD-Resume Fit Check App")
# Retrieve the API key from Streamlit secrets
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
# Configure the Google Generative AI API with your API key
genai.configure(api_key=GOOGLE_API_KEY)
# Create two columns
col1, col2 = st.columns(2)
# Left column: Resume upload
with col1:
st.subheader('Upload your Resume')
uploaded_file = st.file_uploader('Upload your Resume (PDF or DOCX)', type=['pdf', 'docx'])
resume_text = ""
try:
if uploaded_file:
if uploaded_file.type == 'application/pdf':
pdf_reader = PyPDF2.PdfReader(uploaded_file)
for page in pdf_reader.pages:
text = page.extract_text()
if text:
resume_text += text
st.success("Resume uploaded and processed!")
elif uploaded_file.type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
doc = Document(uploaded_file)
resume_text = '\n'.join([paragraph.text for paragraph in doc.paragraphs if paragraph.text])
st.success("Resume uploaded and processed!")
except Exception as e:
st.error(f"Error processing file: {e}")
# Right column: JD input
with col2:
st.subheader('Paste your Job Description')
job_description = st.text_area('Enter Job Description', '', height=150)
if job_description:
st.success("Job Description received!")
# Bottom section: Output
st.subheader("Fit Check Results")
# Ensure both resume and JD are provided before proceeding
if resume_text and job_description:
# Check for minimum content length
if len(resume_text.strip()) < 100 or len(job_description.strip()) < 100:
st.error("Please provide more detailed Resume and Job Description.")
st.stop()
# Truncate input if too large
max_input_tokens = 4000 # Example limit
combined_input = f"{resume_text}\n{job_description}"
words = combined_input.split()
if len(words) > max_input_tokens:
combined_input = ' '.join(words[:max_input_tokens])
st.warning("Input text truncated to fit the model's token limit.")
# Display a "Generate" button
if st.button("Generate Match Score"):
st.write("Your resume and job description are being processed...")
# Construct the prompt for analysis
prompt = f"""
You are an expert recruiter and hiring manager assistant. Analyze the following details and provide a structured response in the specified format:
1. Resume: {resume_text}
2. Job Description: {job_description}
### Tasks:
1. Identify the key skills, experiences, and qualifications mentioned in the Job Description.
2. Compare the above with the details provided in the Resume.
3. Provide a match score (out of 10) based on how well the Resume aligns with the Job Description.
4. Offer a detailed justification for the match score.
5. Suggest changes to improve the Resume so that it matches the Job Description better.
6. Recommend relevant topics for interview preparation based on the Job Description.
### Response Format:
1. Match Score: [Provide a score out of 10]
2. Justification: [Provide a detailed analysis of how well the resume matches the job description]
3. Resume Suggestions: [List actionable changes to align the resume with the job description]
4. Interview Preparation Topics: [List relevant topics for interview preparation]
"""
try:
# Initialize the generative model
model = genai.GenerativeModel("gemini-pro")
# Generate content using the Gemini API
response = model.generate_content(
prompt,
generation_config=genai.types.GenerationConfig(
temperature=0.0, # Ensures deterministic output
max_output_tokens=500, # Limits the response length to 500 tokens
candidate_count=1 # Generates only one candidate
)
)
# Ensure response contains text
if response and hasattr(response, "text"):
st.write(response.text) # Display the generated response
else:
st.error("No response received from the API.")
except Exception as e:
st.error(f"API Error: {str(e)}")
else:
st.write("Please upload both a resume and a job description.")
# Add space or content at the bottom
st.write("\n" * 20) # Adds space to push the content down
# Footer
st.markdown("Built with 🧠 by Hruday & Google Gemini")
|