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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
+
import re
|
| 7 |
+
import nltk
|
| 8 |
+
from nltk.corpus import stopwords
|
| 9 |
+
from nltk.tokenize import word_tokenize
|
| 10 |
+
import string
|
| 11 |
+
import json
|
| 12 |
+
import os
|
| 13 |
+
from utils import load_job_data, preprocess_text, get_top_skills, get_job_recommendations
|
| 14 |
+
|
| 15 |
+
# Download NLTK resources
|
| 16 |
+
nltk.download('punkt')
|
| 17 |
+
nltk.download('stopwords')
|
| 18 |
+
|
| 19 |
+
# Page configuration
|
| 20 |
+
st.set_page_config(
|
| 21 |
+
page_title="Job Title Recommender",
|
| 22 |
+
page_icon="💼",
|
| 23 |
+
layout="wide"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Custom CSS
|
| 27 |
+
st.markdown("""
|
| 28 |
+
<style>
|
| 29 |
+
.main-header {
|
| 30 |
+
font-size: 2.5rem;
|
| 31 |
+
font-weight: bold;
|
| 32 |
+
color: #0A66C2;
|
| 33 |
+
text-align: center;
|
| 34 |
+
margin-bottom: 1rem;
|
| 35 |
+
}
|
| 36 |
+
.sub-header {
|
| 37 |
+
font-size: 1.2rem;
|
| 38 |
+
color: #666;
|
| 39 |
+
text-align: center;
|
| 40 |
+
margin-bottom: 2rem;
|
| 41 |
+
}
|
| 42 |
+
.footer {
|
| 43 |
+
text-align: center;
|
| 44 |
+
margin-top: 2rem;
|
| 45 |
+
color: #666;
|
| 46 |
+
font-size: 0.9rem;
|
| 47 |
+
}
|
| 48 |
+
.recommendation-card {
|
| 49 |
+
border: 1px solid #ddd;
|
| 50 |
+
border-radius: 8px;
|
| 51 |
+
padding: 1rem;
|
| 52 |
+
margin-bottom: 1rem;
|
| 53 |
+
background-color: #f9f9f9;
|
| 54 |
+
}
|
| 55 |
+
.skill-tag {
|
| 56 |
+
display: inline-block;
|
| 57 |
+
background-color: #0A66C2;
|
| 58 |
+
color: white;
|
| 59 |
+
padding: 0.3rem 0.8rem;
|
| 60 |
+
border-radius: 15px;
|
| 61 |
+
margin: 0.2rem;
|
| 62 |
+
font-size: 0.9rem;
|
| 63 |
+
}
|
| 64 |
+
</style>
|
| 65 |
+
""", unsafe_allow_html=True)
|
| 66 |
+
|
| 67 |
+
# Initialize session state
|
| 68 |
+
if 'job_data' not in st.session_state:
|
| 69 |
+
st.session_state.job_data = load_job_data()
|
| 70 |
+
if 'vectorizer' not in st.session_state:
|
| 71 |
+
st.session_state.vectorizer = None
|
| 72 |
+
if 'job_vectors' not in st.session_state:
|
| 73 |
+
st.session_state.job_vectors = None
|
| 74 |
+
|
| 75 |
+
# Header
|
| 76 |
+
st.markdown('<div class="main-header">💼 Job Title Recommender</div>', unsafe_allow_html=True)
|
| 77 |
+
st.markdown('<div class="sub-header">Find the perfect job titles based on your LinkedIn profile or resume</div>', unsafe_allow_html=True)
|
| 78 |
+
|
| 79 |
+
# Built with anycoder
|
| 80 |
+
st.markdown('<div style="text-align: center; margin-bottom: 1rem;">Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a></div>', unsafe_allow_html=True)
|
| 81 |
+
|
| 82 |
+
# Main content
|
| 83 |
+
col1, col2 = st.columns([1, 1])
|
| 84 |
+
|
| 85 |
+
with col1:
|
| 86 |
+
st.header("📝 Input Your Profile")
|
| 87 |
+
|
| 88 |
+
# Input method selection
|
| 89 |
+
input_method = st.radio(
|
| 90 |
+
"Choose input method:",
|
| 91 |
+
["Text Input", "File Upload"],
|
| 92 |
+
horizontal=True
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
if input_method == "Text Input":
|
| 96 |
+
profile_text = st.text_area(
|
| 97 |
+
"Paste your LinkedIn profile or resume text here:",
|
| 98 |
+
height=300,
|
| 99 |
+
placeholder="Include your work experience, skills, education, and any other relevant information..."
|
| 100 |
+
)
|
| 101 |
+
else:
|
| 102 |
+
uploaded_file = st.file_uploader(
|
| 103 |
+
"Upload your resume (PDF or TXT):",
|
| 104 |
+
type=["pdf", "txt"],
|
| 105 |
+
help="Upload your resume file to analyze"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
if uploaded_file:
|
| 109 |
+
try:
|
| 110 |
+
if uploaded_file.type == "application/pdf":
|
| 111 |
+
# For PDF files (would need additional libraries)
|
| 112 |
+
st.warning("PDF parsing requires additional libraries. Please use text input or upload a .txt file.")
|
| 113 |
+
profile_text = ""
|
| 114 |
+
else:
|
| 115 |
+
# For text files
|
| 116 |
+
profile_text = uploaded_file.read().decode("utf-8")
|
| 117 |
+
st.success("File uploaded successfully!")
|
| 118 |
+
except Exception as e:
|
| 119 |
+
st.error(f"Error reading file: {e}")
|
| 120 |
+
profile_text = ""
|
| 121 |
+
|
| 122 |
+
# Skills input
|
| 123 |
+
st.subheader("Key Skills")
|
| 124 |
+
skills_input = st.text_input(
|
| 125 |
+
"Enter your key skills (comma separated):",
|
| 126 |
+
placeholder="e.g., Python, Machine Learning, Project Management"
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
# Experience level
|
| 130 |
+
experience_level = st.select_slider(
|
| 131 |
+
"Years of Experience:",
|
| 132 |
+
options=["0-2 years", "3-5 years", "6-10 years", "10+ years"],
|
| 133 |
+
value="3-5 years"
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
# Education level
|
| 137 |
+
education_level = st.selectbox(
|
| 138 |
+
"Highest Education Level:",
|
| 139 |
+
["High School", "Associate Degree", "Bachelor's Degree", "Master's Degree", "PhD"]
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# Analyze button
|
| 143 |
+
analyze_button = st.button("🔍 Analyze & Get Recommendations", type="primary")
|
| 144 |
+
|
| 145 |
+
with col2:
|
| 146 |
+
st.header("🎯 Your Recommendations")
|
| 147 |
+
|
| 148 |
+
if analyze_button and profile_text:
|
| 149 |
+
with st.spinner("Analyzing your profile..."):
|
| 150 |
+
try:
|
| 151 |
+
# Preprocess the input text
|
| 152 |
+
processed_text = preprocess_text(profile_text)
|
| 153 |
+
|
| 154 |
+
# Extract skills from input
|
| 155 |
+
input_skills = [skill.strip() for skill in skills_input.split(",")] if skills_input else []
|
| 156 |
+
extracted_skills = get_top_skills(processed_text, top_n=10)
|
| 157 |
+
|
| 158 |
+
# Combine all skills
|
| 159 |
+
all_skills = list(set(input_skills + extracted_skills))
|
| 160 |
+
|
| 161 |
+
# Create user profile vector
|
| 162 |
+
if st.session_state.vectorizer is None or st.session_state.job_vectors is None:
|
| 163 |
+
# Initialize vectorizer and job vectors if not already done
|
| 164 |
+
job_descriptions = st.session_state.job_data['description'].tolist()
|
| 165 |
+
st.session_state.vectorizer = TfidfVectorizer(stop_words='english', max_features=5000)
|
| 166 |
+
st.session_state.job_vectors = st.session_state.vectorizer.fit_transform(job_descriptions)
|
| 167 |
+
|
| 168 |
+
# Transform user profile
|
| 169 |
+
user_vector = st.session_state.vectorizer.transform([processed_text])
|
| 170 |
+
|
| 171 |
+
# Get recommendations
|
| 172 |
+
recommendations = get_job_recommendations(
|
| 173 |
+
user_vector,
|
| 174 |
+
st.session_state.job_vectors,
|
| 175 |
+
st.session_state.job_data,
|
| 176 |
+
all_skills,
|
| 177 |
+
experience_level,
|
| 178 |
+
education_level,
|
| 179 |
+
top_n=5
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
if recommendations.empty:
|
| 183 |
+
st.warning("No suitable job titles found. Try adding more details to your profile.")
|
| 184 |
+
else:
|
| 185 |
+
st.success(f"Found {len(recommendations)} suitable job titles for you!")
|
| 186 |
+
|
| 187 |
+
for idx, row in recommendations.iterrows():
|
| 188 |
+
with st.expander(f"🏆 {row['job_title']} (Match: {row['match_score']:.1%})"):
|
| 189 |
+
st.markdown(f"**Industry:** {row['industry']}")
|
| 190 |
+
st.markdown(f"**Experience Level:** {row['experience_level']}")
|
| 191 |
+
st.markdown(f"**Education Requirement:** {row['education_requirement']}")
|
| 192 |
+
|
| 193 |
+
# Display skills
|
| 194 |
+
st.markdown("**Key Skills:**")
|
| 195 |
+
job_skills = [skill.strip() for skill in row['required_skills'].split(",")]
|
| 196 |
+
for skill in job_skills[:5]: # Show top 5 skills
|
| 197 |
+
st.markdown(f'<span class="skill-tag">{skill}</span>', unsafe_allow_html=True)
|
| 198 |
+
|
| 199 |
+
st.markdown(f"**Average Salary:** {row['avg_salary']}")
|
| 200 |
+
|
| 201 |
+
if st.button(f"Learn more about {row['job_title']}", key=f"learn_{idx}"):
|
| 202 |
+
st.info(f"This would typically link to more information about the {row['job_title']} role.")
|
| 203 |
+
|
| 204 |
+
# Show skills analysis
|
| 205 |
+
st.subheader("Your Skills Analysis")
|
| 206 |
+
if all_skills:
|
| 207 |
+
st.markdown("**Detected Skills:**")
|
| 208 |
+
for skill in all_skills[:10]: # Show top 10 skills
|
| 209 |
+
st.markdown(f'<span class="skill-tag">{skill}</span>', unsafe_allow_html=True)
|
| 210 |
+
else:
|
| 211 |
+
st.info("No specific skills detected. Consider adding more details to your profile.")
|
| 212 |
+
|
| 213 |
+
except Exception as e:
|
| 214 |
+
st.error(f"An error occurred during analysis: {e}")
|
| 215 |
+
elif analyze_button and not profile_text:
|
| 216 |
+
st.warning("Please enter your profile information or upload a file.")
|
| 217 |
+
else:
|
| 218 |
+
st.info("Enter your LinkedIn profile or resume information and click 'Analyze' to get job recommendations.")
|
| 219 |
+
|
| 220 |
+
# Footer
|
| 221 |
+
st.markdown("""
|
| 222 |
+
<div class="footer">
|
| 223 |
+
<p>This tool uses natural language processing to match your skills and experience with suitable job titles.</p>
|
| 224 |
+
<p>For best results, provide detailed information about your work experience, skills, and education.</p>
|
| 225 |
+
</div>
|
| 226 |
+
""", unsafe_allow_html=True)
|