Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +341 -98
src/streamlit_app.py
CHANGED
|
@@ -9,181 +9,424 @@ from langchain.chains import LLMChain
|
|
| 9 |
from langchain.prompts import PromptTemplate
|
| 10 |
from sentence_transformers import SentenceTransformer
|
| 11 |
from sklearn.metrics.pairwise import cosine_similarity
|
|
|
|
| 12 |
|
| 13 |
# ----------------------------
|
| 14 |
# 1. Configuration
|
| 15 |
# ----------------------------
|
| 16 |
-
|
|
|
|
| 17 |
|
|
|
|
| 18 |
DEEPSEEK_MODEL = "deepseek-ai/deepseek-llm-67b" # Alternatives: deepseek-ai/deepseek-r1
|
| 19 |
|
| 20 |
# ----------------------------
|
| 21 |
-
# 2. Document Processing
|
| 22 |
# ----------------------------
|
|
|
|
| 23 |
def extract_text(file):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
def clean_text(text):
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# ----------------------------
|
| 38 |
-
# 3. DeepSeek
|
| 39 |
# ----------------------------
|
|
|
|
| 40 |
def init_deepseek_llm():
|
|
|
|
| 41 |
return HuggingFaceHub(
|
| 42 |
repo_id=DEEPSEEK_MODEL,
|
| 43 |
model_kwargs={
|
| 44 |
"temperature": 0.1,
|
| 45 |
"max_new_tokens": 1024,
|
| 46 |
-
"repetition_penalty": 1.1
|
|
|
|
| 47 |
}
|
| 48 |
)
|
| 49 |
|
| 50 |
def analyze_with_deepseek(prompt_template, input_text):
|
|
|
|
| 51 |
llm = init_deepseek_llm()
|
| 52 |
prompt = PromptTemplate.from_template(prompt_template)
|
| 53 |
chain = LLMChain(llm=llm, prompt=prompt)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# ----------------------------
|
| 63 |
-
# 4. Prompt Templates
|
| 64 |
# ----------------------------
|
| 65 |
-
JD_ANALYSIS_PROMPT = """[INST]
|
|
|
|
| 66 |
{
|
| 67 |
-
"required_skills": ["list", "
|
| 68 |
-
"preferred_skills": ["list"],
|
| 69 |
-
"min_experience":
|
| 70 |
-
"certifications": ["list"],
|
| 71 |
-
"keywords": ["industry", "specific", "terms"]
|
|
|
|
| 72 |
}
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
{text} [/INST]"""
|
| 75 |
|
| 76 |
-
RESUME_ANALYSIS_PROMPT = """[INST]
|
|
|
|
| 77 |
{
|
| 78 |
-
"skills": ["
|
| 79 |
"experience": [
|
| 80 |
{
|
| 81 |
-
"role": "position",
|
| 82 |
"years": number,
|
| 83 |
-
"achievements": ["
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
}
|
| 85 |
],
|
| 86 |
-
"
|
| 87 |
-
"certifications": ["list"]
|
| 88 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
Resume text:
|
| 90 |
{text} [/INST]"""
|
| 91 |
|
| 92 |
# ----------------------------
|
| 93 |
-
# 5. Matching Algorithm
|
| 94 |
# ----------------------------
|
|
|
|
| 95 |
def calculate_match(jd_data, resume_data):
|
|
|
|
|
|
|
| 96 |
model = SentenceTransformer('BAAI/bge-small-en-v1.5')
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
exact_match = required_matches / len(jd_data["required_skills"]) if jd_data["required_skills"] else 0
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
|
|
|
| 114 |
score = int(100 * (
|
| 115 |
-
0.
|
| 116 |
-
0.3 *
|
| 117 |
-
0.2 *
|
| 118 |
-
|
|
|
|
| 119 |
))
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
return {
|
| 122 |
"match_score": score,
|
| 123 |
-
"missing_skills":
|
| 124 |
-
"
|
| 125 |
-
"
|
| 126 |
-
"
|
| 127 |
}
|
| 128 |
|
| 129 |
# ----------------------------
|
| 130 |
-
# 6. Streamlit UI
|
| 131 |
# ----------------------------
|
| 132 |
def main():
|
| 133 |
-
st.set_page_config(
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
|
|
|
|
| 137 |
|
| 138 |
-
with
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
resume_input = st.text_area("Paste Resume Text", height=300)
|
| 144 |
-
resume_file = st.file_uploader("Or upload Resume", type=["pdf", "docx"])
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
st.warning("Please provide both Job Description and Resume.")
|
| 149 |
-
return
|
| 150 |
|
| 151 |
-
with
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
|
|
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
-
with st.expander("
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
suggestions = llm.invoke(prompt)
|
| 177 |
-
st.write(suggestions)
|
| 178 |
|
| 179 |
-
|
| 180 |
-
st.
|
| 181 |
-
|
| 182 |
-
"resume_analysis": resume_data
|
| 183 |
-
})
|
| 184 |
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
-
main()
|
|
|
|
| 9 |
from langchain.prompts import PromptTemplate
|
| 10 |
from sentence_transformers import SentenceTransformer
|
| 11 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 12 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 13 |
|
| 14 |
# ----------------------------
|
| 15 |
# 1. Configuration
|
| 16 |
# ----------------------------
|
| 17 |
+
# Initialize from Streamlit secrets or environment variables
|
| 18 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets.get("HUGGINGFACEHUB_API_TOKEN", os.getenv("HUGGINGFACEHUB_API_TOKEN"))
|
| 19 |
|
| 20 |
+
# Model configuration
|
| 21 |
DEEPSEEK_MODEL = "deepseek-ai/deepseek-llm-67b" # Alternatives: deepseek-ai/deepseek-r1
|
| 22 |
|
| 23 |
# ----------------------------
|
| 24 |
+
# 2. Enhanced Document Processing
|
| 25 |
# ----------------------------
|
| 26 |
+
@st.cache_data(show_spinner=False)
|
| 27 |
def extract_text(file):
|
| 28 |
+
"""Robust text extraction with error handling"""
|
| 29 |
+
try:
|
| 30 |
+
if file.name.endswith('.pdf'):
|
| 31 |
+
with st.spinner("Extracting PDF text..."):
|
| 32 |
+
reader = PdfReader(file)
|
| 33 |
+
text = " ".join([page.extract_text() or "" for page in reader.pages])
|
| 34 |
+
if not text.strip():
|
| 35 |
+
raise ValueError("PDF appears to be image-based. Try converting to text first.")
|
| 36 |
+
return clean_text(text)
|
| 37 |
+
elif file.name.endswith('.docx'):
|
| 38 |
+
with st.spinner("Extracting Word document..."):
|
| 39 |
+
return clean_text(docx2txt.process(file))
|
| 40 |
+
raise ValueError("Unsupported file format")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
st.error(f"Error processing {file.name}: {str(e)}")
|
| 43 |
+
raise
|
| 44 |
|
| 45 |
def clean_text(text):
|
| 46 |
+
"""Advanced text cleaning"""
|
| 47 |
+
# Remove non-printable characters
|
| 48 |
+
text = re.sub(r'[^\x20-\x7E\u2013\u2014\u2018\u2019\u201C\u201D]', ' ', text)
|
| 49 |
+
# Normalize whitespace and bullet points
|
| 50 |
+
text = re.sub(r'\s+', ' ', text).strip()
|
| 51 |
+
# Standardize common resume section headers
|
| 52 |
+
text = re.sub(r'(?i)\b(?:work\s*history|employment\s*history)\b', 'EXPERIENCE', text)
|
| 53 |
+
return text
|
| 54 |
|
| 55 |
# ----------------------------
|
| 56 |
+
# 3. Optimized DeepSeek Integration
|
| 57 |
# ----------------------------
|
| 58 |
+
@st.cache_resource
|
| 59 |
def init_deepseek_llm():
|
| 60 |
+
"""Cached model initialization"""
|
| 61 |
return HuggingFaceHub(
|
| 62 |
repo_id=DEEPSEEK_MODEL,
|
| 63 |
model_kwargs={
|
| 64 |
"temperature": 0.1,
|
| 65 |
"max_new_tokens": 1024,
|
| 66 |
+
"repetition_penalty": 1.1,
|
| 67 |
+
"top_p": 0.9
|
| 68 |
}
|
| 69 |
)
|
| 70 |
|
| 71 |
def analyze_with_deepseek(prompt_template, input_text):
|
| 72 |
+
"""Robust analysis with retry logic"""
|
| 73 |
llm = init_deepseek_llm()
|
| 74 |
prompt = PromptTemplate.from_template(prompt_template)
|
| 75 |
chain = LLMChain(llm=llm, prompt=prompt)
|
| 76 |
|
| 77 |
+
max_retries = 2
|
| 78 |
+
for attempt in range(max_retries):
|
| 79 |
+
try:
|
| 80 |
+
response = chain.run(text=input_text)
|
| 81 |
+
# Improved JSON extraction with fallback
|
| 82 |
+
try:
|
| 83 |
+
return json.loads(response.strip())
|
| 84 |
+
except json.JSONDecodeError:
|
| 85 |
+
# Handle cases where response includes markdown code blocks
|
| 86 |
+
cleaned = re.sub(r'^```json|```$', '', response, flags=re.MULTILINE)
|
| 87 |
+
return json.loads(cleaned.strip())
|
| 88 |
+
except Exception as e:
|
| 89 |
+
if attempt == max_retries - 1:
|
| 90 |
+
st.error(f"Analysis failed after {max_retries} attempts: {str(e)}")
|
| 91 |
+
return {"error": str(e)}
|
| 92 |
+
continue
|
| 93 |
|
| 94 |
# ----------------------------
|
| 95 |
+
# 4. Enhanced Prompt Templates
|
| 96 |
# ----------------------------
|
| 97 |
+
JD_ANALYSIS_PROMPT = """[INST] <<SYS>>
|
| 98 |
+
You are an expert HR analyst. Extract these details as valid JSON:
|
| 99 |
{
|
| 100 |
+
"required_skills": ["list", "specific", "technical", "skills"],
|
| 101 |
+
"preferred_skills": ["list", "of", "nice-to-have", "skills"],
|
| 102 |
+
"min_experience": number,
|
| 103 |
+
"certifications": ["list", "of", "required", "certifications"],
|
| 104 |
+
"keywords": ["industry", "specific", "terms"],
|
| 105 |
+
"education_level": "degree requirement"
|
| 106 |
}
|
| 107 |
+
Important:
|
| 108 |
+
- Be specific with skills (e.g., "Python (Pandas, NumPy)" not just "Python")
|
| 109 |
+
- Convert experience requirements to years (e.g., "5+ years" β 5)
|
| 110 |
+
- Include only concrete requirements
|
| 111 |
+
<</SYS>>
|
| 112 |
+
Job description:
|
| 113 |
{text} [/INST]"""
|
| 114 |
|
| 115 |
+
RESUME_ANALYSIS_PROMPT = """[INST] <<SYS>>
|
| 116 |
+
You are a professional resume parser. Extract as valid JSON:
|
| 117 |
{
|
| 118 |
+
"skills": ["specific", "technical", "skills"],
|
| 119 |
"experience": [
|
| 120 |
{
|
| 121 |
+
"role": "position title",
|
| 122 |
"years": number,
|
| 123 |
+
"achievements": ["quantified", "accomplishments"]
|
| 124 |
+
}
|
| 125 |
+
],
|
| 126 |
+
"education": [
|
| 127 |
+
{
|
| 128 |
+
"degree": "degree name",
|
| 129 |
+
"field": "field of study",
|
| 130 |
+
"institution": "school name"
|
| 131 |
}
|
| 132 |
],
|
| 133 |
+
"certifications": ["certificate", "names"]
|
|
|
|
| 134 |
}
|
| 135 |
+
Rules:
|
| 136 |
+
- Estimate years of experience for each role
|
| 137 |
+
- Include only hard skills (no "teamwork" etc.)
|
| 138 |
+
- Quantify achievements where possible
|
| 139 |
+
<</SYS>>
|
| 140 |
Resume text:
|
| 141 |
{text} [/INST]"""
|
| 142 |
|
| 143 |
# ----------------------------
|
| 144 |
+
# 5. Advanced Matching Algorithm
|
| 145 |
# ----------------------------
|
| 146 |
+
@st.cache_data
|
| 147 |
def calculate_match(jd_data, resume_data):
|
| 148 |
+
"""Comprehensive matching with skill clustering"""
|
| 149 |
+
# Initialize embedding model
|
| 150 |
model = SentenceTransformer('BAAI/bge-small-en-v1.5')
|
| 151 |
|
| 152 |
+
# Skill matching with clustering
|
| 153 |
+
jd_skills = [skill.lower() for skill in jd_data["required_skills"] + jd_data["preferred_skills"]]
|
| 154 |
+
resume_skills = [skill.lower() for skill in resume_data["skills"]]
|
| 155 |
|
| 156 |
+
# Create skill embeddings
|
| 157 |
+
jd_embeddings = model.encode(jd_skills)
|
| 158 |
+
resume_embeddings = model.encode(resume_skills)
|
| 159 |
|
| 160 |
+
# Calculate similarity matrix
|
| 161 |
+
similarity_matrix = cosine_similarity(jd_embeddings, resume_embeddings)
|
| 162 |
+
|
| 163 |
+
# Find best matches for each JD skill
|
| 164 |
+
matched_skills = {}
|
| 165 |
+
for i, jd_skill in enumerate(jd_skills):
|
| 166 |
+
best_match_idx = similarity_matrix[i].argmax()
|
| 167 |
+
if similarity_matrix[i][best_match_idx] > 0.65: # Threshold for valid match
|
| 168 |
+
matched_skills[jd_skill] = {
|
| 169 |
+
"resume_skill": resume_skills[best_match_idx],
|
| 170 |
+
"similarity": float(similarity_matrix[i][best_match_idx])
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
# Calculate scores
|
| 174 |
+
required_matches = sum(1 for skill in jd_data["required_skills"]
|
| 175 |
+
if skill.lower() in matched_skills)
|
| 176 |
exact_match = required_matches / len(jd_data["required_skills"]) if jd_data["required_skills"] else 0
|
| 177 |
|
| 178 |
+
# Experience calculation with role relevance
|
| 179 |
+
total_exp = 0
|
| 180 |
+
for exp in resume_data["experience"]:
|
| 181 |
+
# Simple role matching - could be enhanced with embeddings
|
| 182 |
+
role_weight = 1.0 # Default weight
|
| 183 |
+
if any(keyword in exp["role"].lower() for keyword in ["engineer", "developer"]):
|
| 184 |
+
role_weight = 1.2 if "engineer" in jd_data.get("keywords", []) else 1.0
|
| 185 |
+
total_exp += exp["years"] * role_weight
|
| 186 |
+
|
| 187 |
+
exp_ratio = min(total_exp / jd_data.get("min_experience", 1), 2.0)
|
| 188 |
|
| 189 |
+
# Final weighted score
|
| 190 |
score = int(100 * (
|
| 191 |
+
0.5 * exact_match +
|
| 192 |
+
0.3 * exp_ratio +
|
| 193 |
+
0.2 * (len(set(jd_data.get("certifications", [])) &
|
| 194 |
+
set(resume_data.get("certifications", []))) /
|
| 195 |
+
max(1, len(jd_data.get("certifications", [])))
|
| 196 |
))
|
| 197 |
|
| 198 |
+
# Prepare missing skills with alternatives
|
| 199 |
+
missing_skills = []
|
| 200 |
+
for skill in jd_data["required_skills"]:
|
| 201 |
+
if skill.lower() not in matched_skills:
|
| 202 |
+
# Find similar skills in resume that didn't meet threshold
|
| 203 |
+
similar_in_resume = [
|
| 204 |
+
s for s in resume_skills
|
| 205 |
+
if cosine_similarity(
|
| 206 |
+
model.encode([skill.lower()]),
|
| 207 |
+
model.encode([s])
|
| 208 |
+
)[0][0] > 0.5
|
| 209 |
+
]
|
| 210 |
+
missing_skills.append({
|
| 211 |
+
"required": skill,
|
| 212 |
+
"similar_in_resume": similar_in_resume[:3] # Top 3 similar
|
| 213 |
+
})
|
| 214 |
+
|
| 215 |
return {
|
| 216 |
"match_score": score,
|
| 217 |
+
"missing_skills": missing_skills,
|
| 218 |
+
"skill_coverage": f"{exact_match * 100:.1f}%",
|
| 219 |
+
"experience_adequacy": f"{min(exp_ratio, 1.0) * 100:.1f}%",
|
| 220 |
+
"matched_skills": matched_skills
|
| 221 |
}
|
| 222 |
|
| 223 |
# ----------------------------
|
| 224 |
+
# 6. Streamlit UI with Performance Optimizations
|
| 225 |
# ----------------------------
|
| 226 |
def main():
|
| 227 |
+
st.set_page_config(
|
| 228 |
+
page_title="DeepSeek Resume Analyzer Pro",
|
| 229 |
+
layout="wide",
|
| 230 |
+
initial_sidebar_state="expanded"
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
# Custom CSS
|
| 234 |
+
st.markdown("""
|
| 235 |
+
<style>
|
| 236 |
+
.stProgress > div > div > div > div {
|
| 237 |
+
background-color: #4CAF50;
|
| 238 |
+
}
|
| 239 |
+
.st-b7 {
|
| 240 |
+
color: white;
|
| 241 |
+
}
|
| 242 |
+
.st-c0 {
|
| 243 |
+
background-color: #2E86AB;
|
| 244 |
+
}
|
| 245 |
+
div[data-testid="stExpander"] div[role="button"] p {
|
| 246 |
+
font-size: 1.2rem;
|
| 247 |
+
font-weight: bold;
|
| 248 |
+
}
|
| 249 |
+
</style>
|
| 250 |
+
""", unsafe_allow_html=True)
|
| 251 |
|
| 252 |
+
st.title("π DeepSeek Resume Analyzer Pro")
|
| 253 |
+
st.caption("Powered by DeepSeek LLM and advanced NLP")
|
| 254 |
|
| 255 |
+
with st.sidebar:
|
| 256 |
+
st.header("Configuration")
|
| 257 |
+
analysis_mode = st.radio(
|
| 258 |
+
"Analysis Depth",
|
| 259 |
+
["Standard", "Advanced"],
|
| 260 |
+
help="Advanced mode uses more API credits but provides deeper analysis"
|
| 261 |
+
)
|
| 262 |
+
st.info("π‘ For best results, upload the original PDF/DOCX files")
|
| 263 |
|
| 264 |
+
tab1, tab2 = st.tabs(["Analyzer", "How It Works"])
|
|
|
|
|
|
|
| 265 |
|
| 266 |
+
with tab1:
|
| 267 |
+
col1, col2 = st.columns(2, gap="large")
|
|
|
|
|
|
|
| 268 |
|
| 269 |
+
with col1:
|
| 270 |
+
st.subheader("Job Description")
|
| 271 |
+
jd_source = st.radio(
|
| 272 |
+
"JD Input Method",
|
| 273 |
+
["Upload", "Paste"],
|
| 274 |
+
horizontal=True,
|
| 275 |
+
key="jd_source"
|
| 276 |
+
)
|
| 277 |
+
if jd_source == "Upload":
|
| 278 |
+
jd_file = st.file_uploader(
|
| 279 |
+
"Upload Job Description (PDF/DOCX)",
|
| 280 |
+
type=["pdf", "docx"],
|
| 281 |
+
key="jd_upload"
|
| 282 |
+
)
|
| 283 |
+
jd_text = ""
|
| 284 |
+
else:
|
| 285 |
+
jd_text = st.text_area(
|
| 286 |
+
"Paste Job Description",
|
| 287 |
+
height=300,
|
| 288 |
+
placeholder="Paste the full job description here...",
|
| 289 |
+
key="jd_text"
|
| 290 |
+
)
|
| 291 |
+
jd_file = None
|
| 292 |
+
|
| 293 |
+
with col2:
|
| 294 |
+
st.subheader("Resume")
|
| 295 |
+
resume_source = st.radio(
|
| 296 |
+
"Resume Input Method",
|
| 297 |
+
["Upload", "Paste"],
|
| 298 |
+
horizontal=True,
|
| 299 |
+
key="resume_source"
|
| 300 |
+
)
|
| 301 |
+
if resume_source == "Upload":
|
| 302 |
+
resume_file = st.file_uploader(
|
| 303 |
+
"Upload Resume (PDF/DOCX)",
|
| 304 |
+
type=["pdf", "docx"],
|
| 305 |
+
key="resume_upload"
|
| 306 |
+
)
|
| 307 |
+
resume_text = ""
|
| 308 |
+
else:
|
| 309 |
+
resume_text = st.text_area(
|
| 310 |
+
"Paste Resume",
|
| 311 |
+
height=300,
|
| 312 |
+
placeholder="Paste your full resume text here...",
|
| 313 |
+
key="resume_text"
|
| 314 |
+
)
|
| 315 |
+
resume_file = None
|
| 316 |
+
|
| 317 |
+
if st.button("β¨ Analyze Match", type="primary", use_container_width=True):
|
| 318 |
+
if not (jd_file or jd_text) or not (resume_file or resume_text):
|
| 319 |
+
st.warning("Please provide both Job Description and Resume content")
|
| 320 |
+
st.stop()
|
| 321 |
+
|
| 322 |
+
with st.spinner("π Analyzing documents with DeepSeek..."):
|
| 323 |
+
try:
|
| 324 |
+
# Parallel processing
|
| 325 |
+
with ThreadPoolExecutor() as executor:
|
| 326 |
+
future_jd = executor.submit(
|
| 327 |
+
lambda: extract_text(jd_file) if jd_file else jd_text
|
| 328 |
+
)
|
| 329 |
+
future_resume = executor.submit(
|
| 330 |
+
lambda: extract_text(resume_file) if resume_file else resume_text
|
| 331 |
+
)
|
| 332 |
+
jd_text_clean, resume_text_clean = future_jd.result(), future_resume.result()
|
| 333 |
+
|
| 334 |
+
# Analysis
|
| 335 |
+
with st.status("DeepSeek AI is processing...", expanded=True) as status:
|
| 336 |
+
st.write("Parsing Job Description...")
|
| 337 |
+
jd_data = analyze_with_deepseek(JD_ANALYSIS_PROMPT, jd_text_clean)
|
| 338 |
+
|
| 339 |
+
st.write("Analyzing Resume...")
|
| 340 |
+
resume_data = analyze_with_deepseek(RESUME_ANALYSIS_PROMPT, resume_text_clean)
|
| 341 |
+
|
| 342 |
+
st.write("Calculating Match...")
|
| 343 |
+
results = calculate_match(jd_data, resume_data)
|
| 344 |
+
status.update(label="Analysis Complete!", state="complete")
|
| 345 |
|
| 346 |
+
# Display Results
|
| 347 |
+
st.subheader(f"Overall Match Score: {results['match_score']}%")
|
| 348 |
+
st.progress(results['match_score'] / 100)
|
| 349 |
|
| 350 |
+
# Metrics
|
| 351 |
+
col1, col2, col3 = st.columns(3)
|
| 352 |
+
col1.metric(
|
| 353 |
+
"Skill Coverage",
|
| 354 |
+
results["skill_coverage"],
|
| 355 |
+
help="Percentage of required skills matched"
|
| 356 |
+
)
|
| 357 |
+
col2.metric(
|
| 358 |
+
"Experience Adequacy",
|
| 359 |
+
results["experience_adequacy"],
|
| 360 |
+
help="Years of experience vs requirement"
|
| 361 |
+
)
|
| 362 |
+
col3.metric(
|
| 363 |
+
"Certification Match",
|
| 364 |
+
f"{len(set(jd_data.get('certifications', [])) & set(resume_data.get('certifications', []))}/{len(jd_data.get('certifications', [])) or 'N/A'}",
|
| 365 |
+
help="Matching certifications"
|
| 366 |
+
)
|
| 367 |
|
| 368 |
+
# Improvement Recommendations
|
| 369 |
+
with st.expander("π Detailed Skill Matching", expanded=True):
|
| 370 |
+
if results["matched_skills"]:
|
| 371 |
+
st.write("**Strong Matches:**")
|
| 372 |
+
for jd_skill, match in list(results["matched_skills"].items())[:10]:
|
| 373 |
+
st.write(f"- β
{jd_skill} β {match['resume_skill']} (similarity: {match['similarity']:.2f})")
|
| 374 |
+
|
| 375 |
+
if results["missing_skills"]:
|
| 376 |
+
st.write("**Skills to Add:**")
|
| 377 |
+
for item in results["missing_skills"]:
|
| 378 |
+
if item["similar_in_resume"]:
|
| 379 |
+
st.write(f"- β οΈ {item['required']} (You have similar: {', '.join(item['similar_in_resume'])})")
|
| 380 |
+
else:
|
| 381 |
+
st.write(f"- β {item['required']}")
|
| 382 |
|
| 383 |
+
# AI Suggestions
|
| 384 |
+
if analysis_mode == "Advanced" and results["match_score"] < 80:
|
| 385 |
+
with st.expander("π€ AI Improvement Suggestions", expanded=True):
|
| 386 |
+
llm = init_deepseek_llm()
|
| 387 |
+
prompt = f"""Suggest specific improvements for this resume to better match the job:
|
| 388 |
+
Job Requirements: {jd_data['required_skills'][:5]}
|
| 389 |
+
Resume Gaps: {[m['required'] for m in results['missing_skills']][:5]}
|
| 390 |
+
Provide 3-5 concrete suggestions in bullet points:"""
|
| 391 |
+
suggestions = llm(prompt)
|
| 392 |
+
st.write(suggestions)
|
| 393 |
|
| 394 |
+
# Raw Data
|
| 395 |
+
with st.expander("π View Analysis Data"):
|
| 396 |
+
tab_jd, tab_resume = st.tabs(["Job Analysis", "Resume Analysis"])
|
| 397 |
+
with tab_jd:
|
| 398 |
+
st.json(jd_data)
|
| 399 |
+
with tab_resume:
|
| 400 |
+
st.json(resume_data)
|
|
|
|
|
|
|
| 401 |
|
| 402 |
+
except Exception as e:
|
| 403 |
+
st.error(f"Analysis failed: {str(e)}")
|
| 404 |
+
st.exception(e)
|
|
|
|
|
|
|
| 405 |
|
| 406 |
+
with tab2:
|
| 407 |
+
st.markdown("""
|
| 408 |
+
## How This Analyzer Works
|
| 409 |
+
|
| 410 |
+
**1. Document Processing**
|
| 411 |
+
- Extracts and cleans text from PDF/DOCX files
|
| 412 |
+
- Handles complex layouts and normalizes formatting
|
| 413 |
+
|
| 414 |
+
**2. DeepSeek AI Analysis**
|
| 415 |
+
- Uses `deepseek-llm-67b` model for:
|
| 416 |
+
- Job requirement extraction
|
| 417 |
+
- Resume parsing
|
| 418 |
+
- Identifies key patterns and quantifiable data
|
| 419 |
+
|
| 420 |
+
**3. Advanced Matching**
|
| 421 |
+
- Semantic similarity for skill matching
|
| 422 |
+
- Experience weighting by role relevance
|
| 423 |
+
- Certification verification
|
| 424 |
+
|
| 425 |
+
**4. Results Presentation**
|
| 426 |
+
- Clear visual indicators
|
| 427 |
+
- Actionable improvement suggestions
|
| 428 |
+
- Transparent scoring breakdown
|
| 429 |
+
""")
|
| 430 |
|
| 431 |
if __name__ == "__main__":
|
| 432 |
+
main()
|