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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import plotly.graph_objects as go
|
| 5 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 6 |
+
from sklearn.cluster import KMeans
|
| 7 |
+
from sklearn.preprocessing import normalize
|
| 8 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 9 |
+
from sklearn.decomposition import PCA
|
| 10 |
+
import ast, io
|
| 11 |
+
from collections import Counter
|
| 12 |
|
| 13 |
+
# ββ Colors ββββββββββββββββββββββββββββββββββββββββ
|
| 14 |
+
COLORS5 = ["#6c63ff","#22d3ee","#f472b6","#fbbf24","#4ade80"]
|
| 15 |
+
COLORS5_RGBA = ["rgba(108,99,255,0.2)","rgba(34,211,238,0.2)",
|
| 16 |
+
"rgba(244,114,182,0.2)","rgba(251,191,36,0.2)","rgba(74,222,128,0.2)"]
|
| 17 |
+
ACCENT = "#6c63ff"
|
| 18 |
+
PLOTLY_THEME = dict(
|
| 19 |
+
paper_bgcolor="rgba(15,15,23,1)",
|
| 20 |
+
plot_bgcolor ="rgba(15,15,23,1)",
|
| 21 |
+
font=dict(family="sans-serif", color="#a8a6a0", size=12),
|
| 22 |
+
xaxis=dict(gridcolor="#1e1e2e", linecolor="#1e1e2e"),
|
| 23 |
+
yaxis=dict(gridcolor="#1e1e2e", linecolor="#1e1e2e"),
|
| 24 |
+
margin=dict(l=20, r=20, t=40, b=20),
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
def GAP_COLS(g):
|
| 28 |
+
if g > 0.89: return "#f87171"
|
| 29 |
+
if g > 0.79: return "#fbbf24"
|
| 30 |
+
return "#4ade80"
|
| 31 |
+
|
| 32 |
+
def severity(g):
|
| 33 |
+
if g > 0.89: return "π΄ CRITICAL"
|
| 34 |
+
if g > 0.79: return "π‘ MODERATE"
|
| 35 |
+
return "π’ LOW"
|
| 36 |
+
|
| 37 |
+
def parse_skills(s):
|
| 38 |
+
try:
|
| 39 |
+
lst = ast.literal_eval(s)
|
| 40 |
+
return [x.strip().lower() for x in lst if x.strip()]
|
| 41 |
+
except:
|
| 42 |
+
return [x.strip().lower() for x in str(s).split(',') if x.strip()]
|
| 43 |
+
|
| 44 |
+
# ββ Demo data βββββββββββββββββββββββββββββββββββββ
|
| 45 |
+
def generate_demo_data():
|
| 46 |
+
rng = np.random.default_rng(42)
|
| 47 |
+
intern_pools = {
|
| 48 |
+
"Data Scientist": ["python","machine learning","statistics","pandas","numpy","data analysis","regression","classification","visualization","jupyter"],
|
| 49 |
+
"Software Engineer": ["python","java","javascript","git","docker","api","algorithms","sql","testing","agile"],
|
| 50 |
+
"Business Analyst": ["excel","powerpoint","project management","communication","stakeholder","reporting","business intelligence","ms office","presentation","analysis"],
|
| 51 |
+
"Finance Analyst": ["excel","financial modeling","accounting","ledger","budget","forecasting","microsoft","audit","tax","compliance"],
|
| 52 |
+
"ML Engineer": ["python","deep learning","tensorflow","pytorch","neural networks","nlp","machine learning","cuda","model deployment","feature engineering"],
|
| 53 |
+
"Web Developer": ["html","css","javascript","react","git","responsive design","nodejs","rest api","typescript","webpack"],
|
| 54 |
+
"Data Analyst": ["sql","tableau","python","excel","data cleaning","visualization","reporting","statistics","powerbi","etl"],
|
| 55 |
+
"DevOps Engineer": ["docker","kubernetes","ci/cd","linux","aws","terraform","monitoring","git","bash","cloud"],
|
| 56 |
+
}
|
| 57 |
+
industry_pools = {
|
| 58 |
+
"Data Engineer": ["sql","python","spark","aws","cloud","etl","data pipeline","airflow","kafka","dbt","azure","databricks"],
|
| 59 |
+
"ML Engineer": ["python","aws","docker","kubernetes","mlflow","deep learning","cloud","machine learning","ci/cd","model serving"],
|
| 60 |
+
"Cloud Architect": ["aws","azure","gcp","cloud","terraform","kubernetes","microservices","networking","security","cost optimization"],
|
| 61 |
+
"Data Scientist": ["python","sql","machine learning","statistics","aws","communication","agile","data visualization","experiment design","causal inference"],
|
| 62 |
+
"Analytics Engineer": ["sql","dbt","python","analytics","data modeling","communication","business intelligence","airflow","testing","documentation"],
|
| 63 |
+
}
|
| 64 |
+
intern_rows, industry_rows = [], []
|
| 65 |
+
for role, skills in intern_pools.items():
|
| 66 |
+
n = rng.integers(80, 300)
|
| 67 |
+
for _ in range(n):
|
| 68 |
+
sample = rng.choice(skills, size=rng.integers(3,7), replace=False).tolist()
|
| 69 |
+
intern_rows.append({"Job_Role": role, "Intern_Skills": str(sample)})
|
| 70 |
+
for role, skills in industry_pools.items():
|
| 71 |
+
n = rng.integers(200, 800)
|
| 72 |
+
for _ in range(n):
|
| 73 |
+
sample = rng.choice(skills, size=rng.integers(4,9), replace=False).tolist()
|
| 74 |
+
industry_rows.append({"job_title": role, "job_skills": ", ".join(sample)})
|
| 75 |
+
return pd.DataFrame(intern_rows), pd.DataFrame(industry_rows)
|
| 76 |
+
|
| 77 |
+
# ββ Core pipeline βββββββββββββββββββββββββββββββββ
|
| 78 |
+
def run_pipeline(intern_df, industry_df, k, top_n, min_df, max_df):
|
| 79 |
+
if 'Intern_Skills' not in intern_df.columns:
|
| 80 |
+
cols = [c for c in intern_df.columns if 'skill' in c.lower()]
|
| 81 |
+
intern_df['Intern_Skills'] = intern_df[cols[0]] if cols else ""
|
| 82 |
+
if 'Job_Role' not in intern_df.columns:
|
| 83 |
+
intern_df['Job_Role'] = intern_df.iloc[:,0]
|
| 84 |
+
if 'job_skills' not in industry_df.columns:
|
| 85 |
+
cols = [c for c in industry_df.columns if 'skill' in c.lower()]
|
| 86 |
+
industry_df['job_skills'] = industry_df[cols[0]] if cols else ""
|
| 87 |
+
if 'job_title' not in industry_df.columns:
|
| 88 |
+
industry_df['job_title'] = industry_df.iloc[:,0]
|
| 89 |
+
|
| 90 |
+
intern_df['skills_list'] = intern_df['Intern_Skills'].apply(parse_skills)
|
| 91 |
+
industry_df['skills_list'] = industry_df['job_skills'].apply(parse_skills)
|
| 92 |
+
intern_df = intern_df[intern_df['skills_list'].map(len) > 0].copy()
|
| 93 |
+
industry_df = industry_df[industry_df['skills_list'].map(len) > 0].copy()
|
| 94 |
+
intern_df['skills_text'] = intern_df['skills_list'].apply(lambda x: ' '.join(x))
|
| 95 |
+
industry_df['skills_text'] = industry_df['skills_list'].apply(lambda x: ' '.join(x))
|
| 96 |
+
|
| 97 |
+
tfidf = TfidfVectorizer(stop_words='english', min_df=min_df, max_df=max_df)
|
| 98 |
+
tfidf.fit(pd.concat([intern_df['skills_text'], industry_df['skills_text']]))
|
| 99 |
+
features = tfidf.get_feature_names_out()
|
| 100 |
+
|
| 101 |
+
iv = normalize(tfidf.transform(intern_df['skills_text']))
|
| 102 |
+
jv = normalize(tfidf.transform(industry_df['skills_text']))
|
| 103 |
+
|
| 104 |
+
kmi = KMeans(n_clusters=k, random_state=42, n_init=10)
|
| 105 |
+
kmj = KMeans(n_clusters=k, random_state=42, n_init=10)
|
| 106 |
+
intern_df['Cluster'] = kmi.fit_predict(iv)
|
| 107 |
+
industry_df['Cluster'] = kmj.fit_predict(jv)
|
| 108 |
+
|
| 109 |
+
industry_mean = np.asarray(jv.mean(axis=0)).flatten()
|
| 110 |
+
sim = cosine_similarity(iv.toarray(), industry_mean.reshape(1,-1)).flatten()
|
| 111 |
+
intern_df['Similarity'] = sim
|
| 112 |
+
intern_df['Gap_Score'] = 1 - sim
|
| 113 |
+
|
| 114 |
+
top_idx = industry_mean.argsort()[::-1][:top_n]
|
| 115 |
+
top_industry_skills = [features[i] for i in top_idx]
|
| 116 |
+
top_industry_set = set(top_industry_skills)
|
| 117 |
+
|
| 118 |
+
profiles = {}
|
| 119 |
+
for cid in range(k):
|
| 120 |
+
center = kmi.cluster_centers_[cid]
|
| 121 |
+
top_intern = [features[i] for i in center.argsort()[::-1][:top_n]]
|
| 122 |
+
cdf = intern_df[intern_df['Cluster']==cid]
|
| 123 |
+
profiles[cid] = {
|
| 124 |
+
'label': top_intern[0].title() if top_intern else f"Cluster {cid}",
|
| 125 |
+
'count': len(cdf),
|
| 126 |
+
'avg_gap': cdf['Gap_Score'].mean(),
|
| 127 |
+
'missing': sorted(top_industry_set - set(top_intern))[:8],
|
| 128 |
+
'has': sorted(top_industry_set & set(top_intern))[:6],
|
| 129 |
+
'top_skills': top_intern[:8],
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
heatmap_rows = []
|
| 133 |
+
for cid in range(k):
|
| 134 |
+
center = kmi.cluster_centers_[cid]
|
| 135 |
+
row = [float(center[tfidf.vocabulary_[s]]) if s in tfidf.vocabulary_ else 0 for s in top_industry_skills]
|
| 136 |
+
heatmap_rows.append(row)
|
| 137 |
+
|
| 138 |
+
pca = PCA(n_components=2, random_state=42)
|
| 139 |
+
sidx = np.random.choice(iv.shape[0], min(800, iv.shape[0]), replace=False)
|
| 140 |
+
coords = pca.fit_transform(iv[sidx].toarray())
|
| 141 |
+
df_pca = pd.DataFrame({
|
| 142 |
+
'x': coords[:,0], 'y': coords[:,1],
|
| 143 |
+
'cluster': intern_df.iloc[sidx]['Cluster'].values,
|
| 144 |
+
'gap': intern_df.iloc[sidx]['Gap_Score'].values,
|
| 145 |
+
'role': intern_df.iloc[sidx]['Job_Role'].values,
|
| 146 |
+
})
|
| 147 |
+
|
| 148 |
+
skill_freq = Counter([s for lst in intern_df['skills_list'] for s in lst]).most_common(20)
|
| 149 |
+
return intern_df, profiles, heatmap_rows, top_industry_skills, df_pca, skill_freq, k
|
| 150 |
+
|
| 151 |
+
# ββ Chart builders ββββββββββββββββββββββββββββββββ
|
| 152 |
+
def make_overview_charts(profiles, intern_df, K):
|
| 153 |
+
cids = list(profiles.keys())
|
| 154 |
+
labels = [profiles[c]['label'] for c in cids]
|
| 155 |
+
gaps = [profiles[c]['avg_gap'] for c in cids]
|
| 156 |
+
|
| 157 |
+
# Bar chart
|
| 158 |
+
fig_bar = go.Figure(go.Bar(
|
| 159 |
+
x=gaps, y=labels, orientation='h',
|
| 160 |
+
marker=dict(color=[GAP_COLS(g) for g in gaps], line=dict(width=0)),
|
| 161 |
+
text=[f"{g:.3f}" for g in gaps], textposition='outside',
|
| 162 |
+
textfont=dict(color="#a8a6a0", size=11),
|
| 163 |
+
))
|
| 164 |
+
fig_bar.add_vline(x=0.89, line_dash="dash", line_color="#f87171", line_width=1,
|
| 165 |
+
annotation_text="critical", annotation_font_color="#f87171")
|
| 166 |
+
fig_bar.add_vline(x=0.79, line_dash="dash", line_color="#fbbf24", line_width=1)
|
| 167 |
+
fig_bar.update_layout(**PLOTLY_THEME, height=300, title="Gap score by cluster",
|
| 168 |
+
xaxis=dict(range=[0.4,1.05], title="gap score", gridcolor="#1e1e2e"),
|
| 169 |
+
yaxis=dict(gridcolor="rgba(0,0,0,0)"), bargap=0.35)
|
| 170 |
+
|
| 171 |
+
# Donut
|
| 172 |
+
fig_pie = go.Figure(go.Pie(
|
| 173 |
+
labels=labels, values=[profiles[c]['count'] for c in cids],
|
| 174 |
+
hole=0.6, marker=dict(colors=COLORS5[:K], line=dict(color="#0a0a0f", width=2)),
|
| 175 |
+
textinfo='percent', textfont=dict(size=11),
|
| 176 |
+
))
|
| 177 |
+
fig_pie.update_layout(**PLOTLY_THEME, height=300, title="Intern distribution",
|
| 178 |
+
showlegend=True, legend=dict(font=dict(size=10, color="#a8a6a0"), bgcolor="rgba(0,0,0,0)"))
|
| 179 |
+
|
| 180 |
+
# Violin
|
| 181 |
+
fig_vio = go.Figure()
|
| 182 |
+
for i, cid in enumerate(cids):
|
| 183 |
+
sub = intern_df[intern_df['Cluster']==cid]['Gap_Score']
|
| 184 |
+
fig_vio.add_trace(go.Violin(x=sub, name=profiles[cid]['label'],
|
| 185 |
+
line_color=COLORS5[i%len(COLORS5)],
|
| 186 |
+
fillcolor=COLORS5_RGBA[i%len(COLORS5_RGBA)],
|
| 187 |
+
opacity=0.8, box_visible=True, meanline_visible=True))
|
| 188 |
+
fig_vio.update_layout(**PLOTLY_THEME, height=250, title="Gap distribution",
|
| 189 |
+
xaxis_title="gap score", yaxis=dict(showgrid=False),
|
| 190 |
+
violingap=0.2, violinmode='overlay')
|
| 191 |
+
|
| 192 |
+
return fig_bar, fig_pie, fig_vio
|
| 193 |
+
|
| 194 |
+
def make_heatmap(heatmap_rows, top_skills, profiles, K):
|
| 195 |
+
z = np.array(heatmap_rows)
|
| 196 |
+
cluster_labels = [f"C{c}: {profiles[c]['label']}" for c in range(K)]
|
| 197 |
+
fig = go.Figure(go.Heatmap(
|
| 198 |
+
z=z, x=top_skills, y=cluster_labels,
|
| 199 |
+
colorscale=[[0,"#1a0a2e"],[0.3,"#3c1a6b"],[0.6,"#6c3fc4"],[1.0,"#22d3ee"]],
|
| 200 |
+
text=[[f"{v:.3f}" for v in row] for row in z],
|
| 201 |
+
texttemplate="%{text}", textfont=dict(size=10, color="#e8e6e0"),
|
| 202 |
+
colorbar=dict(tickfont=dict(color="#a8a6a0"))
|
| 203 |
+
))
|
| 204 |
+
fig.update_layout(**PLOTLY_THEME, height=350, title="Skill presence heatmap",
|
| 205 |
+
xaxis=dict(tickangle=-30, gridcolor="rgba(0,0,0,0)"),
|
| 206 |
+
yaxis=dict(gridcolor="rgba(0,0,0,0)"))
|
| 207 |
+
return fig
|
| 208 |
+
|
| 209 |
+
def make_radar(heatmap_rows, top_skills, sel):
|
| 210 |
+
iv_r = np.array(heatmap_rows[sel])
|
| 211 |
+
iv_norm = iv_r / iv_r.max() if iv_r.max() > 0 else iv_r
|
| 212 |
+
ind_r = np.ones(len(top_skills)) * 0.9
|
| 213 |
+
cats = top_skills + [top_skills[0]]
|
| 214 |
+
fig = go.Figure()
|
| 215 |
+
fig.add_trace(go.Scatterpolar(r=list(iv_norm)+[iv_norm[0]], theta=cats, fill='toself',
|
| 216 |
+
fillcolor="rgba(108,99,255,0.2)", line=dict(color=ACCENT, width=2), name="Intern"))
|
| 217 |
+
fig.add_trace(go.Scatterpolar(r=list(ind_r)+[ind_r[0]], theta=cats, fill='toself',
|
| 218 |
+
fillcolor="rgba(34,211,238,0.15)", line=dict(color="#22d3ee", width=2, dash="dash"),
|
| 219 |
+
name="Industry target"))
|
| 220 |
+
fig.update_layout(**PLOTLY_THEME, height=400, title="Radar β intern vs industry",
|
| 221 |
+
polar=dict(bgcolor="#0f0f17",
|
| 222 |
+
radialaxis=dict(visible=True, range=[0,1], gridcolor="#1e1e2e",
|
| 223 |
+
tickfont=dict(color="#5a5a72", size=9)),
|
| 224 |
+
angularaxis=dict(gridcolor="#1e1e2e", tickfont=dict(color="#a8a6a0", size=10))),
|
| 225 |
+
legend=dict(font=dict(color="#a8a6a0"), bgcolor="rgba(0,0,0,0)"))
|
| 226 |
+
return fig
|
| 227 |
+
|
| 228 |
+
def make_skill_charts(skill_freq, profiles, K):
|
| 229 |
+
skills_df = pd.DataFrame(skill_freq, columns=["skill","count"])
|
| 230 |
+
fig_sk = go.Figure(go.Bar(
|
| 231 |
+
x=skills_df['count'], y=skills_df['skill'], orientation='h',
|
| 232 |
+
marker=dict(color=skills_df['count'],
|
| 233 |
+
colorscale=[[0,"#3c1a6b"],[1,"#22d3ee"]], line=dict(width=0)),
|
| 234 |
+
text=skills_df['count'], textposition='outside',
|
| 235 |
+
textfont=dict(color="#a8a6a0", size=10),
|
| 236 |
+
))
|
| 237 |
+
fig_sk.update_layout(**PLOTLY_THEME, height=450, title="Top intern skills",
|
| 238 |
+
xaxis_title="frequency", yaxis=dict(gridcolor="rgba(0,0,0,0)"), bargap=0.3)
|
| 239 |
+
|
| 240 |
+
bub_x = [profiles[c]['avg_gap'] for c in range(K)]
|
| 241 |
+
bub_s = [profiles[c]['count'] for c in range(K)]
|
| 242 |
+
bub_l = [profiles[c]['label'] for c in range(K)]
|
| 243 |
+
fig_bub = go.Figure(go.Scatter(
|
| 244 |
+
x=bub_x, y=list(range(K)), mode='markers+text',
|
| 245 |
+
marker=dict(size=[s/max(bub_s)*60+20 for s in bub_s],
|
| 246 |
+
color=[GAP_COLS(g) for g in bub_x], opacity=0.85,
|
| 247 |
+
line=dict(color="#0a0a0f", width=2)),
|
| 248 |
+
text=bub_l, textposition="middle right",
|
| 249 |
+
textfont=dict(color="#a8a6a0", size=11),
|
| 250 |
+
))
|
| 251 |
+
fig_bub.update_layout(**PLOTLY_THEME, height=300, title="Gap bubble chart",
|
| 252 |
+
xaxis=dict(title="avg gap score", range=[0.4,1.05]),
|
| 253 |
+
yaxis=dict(visible=False), showlegend=False)
|
| 254 |
+
return fig_sk, fig_bub
|
| 255 |
+
|
| 256 |
+
def make_pca_charts(df_pca, intern_df, profiles, K):
|
| 257 |
+
fig_sc = go.Figure()
|
| 258 |
+
for cid in range(K):
|
| 259 |
+
sub = df_pca[df_pca['cluster']==cid]
|
| 260 |
+
fig_sc.add_trace(go.Scatter(
|
| 261 |
+
x=sub['x'], y=sub['y'], mode='markers',
|
| 262 |
+
name=f"C{cid}: {profiles[cid]['label']}",
|
| 263 |
+
marker=dict(color=COLORS5[cid%len(COLORS5)], size=5, opacity=0.7,
|
| 264 |
+
line=dict(width=0)),
|
| 265 |
+
hovertemplate="<b>%{customdata[0]}</b><br>gap: %{customdata[1]:.3f}<extra></extra>",
|
| 266 |
+
customdata=np.stack([sub['role'], sub['gap']], axis=-1)
|
| 267 |
+
))
|
| 268 |
+
fig_sc.update_layout(**PLOTLY_THEME, height=450, title="2D PCA cluster map",
|
| 269 |
+
xaxis_title="PC1", yaxis_title="PC2",
|
| 270 |
+
legend=dict(font=dict(color="#a8a6a0", size=10), bgcolor="rgba(0,0,0,0)"))
|
| 271 |
+
|
| 272 |
+
sample = intern_df.sample(min(500, len(intern_df)), random_state=42)
|
| 273 |
+
fig_gs = go.Figure()
|
| 274 |
+
for cid in range(K):
|
| 275 |
+
sub = sample[sample['Cluster']==cid]
|
| 276 |
+
fig_gs.add_trace(go.Scatter(
|
| 277 |
+
x=sub['Similarity'], y=sub['Gap_Score'], mode='markers',
|
| 278 |
+
name=f"C{cid}",
|
| 279 |
+
marker=dict(color=COLORS5[cid%len(COLORS5)], size=4, opacity=0.6,
|
| 280 |
+
line=dict(width=0))
|
| 281 |
+
))
|
| 282 |
+
fig_gs.update_layout(**PLOTLY_THEME, height=300, title="Gap score vs similarity",
|
| 283 |
+
xaxis_title="similarity", yaxis_title="gap score",
|
| 284 |
+
legend=dict(font=dict(color="#a8a6a0", size=10), bgcolor="rgba(0,0,0,0)"))
|
| 285 |
+
return fig_sc, fig_gs
|
| 286 |
+
|
| 287 |
+
# ββ Main analysis function ββββββββββββββββββββββββ
|
| 288 |
+
def analyze(intern_file, industry_file, k, top_n, min_df, max_df, cluster_sel, radar_sel):
|
| 289 |
+
# Load data
|
| 290 |
+
if intern_file is not None and industry_file is not None:
|
| 291 |
+
intern_df = pd.read_csv(intern_file.name)
|
| 292 |
+
industry_df = pd.read_csv(industry_file.name)
|
| 293 |
+
else:
|
| 294 |
+
intern_df, industry_df = generate_demo_data()
|
| 295 |
+
|
| 296 |
+
k = int(k)
|
| 297 |
+
top_n = int(top_n)
|
| 298 |
+
min_df = int(min_df)
|
| 299 |
+
|
| 300 |
+
intern_df, profiles, heatmap_rows, top_skills, df_pca, skill_freq, K = \
|
| 301 |
+
run_pipeline(intern_df, industry_df, k, top_n, min_df, max_df)
|
| 302 |
+
|
| 303 |
+
# KPI summary
|
| 304 |
+
total = len(intern_df)
|
| 305 |
+
avg_gap = intern_df['Gap_Score'].mean()
|
| 306 |
+
critical_n = sum(1 for p in profiles.values() if p['avg_gap'] > 0.89)
|
| 307 |
+
|
| 308 |
+
kpi_html = f"""
|
| 309 |
+
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin:16px 0">
|
| 310 |
+
<div style="background:#13131e;border:1px solid #1e1e30;border-radius:12px;padding:1rem;text-align:center">
|
| 311 |
+
<div style="font-size:0.7rem;color:#5a5a72;text-transform:uppercase;letter-spacing:0.1em">Total interns</div>
|
| 312 |
+
<div style="font-size:1.8rem;font-weight:700;color:#f0ede6">{total:,}</div>
|
| 313 |
+
</div>
|
| 314 |
+
<div style="background:#13131e;border:1px solid #1e1e30;border-radius:12px;padding:1rem;text-align:center">
|
| 315 |
+
<div style="font-size:0.7rem;color:#5a5a72;text-transform:uppercase;letter-spacing:0.1em">Avg gap score</div>
|
| 316 |
+
<div style="font-size:1.8rem;font-weight:700;color:#f87171">{avg_gap:.3f}</div>
|
| 317 |
+
</div>
|
| 318 |
+
<div style="background:#13131e;border:1px solid #1e1e30;border-radius:12px;padding:1rem;text-align:center">
|
| 319 |
+
<div style="font-size:0.7rem;color:#5a5a72;text-transform:uppercase;letter-spacing:0.1em">Clusters</div>
|
| 320 |
+
<div style="font-size:1.8rem;font-weight:700;color:#f0ede6">{K}</div>
|
| 321 |
+
</div>
|
| 322 |
+
<div style="background:#13131e;border:1px solid #1e1e30;border-radius:12px;padding:1rem;text-align:center">
|
| 323 |
+
<div style="font-size:0.7rem;color:#5a5a72;text-transform:uppercase;letter-spacing:0.1em">Critical clusters</div>
|
| 324 |
+
<div style="font-size:1.8rem;font-weight:700;color:#f87171">{critical_n}/{K}</div>
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
"""
|
| 328 |
+
|
| 329 |
+
# Cluster summary table
|
| 330 |
+
rows = ""
|
| 331 |
+
for cid, p in profiles.items():
|
| 332 |
+
sev = severity(p['avg_gap'])
|
| 333 |
+
rows += f"""<tr>
|
| 334 |
+
<td style="padding:8px 12px;color:#c8c6c0">Cluster {cid}</td>
|
| 335 |
+
<td style="padding:8px 12px;color:#a8a6a0">{p['label']}</td>
|
| 336 |
+
<td style="padding:8px 12px;color:#a8a6a0">{p['count']:,}</td>
|
| 337 |
+
<td style="padding:8px 12px;color:#f0ede6;font-weight:500">{p['avg_gap']:.3f}</td>
|
| 338 |
+
<td style="padding:8px 12px">{sev}</td>
|
| 339 |
+
<td style="padding:8px 12px;color:#f87171;font-size:0.85rem">{', '.join(p['missing'][:4])}</td>
|
| 340 |
+
</tr>"""
|
| 341 |
+
|
| 342 |
+
table_html = f"""
|
| 343 |
+
<div style="background:#0f0f17;border:1px solid #1e1e2e;border-radius:12px;overflow:hidden;margin:8px 0">
|
| 344 |
+
<table style="width:100%;border-collapse:collapse;font-size:0.88rem">
|
| 345 |
+
<thead>
|
| 346 |
+
<tr style="background:#13131e;border-bottom:1px solid #1e1e2e">
|
| 347 |
+
<th style="padding:10px 12px;color:#5a5a72;text-align:left;font-weight:400;font-size:0.75rem;text-transform:uppercase;letter-spacing:0.08em">Cluster</th>
|
| 348 |
+
<th style="padding:10px 12px;color:#5a5a72;text-align:left;font-weight:400;font-size:0.75rem;text-transform:uppercase;letter-spacing:0.08em">Name</th>
|
| 349 |
+
<th style="padding:10px 12px;color:#5a5a72;text-align:left;font-weight:400;font-size:0.75rem;text-transform:uppercase;letter-spacing:0.08em">Count</th>
|
| 350 |
+
<th style="padding:10px 12px;color:#5a5a72;text-align:left;font-weight:400;font-size:0.75rem;text-transform:uppercase;letter-spacing:0.08em">Avg gap</th>
|
| 351 |
+
<th style="padding:10px 12px;color:#5a5a72;text-align:left;font-weight:400;font-size:0.75rem;text-transform:uppercase;letter-spacing:0.08em">Severity</th>
|
| 352 |
+
<th style="padding:10px 12px;color:#5a5a72;text-align:left;font-weight:400;font-size:0.75rem;text-transform:uppercase;letter-spacing:0.08em">Top missing skills</th>
|
| 353 |
+
</tr>
|
| 354 |
+
</thead>
|
| 355 |
+
<tbody style="border-top:1px solid #1e1e2e">{rows}</tbody>
|
| 356 |
+
</table>
|
| 357 |
+
</div>"""
|
| 358 |
+
|
| 359 |
+
# Build all charts
|
| 360 |
+
fig_bar, fig_pie, fig_vio = make_overview_charts(profiles, intern_df, K)
|
| 361 |
+
fig_hm = make_heatmap(heatmap_rows, top_skills, profiles, K)
|
| 362 |
+
|
| 363 |
+
sel_r = min(int(radar_sel) if str(radar_sel).isdigit() else 0, K-1)
|
| 364 |
+
fig_rad = make_radar(heatmap_rows, top_skills, sel_r)
|
| 365 |
+
|
| 366 |
+
fig_sk, fig_bub = make_skill_charts(skill_freq, profiles, K)
|
| 367 |
+
fig_sc, fig_gs = make_pca_charts(df_pca, intern_df, profiles, K)
|
| 368 |
+
|
| 369 |
+
# Recommendations HTML
|
| 370 |
+
training_plans = {
|
| 371 |
+
0: {"priority":["cloud platforms","agile methodologies","data analytics","SQL"],
|
| 372 |
+
"courses":["AWS Cloud Practitioner","Google Data Analytics","Agile Scrum","SQL Bootcamp"],
|
| 373 |
+
"timeline":"3β4 months"},
|
| 374 |
+
1: {"priority":["cloud deployment","agile workflows","database design","CI/CD"],
|
| 375 |
+
"courses":["AWS Solutions Architect","dbt Fundamentals","GitHub Actions","Airflow"],
|
| 376 |
+
"timeline":"2β3 months"},
|
| 377 |
+
2: {"priority":["data analytics","BI platforms","cloud tools","communication"],
|
| 378 |
+
"courses":["Power BI","Tableau","Cloud for Finance","Data Storytelling"],
|
| 379 |
+
"timeline":"3β4 months"},
|
| 380 |
+
3: {"priority":["agile/scrum","cloud services","data analysis","business context"],
|
| 381 |
+
"courses":["PSM I Scrum","AWS for Devs","Python for Data","Product Thinking"],
|
| 382 |
+
"timeline":"2β3 months"},
|
| 383 |
+
4: {"priority":["cloud ML","agile practices","analytics engineering","SQL"],
|
| 384 |
+
"courses":["MLflow + SageMaker","dbt Analytics","SQL for ML","Agile for AI"],
|
| 385 |
+
"timeline":"2 months"},
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
rec_html = ""
|
| 389 |
+
for cid in range(K):
|
| 390 |
+
p = profiles[cid]
|
| 391 |
+
plan = training_plans.get(cid % 5, training_plans[0])
|
| 392 |
+
sev = severity(p['avg_gap'])
|
| 393 |
+
pills = "".join(f'<span style="display:inline-block;padding:3px 10px;margin:2px;background:#2d1515;border:1px solid #5c2020;border-radius:6px;font-size:0.78rem;color:#f87171">{s}</span>' for s in plan['priority'])
|
| 394 |
+
courses = "".join(f'<span style="display:inline-block;padding:3px 10px;margin:2px;background:#1a1a2e;border:1px solid #2a2a42;border-radius:6px;font-size:0.78rem;color:#8888aa">{c}</span>' for c in plan['courses'])
|
| 395 |
+
rec_html += f"""
|
| 396 |
+
<div style="background:#13131e;border:1px solid #1e1e30;border-radius:12px;padding:1rem 1.2rem;margin-bottom:10px">
|
| 397 |
+
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px">
|
| 398 |
+
<div style="font-weight:600;color:#f0ede6">Cluster {cid} β {p['label']}</div>
|
| 399 |
+
<div style="font-size:0.78rem;color:#5a5a72">{p['count']:,} interns Β· {plan['timeline']} Β· {sev}</div>
|
| 400 |
+
</div>
|
| 401 |
+
<div style="margin-bottom:6px"><span style="font-size:0.72rem;color:#5a5a72;text-transform:uppercase;letter-spacing:0.08em">Priority skills: </span>{pills}</div>
|
| 402 |
+
<div><span style="font-size:0.72rem;color:#5a5a72;text-transform:uppercase;letter-spacing:0.08em">Courses: </span>{courses}</div>
|
| 403 |
+
</div>"""
|
| 404 |
+
|
| 405 |
+
# Export CSV
|
| 406 |
+
export_df = intern_df[['Job_Role','Cluster','Gap_Score','Similarity']].copy()
|
| 407 |
+
export_df.to_csv("intern_gap_results.csv", index=False)
|
| 408 |
+
|
| 409 |
+
return (kpi_html, table_html,
|
| 410 |
+
fig_bar, fig_pie, fig_vio,
|
| 411 |
+
fig_hm, fig_rad,
|
| 412 |
+
fig_sk, fig_bub,
|
| 413 |
+
fig_sc, fig_gs,
|
| 414 |
+
rec_html,
|
| 415 |
+
"intern_gap_results.csv")
|
| 416 |
+
|
| 417 |
+
# ββ Gradio UI βββββββββββββββββββββββββββββββββββββ
|
| 418 |
+
css = """
|
| 419 |
+
body { background: #0a0a0f !important; }
|
| 420 |
+
.gradio-container { background: #0a0a0f !important; font-family: 'DM Sans', sans-serif; }
|
| 421 |
+
.gr-panel { background: #0f0f17 !important; border: 1px solid #1e1e2e !important; }
|
| 422 |
+
h1, h2, h3, label, .gr-block-label { color: #c8c6c0 !important; }
|
| 423 |
+
.gr-button-primary { background: #6c63ff !important; border: none !important; color: white !important; }
|
| 424 |
+
.gr-button-primary:hover { background: #7c73ff !important; }
|
| 425 |
+
footer { display: none !important; }
|
| 426 |
+
"""
|
| 427 |
+
|
| 428 |
+
with gr.Blocks(css=css, title="β SkillScope β Intern Gap Analyzer") as demo:
|
| 429 |
+
|
| 430 |
+
gr.HTML("""
|
| 431 |
+
<div style="text-align:center;padding:2rem 0 1rem">
|
| 432 |
+
<div style="font-size:2.5rem;font-weight:800;color:#f0ede6;letter-spacing:-0.03em">β SkillScope</div>
|
| 433 |
+
<div style="font-size:0.85rem;color:#5a5a72;letter-spacing:0.15em;text-transform:uppercase;margin-top:4px">
|
| 434 |
+
Intern Skill Gap Analyzer Β· NLP + Clustering Intelligence
|
| 435 |
+
</div>
|
| 436 |
+
</div>
|
| 437 |
+
""")
|
| 438 |
+
|
| 439 |
+
# ββ Controls ββββββββββββββββββββββββββββββββββ
|
| 440 |
+
with gr.Row():
|
| 441 |
+
with gr.Column(scale=1):
|
| 442 |
+
gr.Markdown("### β Pipeline Config")
|
| 443 |
+
k_slider = gr.Slider(2, 10, value=5, step=1, label="Clusters (K)")
|
| 444 |
+
topn_slider = gr.Slider(5, 20, value=10, step=1, label="Top N skills")
|
| 445 |
+
mindf_slider = gr.Slider(1, 10, value=2, step=1, label="TF-IDF min_df")
|
| 446 |
+
maxdf_slider = gr.Slider(0.70, 1.0, value=0.95, step=0.05, label="TF-IDF max_df")
|
| 447 |
+
gr.Markdown("### π Upload CSVs (optional)")
|
| 448 |
+
intern_file = gr.File(label="Intern / Resume CSV", file_types=[".csv"])
|
| 449 |
+
industry_file = gr.File(label="Industry / Jobs CSV", file_types=[".csv"])
|
| 450 |
+
gr.Markdown("### π Chart Options")
|
| 451 |
+
radar_sel = gr.Number(value=0, label="Radar cluster index", precision=0)
|
| 452 |
+
cluster_sel = gr.Number(value=0, label="Cluster select (unused)", precision=0, visible=False)
|
| 453 |
+
run_btn = gr.Button("βΆ Run Analysis", variant="primary")
|
| 454 |
+
|
| 455 |
+
# ββ Results βββββββββββββββββββββββββββββββ
|
| 456 |
+
with gr.Column(scale=3):
|
| 457 |
+
with gr.Tabs():
|
| 458 |
+
|
| 459 |
+
with gr.Tab("π Overview"):
|
| 460 |
+
kpi_out = gr.HTML()
|
| 461 |
+
table_out = gr.HTML()
|
| 462 |
+
with gr.Row():
|
| 463 |
+
bar_out = gr.Plot()
|
| 464 |
+
pie_out = gr.Plot()
|
| 465 |
+
vio_out = gr.Plot()
|
| 466 |
+
|
| 467 |
+
with gr.Tab("πΊ Heatmap & Radar"):
|
| 468 |
+
hm_out = gr.Plot()
|
| 469 |
+
rad_out = gr.Plot()
|
| 470 |
+
|
| 471 |
+
with gr.Tab("π Skill Explorer"):
|
| 472 |
+
sk_out = gr.Plot()
|
| 473 |
+
bub_out = gr.Plot()
|
| 474 |
+
|
| 475 |
+
with gr.Tab("π§ 2D Cluster Map"):
|
| 476 |
+
sc_out = gr.Plot()
|
| 477 |
+
gs_out = gr.Plot()
|
| 478 |
+
|
| 479 |
+
with gr.Tab("π Recommendations"):
|
| 480 |
+
rec_out = gr.HTML()
|
| 481 |
+
dl_out = gr.File(label="Download intern results CSV")
|
| 482 |
+
|
| 483 |
+
run_btn.click(
|
| 484 |
+
fn=analyze,
|
| 485 |
+
inputs=[intern_file, industry_file, k_slider, topn_slider,
|
| 486 |
+
mindf_slider, maxdf_slider, cluster_sel, radar_sel],
|
| 487 |
+
outputs=[kpi_out, table_out,
|
| 488 |
+
bar_out, pie_out, vio_out,
|
| 489 |
+
hm_out, rad_out,
|
| 490 |
+
sk_out, bub_out,
|
| 491 |
+
sc_out, gs_out,
|
| 492 |
+
rec_out, dl_out]
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
+
demo.load(
|
| 496 |
+
fn=analyze,
|
| 497 |
+
inputs=[intern_file, industry_file, k_slider, topn_slider,
|
| 498 |
+
mindf_slider, maxdf_slider, cluster_sel, radar_sel],
|
| 499 |
+
outputs=[kpi_out, table_out,
|
| 500 |
+
bar_out, pie_out, vio_out,
|
| 501 |
+
hm_out, rad_out,
|
| 502 |
+
sk_out, bub_out,
|
| 503 |
+
sc_out, gs_out,
|
| 504 |
+
rec_out, dl_out]
|
| 505 |
+
)
|
| 506 |
+
|
| 507 |
+
demo.launch()
|