Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,10 @@ import torch
|
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
from model import JobRecommendationSystem
|
| 7 |
|
| 8 |
-
# -----------------
|
|
|
|
| 9 |
|
|
|
|
| 10 |
@st.cache_resource
|
| 11 |
def load_model():
|
| 12 |
"""Load and quantize the SentenceTransformer model once"""
|
|
@@ -18,16 +20,13 @@ def load_model():
|
|
| 18 |
|
| 19 |
@st.cache_resource
|
| 20 |
def load_recommender():
|
| 21 |
-
"""Load recommender system once with cached embeddings
|
| 22 |
return JobRecommendationSystem("JobsFE.csv")
|
| 23 |
|
| 24 |
MODEL = load_model()
|
| 25 |
recommender = load_recommender()
|
| 26 |
|
| 27 |
-
# ----------------- STREAMLIT
|
| 28 |
-
|
| 29 |
-
st.set_page_config(page_title="AI Job Recommender", page_icon="πΌ", layout="wide")
|
| 30 |
-
|
| 31 |
st.markdown(
|
| 32 |
"""
|
| 33 |
<style>
|
|
@@ -59,12 +58,9 @@ st.markdown(
|
|
| 59 |
)
|
| 60 |
|
| 61 |
st.title("πΌ AI-Powered Job Recommendation System")
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
"π Upload your resume as a **PDF file** and get tailored job recommendations with direct apply links."
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
# File uploader for PDF resume
|
| 68 |
uploaded_file = st.file_uploader("Upload your resume (PDF only)", type=["pdf"], help="Only PDF resumes are supported.")
|
| 69 |
|
| 70 |
def extract_text_from_pdf(pdf_file):
|
|
@@ -74,11 +70,11 @@ def extract_text_from_pdf(pdf_file):
|
|
| 74 |
return text.strip()
|
| 75 |
|
| 76 |
resume_text = ""
|
| 77 |
-
|
| 78 |
if uploaded_file:
|
| 79 |
with st.spinner("β³ Extracting text from your resume..."):
|
| 80 |
resume_text = extract_text_from_pdf(uploaded_file)
|
| 81 |
|
|
|
|
| 82 |
if st.button("π Recommend Jobs"):
|
| 83 |
if resume_text:
|
| 84 |
with st.spinner("π€ Analyzing your resume and finding best matches..."):
|
|
@@ -86,53 +82,42 @@ if st.button("π Recommend Jobs"):
|
|
| 86 |
|
| 87 |
st.success(f"β
Found {len(job_results)} job recommendations for you!")
|
| 88 |
|
| 89 |
-
# Display recommended jobs
|
| 90 |
for i, job in enumerate(job_results, start=1):
|
| 91 |
with st.container():
|
| 92 |
st.markdown('<div class="recommend-card">', unsafe_allow_html=True)
|
| 93 |
|
| 94 |
-
# Title + Company
|
| 95 |
st.markdown(f"<div class='job-title'> {i}. {job.get('position', 'N/A')} </div>", unsafe_allow_html=True)
|
| 96 |
st.markdown(
|
| 97 |
f"<div class='company-name'>π’ {job.get('workplace', 'N/A')} ({job.get('formatted_work_type', 'N/A')})</div>",
|
| 98 |
unsafe_allow_html=True,
|
| 99 |
)
|
| 100 |
|
| 101 |
-
# Salary Range
|
| 102 |
if job.get("salary_range") and "N/A" not in job.get("salary_range"):
|
| 103 |
st.markdown(f"<div class='salary'>π° {job['salary_range']}</div>", unsafe_allow_html=True)
|
| 104 |
|
| 105 |
-
# Experience
|
| 106 |
if job.get("experience_level") and job.get("experience_level") != "N/A":
|
| 107 |
st.write(f"**π― Experience Level:** {job['experience_level']}")
|
| 108 |
|
| 109 |
-
# Duties
|
| 110 |
if job.get("job_role_and_duties"):
|
| 111 |
st.write(f"**π Duties:** {job['job_role_and_duties']}")
|
| 112 |
|
| 113 |
-
# Skills
|
| 114 |
if job.get("skills"):
|
| 115 |
st.write(f"**π Required Skills:** {job['skills']}")
|
| 116 |
|
| 117 |
-
# Benefits
|
| 118 |
if job.get("benefits"):
|
| 119 |
st.write(f"**π Benefits:** {job['benefits']}")
|
| 120 |
|
| 121 |
-
# Location
|
| 122 |
if job.get("location") and job.get("location").strip(", "):
|
| 123 |
st.write(f"**π Location:** {job['location']}")
|
| 124 |
|
| 125 |
-
# Company size & employees
|
| 126 |
if job.get("company_size") and job.get("company_size") != "N/A":
|
| 127 |
st.write(f"**π’ Company Size:** {job['company_size']}")
|
| 128 |
if job.get("employee_count") and job.get("employee_count") != "N/A":
|
| 129 |
st.write(f"**π₯ Employees:** {job['employee_count']}")
|
| 130 |
|
| 131 |
-
# Company website
|
| 132 |
if job.get("company_website") and job.get("company_website") != "N/A":
|
| 133 |
st.markdown(f"[π Company Website]({job['company_website']})", unsafe_allow_html=True)
|
| 134 |
|
| 135 |
-
# Apply Links
|
| 136 |
if job.get("apply_link") and job.get("apply_link") != "N/A":
|
| 137 |
st.markdown(f"[π Apply Here]({job['apply_link']})", unsafe_allow_html=True)
|
| 138 |
|
|
|
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
from model import JobRecommendationSystem
|
| 7 |
|
| 8 |
+
# ----------------- PAGE CONFIG (must be FIRST) -----------------
|
| 9 |
+
st.set_page_config(page_title="AI Job Recommender", page_icon="πΌ", layout="wide")
|
| 10 |
|
| 11 |
+
# ----------------- CACHE HEAVY STUFF -----------------
|
| 12 |
@st.cache_resource
|
| 13 |
def load_model():
|
| 14 |
"""Load and quantize the SentenceTransformer model once"""
|
|
|
|
| 20 |
|
| 21 |
@st.cache_resource
|
| 22 |
def load_recommender():
|
| 23 |
+
"""Load recommender system once with cached embeddings"""
|
| 24 |
return JobRecommendationSystem("JobsFE.csv")
|
| 25 |
|
| 26 |
MODEL = load_model()
|
| 27 |
recommender = load_recommender()
|
| 28 |
|
| 29 |
+
# ----------------- STREAMLIT UI -----------------
|
|
|
|
|
|
|
|
|
|
| 30 |
st.markdown(
|
| 31 |
"""
|
| 32 |
<style>
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
st.title("πΌ AI-Powered Job Recommendation System")
|
| 61 |
+
st.write("π Upload your resume as a **PDF file** and get tailored job recommendations with direct apply links.")
|
| 62 |
|
| 63 |
+
# ----------------- FILE UPLOADER -----------------
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
uploaded_file = st.file_uploader("Upload your resume (PDF only)", type=["pdf"], help="Only PDF resumes are supported.")
|
| 65 |
|
| 66 |
def extract_text_from_pdf(pdf_file):
|
|
|
|
| 70 |
return text.strip()
|
| 71 |
|
| 72 |
resume_text = ""
|
|
|
|
| 73 |
if uploaded_file:
|
| 74 |
with st.spinner("β³ Extracting text from your resume..."):
|
| 75 |
resume_text = extract_text_from_pdf(uploaded_file)
|
| 76 |
|
| 77 |
+
# ----------------- JOB RECOMMENDATIONS -----------------
|
| 78 |
if st.button("π Recommend Jobs"):
|
| 79 |
if resume_text:
|
| 80 |
with st.spinner("π€ Analyzing your resume and finding best matches..."):
|
|
|
|
| 82 |
|
| 83 |
st.success(f"β
Found {len(job_results)} job recommendations for you!")
|
| 84 |
|
|
|
|
| 85 |
for i, job in enumerate(job_results, start=1):
|
| 86 |
with st.container():
|
| 87 |
st.markdown('<div class="recommend-card">', unsafe_allow_html=True)
|
| 88 |
|
|
|
|
| 89 |
st.markdown(f"<div class='job-title'> {i}. {job.get('position', 'N/A')} </div>", unsafe_allow_html=True)
|
| 90 |
st.markdown(
|
| 91 |
f"<div class='company-name'>π’ {job.get('workplace', 'N/A')} ({job.get('formatted_work_type', 'N/A')})</div>",
|
| 92 |
unsafe_allow_html=True,
|
| 93 |
)
|
| 94 |
|
|
|
|
| 95 |
if job.get("salary_range") and "N/A" not in job.get("salary_range"):
|
| 96 |
st.markdown(f"<div class='salary'>π° {job['salary_range']}</div>", unsafe_allow_html=True)
|
| 97 |
|
|
|
|
| 98 |
if job.get("experience_level") and job.get("experience_level") != "N/A":
|
| 99 |
st.write(f"**π― Experience Level:** {job['experience_level']}")
|
| 100 |
|
|
|
|
| 101 |
if job.get("job_role_and_duties"):
|
| 102 |
st.write(f"**π Duties:** {job['job_role_and_duties']}")
|
| 103 |
|
|
|
|
| 104 |
if job.get("skills"):
|
| 105 |
st.write(f"**π Required Skills:** {job['skills']}")
|
| 106 |
|
|
|
|
| 107 |
if job.get("benefits"):
|
| 108 |
st.write(f"**π Benefits:** {job['benefits']}")
|
| 109 |
|
|
|
|
| 110 |
if job.get("location") and job.get("location").strip(", "):
|
| 111 |
st.write(f"**π Location:** {job['location']}")
|
| 112 |
|
|
|
|
| 113 |
if job.get("company_size") and job.get("company_size") != "N/A":
|
| 114 |
st.write(f"**π’ Company Size:** {job['company_size']}")
|
| 115 |
if job.get("employee_count") and job.get("employee_count") != "N/A":
|
| 116 |
st.write(f"**π₯ Employees:** {job['employee_count']}")
|
| 117 |
|
|
|
|
| 118 |
if job.get("company_website") and job.get("company_website") != "N/A":
|
| 119 |
st.markdown(f"[π Company Website]({job['company_website']})", unsafe_allow_html=True)
|
| 120 |
|
|
|
|
| 121 |
if job.get("apply_link") and job.get("apply_link") != "N/A":
|
| 122 |
st.markdown(f"[π Apply Here]({job['apply_link']})", unsafe_allow_html=True)
|
| 123 |
|