Update app.py
Browse files
app.py
CHANGED
|
@@ -126,6 +126,12 @@ st.markdown("""
|
|
| 126 |
[data-testid="stSidebar"] [data-testid="stExpander"] {
|
| 127 |
color: var(--secondary-text-color) !important;
|
| 128 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
/* Scorecard Style (Tiles) */
|
| 131 |
.scorecard-block {
|
|
@@ -183,7 +189,7 @@ skills_list = [
|
|
| 183 |
|
| 184 |
skills_pattern = re.compile(r'\b(' + '|'.join(re.escape(skill) for skill in skills_list) + r')\b', re.IGNORECASE)
|
| 185 |
|
| 186 |
-
# Helper functions for CV parsing
|
| 187 |
def extract_text_from_pdf(file):
|
| 188 |
try:
|
| 189 |
pdf_reader = PyPDF2.PdfReader(file)
|
|
@@ -279,7 +285,7 @@ def extract_skills(text):
|
|
| 279 |
|
| 280 |
@st.cache_data
|
| 281 |
def classify_and_summarize_batch(resume, job_description, _bert_tokenized, _t5_input, _t5_tokenized, _job_skills_set):
|
| 282 |
-
# Classification and Summary logic (
|
| 283 |
_, bert_model, t5_tokenizer, t5_model, device = st.session_state.models
|
| 284 |
timeout = 60
|
| 285 |
|
|
@@ -343,13 +349,14 @@ def classify_and_summarize_batch(resume, job_description, _bert_tokenized, _t5_i
|
|
| 343 |
elif suitability == "Irrelevant": color = "#F44336"
|
| 344 |
else: color = "#FFC107"
|
| 345 |
|
| 346 |
-
|
|
|
|
| 347 |
except Exception as e:
|
| 348 |
-
return {"Suitability": "Error", "Data/Tech Related Skills Summary": "Failed to process profile", "Warning": str(e), "
|
| 349 |
|
| 350 |
@st.cache_data
|
| 351 |
def generate_skill_pie_chart(resumes):
|
| 352 |
-
# Skill chart logic (
|
| 353 |
skill_counts = {}
|
| 354 |
total_resumes = len([r for r in resumes if r.strip()])
|
| 355 |
if total_resumes == 0: return None
|
|
@@ -372,7 +379,8 @@ def generate_skill_pie_chart(resumes):
|
|
| 372 |
|
| 373 |
# Use dark theme settings for the chart
|
| 374 |
plt.style.use('dark_background')
|
| 375 |
-
|
|
|
|
| 376 |
colors = plt.cm.plasma(np.linspace(0.2, 0.9, len(labels)))
|
| 377 |
plt.rcParams['text.color'] = '#F8F8F8'
|
| 378 |
wedges, texts, autotexts = ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, colors=colors, textprops={'fontsize': 10, 'color': '#F8F8F8'})
|
|
@@ -645,27 +653,29 @@ def main():
|
|
| 645 |
st.markdown("### 📋 Detailed Screening Results")
|
| 646 |
|
| 647 |
# RANK 1: Color-Coded Table Rows using Pandas Styler
|
|
|
|
| 648 |
def style_suitability_row(row):
|
| 649 |
# Using light background color for dark theme
|
| 650 |
-
if row['
|
| 651 |
return ['background-color: rgba(76, 175, 80, 0.15)'] * len(row)
|
| 652 |
-
elif row['
|
| 653 |
return ['background-color: rgba(244, 67, 54, 0.15)'] * len(row)
|
| 654 |
-
elif row['
|
| 655 |
return ['background-color: rgba(255, 193, 7, 0.15)'] * len(row)
|
| 656 |
else:
|
| 657 |
return [''] * len(row)
|
| 658 |
|
| 659 |
# Apply styling and rename columns
|
| 660 |
-
|
|
|
|
| 661 |
|
| 662 |
# Apply row styling (using the column that holds the hex color)
|
| 663 |
styled_df = display_df.style.apply(style_suitability_row, axis=1)
|
| 664 |
|
| 665 |
-
# Remove the now-
|
| 666 |
-
styled_df = styled_df.hide(subset=['
|
| 667 |
|
| 668 |
-
# Display the styled DataFrame.
|
| 669 |
st.dataframe(
|
| 670 |
styled_df,
|
| 671 |
use_container_width=True
|
|
@@ -677,7 +687,8 @@ def main():
|
|
| 677 |
|
| 678 |
with col_dl:
|
| 679 |
csv_buffer = io.StringIO()
|
| 680 |
-
|
|
|
|
| 681 |
|
| 682 |
st.download_button(
|
| 683 |
"💾 Download Full Report (CSV)",
|
|
@@ -692,7 +703,8 @@ def main():
|
|
| 692 |
if st.session_state.valid_resumes:
|
| 693 |
fig = generate_skill_pie_chart(st.session_state.valid_resumes)
|
| 694 |
if fig:
|
| 695 |
-
|
|
|
|
| 696 |
plt.close(fig)
|
| 697 |
else:
|
| 698 |
st.info("No recognized technical skills found in the profiles for charting.")
|
|
|
|
| 126 |
[data-testid="stSidebar"] [data-testid="stExpander"] {
|
| 127 |
color: var(--secondary-text-color) !important;
|
| 128 |
}
|
| 129 |
+
|
| 130 |
+
/* Fix: Condense paragraph spacing in Quick Guide (Sidebar) */
|
| 131 |
+
.stSidebar .stExpanderContent p {
|
| 132 |
+
margin-block-start: 0.5em !important;
|
| 133 |
+
margin-block-end: 0.5em !important;
|
| 134 |
+
}
|
| 135 |
|
| 136 |
/* Scorecard Style (Tiles) */
|
| 137 |
.scorecard-block {
|
|
|
|
| 189 |
|
| 190 |
skills_pattern = re.compile(r'\b(' + '|'.join(re.escape(skill) for skill in skills_list) + r')\b', re.IGNORECASE)
|
| 191 |
|
| 192 |
+
# Helper functions for CV parsing (UNCHANGED)
|
| 193 |
def extract_text_from_pdf(file):
|
| 194 |
try:
|
| 195 |
pdf_reader = PyPDF2.PdfReader(file)
|
|
|
|
| 285 |
|
| 286 |
@st.cache_data
|
| 287 |
def classify_and_summarize_batch(resume, job_description, _bert_tokenized, _t5_input, _t5_tokenized, _job_skills_set):
|
| 288 |
+
# Classification and Summary logic (UNCHANGED CORE LOGIC)
|
| 289 |
_, bert_model, t5_tokenizer, t5_model, device = st.session_state.models
|
| 290 |
timeout = 60
|
| 291 |
|
|
|
|
| 349 |
elif suitability == "Irrelevant": color = "#F44336"
|
| 350 |
else: color = "#FFC107"
|
| 351 |
|
| 352 |
+
# *** CHANGE 3: Renamed Suitability_Color to __style_color for clarity ***
|
| 353 |
+
return {"Suitability": suitability, "Data/Tech Related Skills Summary": final_summary, "Warning": warning or "None", "__style_color": color}
|
| 354 |
except Exception as e:
|
| 355 |
+
return {"Suitability": "Error", "Data/Tech Related Skills Summary": "Failed to process profile", "Warning": str(e), "__style_color": "#F44336"}
|
| 356 |
|
| 357 |
@st.cache_data
|
| 358 |
def generate_skill_pie_chart(resumes):
|
| 359 |
+
# Skill chart logic (UNCHANGED)
|
| 360 |
skill_counts = {}
|
| 361 |
total_resumes = len([r for r in resumes if r.strip()])
|
| 362 |
if total_resumes == 0: return None
|
|
|
|
| 379 |
|
| 380 |
# Use dark theme settings for the chart
|
| 381 |
plt.style.use('dark_background')
|
| 382 |
+
# *** CHANGE 1: Removed figsize to let Streamlit manage size and prevent flicker ***
|
| 383 |
+
fig, ax = plt.subplots()
|
| 384 |
colors = plt.cm.plasma(np.linspace(0.2, 0.9, len(labels)))
|
| 385 |
plt.rcParams['text.color'] = '#F8F8F8'
|
| 386 |
wedges, texts, autotexts = ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, colors=colors, textprops={'fontsize': 10, 'color': '#F8F8F8'})
|
|
|
|
| 653 |
st.markdown("### 📋 Detailed Screening Results")
|
| 654 |
|
| 655 |
# RANK 1: Color-Coded Table Rows using Pandas Styler
|
| 656 |
+
# *** CHANGE 3: The styling function now targets the internal __style_color column ***
|
| 657 |
def style_suitability_row(row):
|
| 658 |
# Using light background color for dark theme
|
| 659 |
+
if row['__style_color'] == '#4CAF50': # Relevant - Green
|
| 660 |
return ['background-color: rgba(76, 175, 80, 0.15)'] * len(row)
|
| 661 |
+
elif row['__style_color'] == '#F44336': # Irrelevant/Error - Red
|
| 662 |
return ['background-color: rgba(244, 67, 54, 0.15)'] * len(row)
|
| 663 |
+
elif row['__style_color'] == '#FFC107': # Uncertain - Yellow
|
| 664 |
return ['background-color: rgba(255, 193, 7, 0.15)'] * len(row)
|
| 665 |
else:
|
| 666 |
return [''] * len(row)
|
| 667 |
|
| 668 |
# Apply styling and rename columns
|
| 669 |
+
# Note: display_df still contains '__style_color' for the styling function to use.
|
| 670 |
+
display_df = results_df.rename(columns={'Data/Tech Related Skills Summary': 'PROFILE SUMMARY', 'Warning': 'FLAGGING REASON', 'Resume': 'PROFILE ID', '__style_color': '__STYLE_COLOR_INTERNAL'})
|
| 671 |
|
| 672 |
# Apply row styling (using the column that holds the hex color)
|
| 673 |
styled_df = display_df.style.apply(style_suitability_row, axis=1)
|
| 674 |
|
| 675 |
+
# Remove the now-internal-only color column from display
|
| 676 |
+
styled_df = styled_df.hide(subset=['__STYLE_COLOR_INTERNAL'], axis=1)
|
| 677 |
|
| 678 |
+
# Display the styled DataFrame.
|
| 679 |
st.dataframe(
|
| 680 |
styled_df,
|
| 681 |
use_container_width=True
|
|
|
|
| 687 |
|
| 688 |
with col_dl:
|
| 689 |
csv_buffer = io.StringIO()
|
| 690 |
+
# *** CHANGE 3: Drop the internal column before download ***
|
| 691 |
+
results_df.drop(columns=['__style_color']).to_csv(csv_buffer, index=False)
|
| 692 |
|
| 693 |
st.download_button(
|
| 694 |
"💾 Download Full Report (CSV)",
|
|
|
|
| 703 |
if st.session_state.valid_resumes:
|
| 704 |
fig = generate_skill_pie_chart(st.session_state.valid_resumes)
|
| 705 |
if fig:
|
| 706 |
+
# *** CHANGE 1: Added use_container_width for stability ***
|
| 707 |
+
st.pyplot(fig, use_container_width=True)
|
| 708 |
plt.close(fig)
|
| 709 |
else:
|
| 710 |
st.info("No recognized technical skills found in the profiles for charting.")
|