Skip to content

Commit bbcbe6c

Browse files
Merge pull request steam-bell-92#1122 from Tech4Aditya/main
fix: lazy-load NLTK resources to eliminate startup overhead
2 parents 03add1c + 172ea69 commit bbcbe6c

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

utilities/AI-Resume-Analyzer/AI-Resume-Analyzer.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@
44
from nltk.tokenize import word_tokenize
55
from nltk.util import ngrams
66

7-
# Ensure NLTK downloads happen at the top level so they're available,
8-
# but can be verified inside main or when running.
9-
nltk.download('punkt')
10-
nltk.download('stopwords')
7+
8+
def _ensure_nltk_resources() -> None:
9+
"""Download NLTK resources only if not already present."""
10+
resources = {
11+
'punkt': 'tokenizers/punkt',
12+
'punkt_tab': 'tokenizers/punkt_tab',
13+
'stopwords': 'corpora/stopwords',
14+
}
15+
for name, path in resources.items():
16+
try:
17+
nltk.data.find(path)
18+
except LookupError:
19+
nltk.download(name, quiet=True)
20+
1121

1222
def analyze_resume(resume_text: str) -> dict:
23+
_ensure_nltk_resources()
24+
1325
resume = resume_text.lower()
1426

1527
# NLP processing
@@ -117,6 +129,7 @@ def analyze_resume(resume_text: str) -> dict:
117129
"all_skills": skills,
118130
}
119131

132+
120133
def main() -> None:
121134
print("=== 🤖 AI Resume Analyzer (Advanced NLP Version) ===")
122135

@@ -159,5 +172,6 @@ def main() -> None:
159172
# Final
160173
print("\n🚀 Analysis Completed")
161174

175+
162176
if __name__ == "__main__":
163177
main()

0 commit comments

Comments
 (0)