Update app.py
Browse files
app.py
CHANGED
|
@@ -3,257 +3,171 @@ import spacy
|
|
| 3 |
import pdfplumber
|
| 4 |
from docx import Document
|
| 5 |
from sentence_transformers import SentenceTransformer, util
|
| 6 |
-
import pandas as pd
|
| 7 |
import re
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
print("
|
| 11 |
try:
|
| 12 |
nlp = spacy.load("en_core_web_sm")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
import en_core_web_sm
|
| 18 |
-
nlp = en_core_web_sm.load()
|
| 19 |
-
except:
|
| 20 |
-
print("Model not found. Using fallback keyword matching only.")
|
| 21 |
-
nlp = None
|
| 22 |
|
| 23 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 24 |
-
print("Sentence Transformer loaded.")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
SKILLS_DB = [
|
| 28 |
"python", "javascript", "react", "fastapi", "aws", "docker", "kubernetes", "sql",
|
| 29 |
-
"git", "
|
| 30 |
-
"
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
]
|
| 36 |
|
| 37 |
ROADMAP_DB = {
|
| 38 |
-
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
"
|
| 45 |
-
"
|
| 46 |
-
"
|
| 47 |
-
"
|
| 48 |
-
"git": "Version Control: [Git Immersion](https://gitimmersion.com/) | [GitHub Learning Path](https://skills.github.com/)",
|
| 49 |
-
"javascript": "JS Deep Dive: [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript) | [JavaScript.info](https://javascript.info/)",
|
| 50 |
-
"typescript": "Strict Typing: [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)",
|
| 51 |
-
"postgresql": "Advanced Data: [Postgres Tutorial](https://www.postgresqltutorial.com/)",
|
| 52 |
-
"rest api": "API Design: [RESTful API Guide](https://restfulapi.net/)",
|
| 53 |
-
"html": "Web Basics: [W3Schools HTML](https://www.w3schools.com/html/)",
|
| 54 |
-
"css": "Styling: [CSS-Tricks](https://css-tricks.com/)",
|
| 55 |
-
"node.js": "Backend JS: [Node.js Guide](https://nodejs.dev/en/learn/)"
|
| 56 |
}
|
| 57 |
|
| 58 |
-
def
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
text = ""
|
| 62 |
-
for page in pdf.pages:
|
| 63 |
-
text += page.extract_text() or ""
|
| 64 |
-
return text
|
| 65 |
-
except Exception as e:
|
| 66 |
-
print(f"PDF Extraction Error: {e}")
|
| 67 |
return ""
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
try:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
except Exception as e:
|
| 77 |
-
print(f"
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
def
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
if resume_path.lower().endswith('.pdf'):
|
| 104 |
-
resume_text = extract_text_from_pdf(resume_path)
|
| 105 |
-
elif resume_path.lower().endswith('.docx'):
|
| 106 |
-
resume_text = extract_text_from_docx(resume_path)
|
| 107 |
-
else:
|
| 108 |
-
return "Unsupported file format. Please upload PDF or DOCX.", "", "", 0, []
|
| 109 |
|
|
|
|
|
|
|
| 110 |
if not resume_text.strip():
|
| 111 |
-
return "
|
| 112 |
-
|
| 113 |
-
#
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
print(f"Match: {match_percentage}%")
|
| 137 |
-
return f"{match_percentage}%", present_str, missing_str, match_percentage, missing_skills
|
| 138 |
-
|
| 139 |
-
def get_roadmap(missing_skills):
|
| 140 |
-
if not missing_skills:
|
| 141 |
-
return "### π Perfect Match!\nYou already possess all the key skills mentioned in the job description. Tip: ensure you've highlighted these clearly in your experience sections."
|
| 142 |
|
| 143 |
-
|
| 144 |
-
for
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
custom_css = """
|
| 152 |
-
#logo-img {
|
| 153 |
-
margin: auto;
|
| 154 |
-
display: block;
|
| 155 |
-
max-width: 150px;
|
| 156 |
-
}
|
| 157 |
-
.gradio-container {
|
| 158 |
-
background-color: #f0f2f5;
|
| 159 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 160 |
-
}
|
| 161 |
-
.main-header {
|
| 162 |
-
text-align: center;
|
| 163 |
-
color: #003366;
|
| 164 |
-
margin-bottom: 5px;
|
| 165 |
-
}
|
| 166 |
-
.sub-header {
|
| 167 |
-
text-align: center;
|
| 168 |
-
color: #b8860b;
|
| 169 |
-
margin-top: 0;
|
| 170 |
-
font-style: italic;
|
| 171 |
-
}
|
| 172 |
-
.sastra-text {
|
| 173 |
-
text-align: center;
|
| 174 |
-
font-size: 1em;
|
| 175 |
-
color: #444;
|
| 176 |
-
font-weight: bold;
|
| 177 |
-
}
|
| 178 |
-
#analyze-btn {
|
| 179 |
-
background: linear-gradient(135deg, #003366 0%, #00509d 100%) !important;
|
| 180 |
-
border: none !important;
|
| 181 |
-
color: white !important;
|
| 182 |
-
height: 50px;
|
| 183 |
-
font-size: 1.1em;
|
| 184 |
-
}
|
| 185 |
-
#roadmap-btn {
|
| 186 |
-
background: linear-gradient(135deg, #b8860b 0%, #daa520 100%) !important;
|
| 187 |
-
border: none !important;
|
| 188 |
-
color: white !important;
|
| 189 |
-
height: 45px;
|
| 190 |
-
}
|
| 191 |
-
.output-label {
|
| 192 |
-
text-align: center;
|
| 193 |
-
font-size: 2em;
|
| 194 |
-
}
|
| 195 |
-
"""
|
| 196 |
-
|
| 197 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), css=custom_css) as demo:
|
| 198 |
with gr.Row():
|
| 199 |
with gr.Column(scale=1):
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
gr.Markdown("# SETHU AI", elem_classes=["main-header"])
|
| 206 |
-
gr.Markdown("### From Resume to Career Readiness", elem_classes=["sub-header"])
|
| 207 |
-
gr.Markdown("SASTRA DEEMED UNIVERSITY", elem_classes=["sastra-text"])
|
| 208 |
-
|
| 209 |
gr.Markdown("---")
|
| 210 |
-
|
| 211 |
with gr.Row():
|
| 212 |
with gr.Column(scale=1):
|
| 213 |
-
gr.Markdown("### π₯
|
| 214 |
-
resume_input = gr.File(label="Upload Resume (PDF/DOCX)"
|
| 215 |
-
jd_input = gr.Textbox(label="Job Description", placeholder="Paste the job requirements here..."
|
| 216 |
-
|
| 217 |
|
| 218 |
with gr.Column(scale=1):
|
| 219 |
-
gr.Markdown("### π
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
missing_skills_output = gr.Textbox(label="", interactive=False, lines=4)
|
| 227 |
-
|
| 228 |
gr.Markdown("---")
|
| 229 |
-
roadmap_btn = gr.Button("π Generate
|
|
|
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
missing_skills_output: missing,
|
| 240 |
-
missing_skills_state: missing_list,
|
| 241 |
-
roadmap_output: gr.update(visible=False)
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
def on_roadmap(missing_list):
|
| 245 |
-
content = get_roadmap(missing_list)
|
| 246 |
-
return gr.update(value=content, visible=True)
|
| 247 |
-
|
| 248 |
-
analyze_btn.click(
|
| 249 |
-
on_analyze,
|
| 250 |
-
inputs=[resume_input, jd_input],
|
| 251 |
-
outputs=[match_score_output, present_skills_output, missing_skills_output, missing_skills_state, roadmap_output]
|
| 252 |
)
|
| 253 |
-
|
| 254 |
roadmap_btn.click(
|
| 255 |
-
|
| 256 |
-
inputs=[
|
| 257 |
outputs=[roadmap_output]
|
| 258 |
)
|
| 259 |
|
|
|
|
| 3 |
import pdfplumber
|
| 4 |
from docx import Document
|
| 5 |
from sentence_transformers import SentenceTransformer, util
|
|
|
|
| 6 |
import re
|
| 7 |
+
import plotly.graph_objects as go
|
| 8 |
|
| 9 |
+
# Initialize Models once at startup
|
| 10 |
+
print("π Initializing SETHU AI Engine...")
|
| 11 |
try:
|
| 12 |
nlp = spacy.load("en_core_web_sm")
|
| 13 |
+
except:
|
| 14 |
+
import os
|
| 15 |
+
os.system("python -m spacy download en_core_web_sm")
|
| 16 |
+
nlp = spacy.load("en_core_web_sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
|
|
| 19 |
|
| 20 |
+
TECH_SKILLS = [
|
|
|
|
| 21 |
"python", "javascript", "react", "fastapi", "aws", "docker", "kubernetes", "sql",
|
| 22 |
+
"git", "ml", "nlp", "tensorflow", "pytorch", "java", "golang", "postgresql",
|
| 23 |
+
"mongodb", "redis", "devops", "rest api", "graphql", "scikit-learn", "pandas",
|
| 24 |
+
"numpy", "django", "flask", "typescript", "angular", "vue", "html", "css",
|
| 25 |
+
"node.js", "express", "azure", "gcp", "linux", "terraform", "ansible", "jenkins",
|
| 26 |
+
"prompt engineering", "openai", "llm", "bert", "tableau", "powerbi", "excel",
|
| 27 |
+
"c#", "c++", "rust", "r", "spark", "hadoop", "kafka", "mysql", "oracle", "snowflake"
|
| 28 |
]
|
| 29 |
|
| 30 |
ROADMAP_DB = {
|
| 31 |
+
"python": "π [Master Python](https://realpython.com/) - Focus on Backend Automation & Data Science.",
|
| 32 |
+
"react": "βοΈ [React.dev](https://react.dev/) - Master Hooks & State Management.",
|
| 33 |
+
"aws": "βοΈ [AWS Builder](https://explore.skillbuilder.aws/) - Get Certified (Solutions Architect).",
|
| 34 |
+
"docker": "π³ [Docker Guide](https://docs.docker.com/) - Learn Container Architecture.",
|
| 35 |
+
"kubernetes": "βΈοΈ [K8s Certification](https://kubernetes.io/docs/tutorials/) - Master Orchestration.",
|
| 36 |
+
"ml": "π€ [ML Specialization](https://www.coursera.org/specializations/machine-learning-introduction) - Focus on Scikit-Learn.",
|
| 37 |
+
"nlp": "βοΈ [HF NLP Course](https://huggingface.co/learn/nlp-course/) - Master Transformers.",
|
| 38 |
+
"sql": "πΎ [SQL Practice](https://sqlzoo.net/) - Master Joins & Query Optmization.",
|
| 39 |
+
"javascript": "π [JS.info](https://javascript.info/) - Master ES6+ Features.",
|
| 40 |
+
"devops": "βοΈ [Roadmap.sh/devops](https://roadmap.sh/devops/) - Learn CI/CD & Infrastructure as Code."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
+
def extract_text(file_obj):
|
| 44 |
+
"""Robust text extraction for PDF and DOCX."""
|
| 45 |
+
if file_obj is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return ""
|
| 47 |
+
|
| 48 |
+
# Gradio might pass a file-like object or a string path
|
| 49 |
+
file_path = file_obj.name if hasattr(file_obj, 'name') else str(file_obj)
|
| 50 |
+
|
| 51 |
try:
|
| 52 |
+
if file_path.lower().endswith('.pdf'):
|
| 53 |
+
with pdfplumber.open(file_path) as pdf:
|
| 54 |
+
return "".join([page.extract_text() or "" for page in pdf.pages])
|
| 55 |
+
elif file_path.lower().endswith('.docx'):
|
| 56 |
+
doc = Document(file_path)
|
| 57 |
+
return "\n".join([p.text for p in doc.paragraphs])
|
| 58 |
except Exception as e:
|
| 59 |
+
print(f"Extraction error on {file_path}: {e}")
|
| 60 |
+
return ""
|
| 61 |
+
|
| 62 |
+
def discover_skills(text):
|
| 63 |
+
if not text: return set()
|
| 64 |
+
found = set()
|
| 65 |
+
text_l = text.lower()
|
| 66 |
+
for skill in TECH_SKILLS:
|
| 67 |
+
if re.search(r'\b' + re.escape(skill) + r'\b', text_l):
|
| 68 |
+
found.add(skill)
|
| 69 |
+
return found
|
| 70 |
+
|
| 71 |
+
def create_gauge(score):
|
| 72 |
+
fig = go.Figure(go.Indicator(
|
| 73 |
+
mode = "gauge+number",
|
| 74 |
+
value = score,
|
| 75 |
+
domain = {'x': [0, 1], 'y': [0, 1]},
|
| 76 |
+
gauge = {
|
| 77 |
+
'axis': {'range': [0, 100]},
|
| 78 |
+
'bar': {'color': "#003366"},
|
| 79 |
+
'steps': [
|
| 80 |
+
{'range': [0, 50], 'color': "#ffcccc"},
|
| 81 |
+
{'range': [50, 80], 'color': "#fff3cd"},
|
| 82 |
+
{'range': [80, 100], 'color': "#d4edda"}
|
| 83 |
+
],
|
| 84 |
+
}
|
| 85 |
+
))
|
| 86 |
+
fig.update_layout(height=250, margin=dict(l=30, r=30, t=30, b=30), paper_bgcolor="rgba(0,0,0,0)")
|
| 87 |
+
return fig
|
| 88 |
|
| 89 |
+
def main_process(resume_file, jd_text):
|
| 90 |
+
print("--- New Analysis Request ---")
|
| 91 |
+
if not resume_file or not jd_text.strip():
|
| 92 |
+
return "β οΈ Error: Please upload a resume and paste the JD.", "", None, [], gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
# 1. Extraction
|
| 95 |
+
resume_text = extract_text(resume_file)
|
| 96 |
if not resume_text.strip():
|
| 97 |
+
return "β οΈ Error: Failed to extract text from resume. Ensure it's not and image-only PDF.", "", None, [], gr.update(visible=False)
|
| 98 |
+
|
| 99 |
+
# 2. Skill Matching
|
| 100 |
+
r_skills = discover_skills(resume_text)
|
| 101 |
+
j_skills = discover_skills(jd_text)
|
| 102 |
+
match_skills = sorted(list(r_skills.intersection(j_skills)))
|
| 103 |
+
gap_skills = sorted(list(j_skills - r_skills))
|
| 104 |
+
|
| 105 |
+
# 3. AI scoring
|
| 106 |
+
emb1 = model.encode(resume_text, convert_to_tensor=True)
|
| 107 |
+
emb2 = model.encode(jd_text, convert_to_tensor=True)
|
| 108 |
+
score = round(util.pytorch_cos_sim(emb1, emb2).item() * 100, 1)
|
| 109 |
+
|
| 110 |
+
# 4. Results Formatting
|
| 111 |
+
present_str = ", ".join([s.upper() for s in match_skills]) if match_skills else "No direct skill matches found."
|
| 112 |
+
gap_str = ", ".join([s.upper() for s in gap_skills]) if gap_skills else "No major skill gaps detected!"
|
| 113 |
+
plot = create_gauge(score)
|
| 114 |
+
|
| 115 |
+
print(f"Analysis Complete. Score: {score}")
|
| 116 |
+
return present_str, gap_str, plot, gap_skills, gr.update(visible=True)
|
| 117 |
+
|
| 118 |
+
def generate_roadmap(gap_skills):
|
| 119 |
+
if not gap_skills:
|
| 120 |
+
return "### π Career Ready!\nYour profile is an excellent match for this role. Focus on practicing behavioral interview questions."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
roadmap = "### π€οΈ Personalized Readiness Roadmap\n\n"
|
| 123 |
+
for s in gap_skills:
|
| 124 |
+
res = ROADMAP_DB.get(s.lower(), f"Learn **{s.upper()}** through hands-on projects and documentation.")
|
| 125 |
+
roadmap += f"- **{s.upper()}**: {res}\n"
|
| 126 |
+
return roadmap
|
| 127 |
+
|
| 128 |
+
# UI Layout
|
| 129 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="SETHU AI") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
with gr.Row():
|
| 131 |
with gr.Column(scale=1):
|
| 132 |
+
gr.Image("logo.png", show_label=False, height=120, container=False)
|
| 133 |
+
with gr.Column(scale=4):
|
| 134 |
+
gr.Markdown("# SETHU AI - Career Intelligence Hub")
|
| 135 |
+
gr.Markdown("### From Resume to Career Readiness | Powered by SASTRA DEEMED UNIVERSITY")
|
| 136 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
gr.Markdown("---")
|
| 138 |
+
|
| 139 |
with gr.Row():
|
| 140 |
with gr.Column(scale=1):
|
| 141 |
+
gr.Markdown("### π₯ 1. Upload Requirements")
|
| 142 |
+
resume_input = gr.File(label="Upload Resume (PDF/DOCX)")
|
| 143 |
+
jd_input = gr.Textbox(label="Job Description", lines=12, placeholder="Paste the job requirements here...")
|
| 144 |
+
run_btn = gr.Button("π Run AI Analysis", variant="primary")
|
| 145 |
|
| 146 |
with gr.Column(scale=1):
|
| 147 |
+
gr.Markdown("### π 2. Match Intelligence")
|
| 148 |
+
gauge_plot = gr.Plot()
|
| 149 |
+
match_display = gr.Textbox(label="Identified Matching Skills", interactive=False)
|
| 150 |
+
gap_display = gr.Textbox(label="Identified Skill Gaps", interactive=False)
|
| 151 |
+
|
| 152 |
+
with gr.Row(visible=False) as roadmap_container:
|
| 153 |
+
with gr.Column():
|
|
|
|
|
|
|
| 154 |
gr.Markdown("---")
|
| 155 |
+
roadmap_btn = gr.Button("π Generate Knowledge Upgrade Roadmap", variant="secondary")
|
| 156 |
+
roadmap_output = gr.Markdown()
|
| 157 |
|
| 158 |
+
# Shared State
|
| 159 |
+
gap_state = gr.State([])
|
| 160 |
|
| 161 |
+
# Event Mapping
|
| 162 |
+
run_btn.click(
|
| 163 |
+
fn=main_process,
|
| 164 |
+
inputs=[resume_input, jd_input],
|
| 165 |
+
outputs=[match_display, gap_display, gauge_plot, gap_state, roadmap_container]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
)
|
| 167 |
+
|
| 168 |
roadmap_btn.click(
|
| 169 |
+
fn=generate_roadmap,
|
| 170 |
+
inputs=[gap_state],
|
| 171 |
outputs=[roadmap_output]
|
| 172 |
)
|
| 173 |
|