-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
136 lines (130 loc) · 6.13 KB
/
app.js
File metadata and controls
136 lines (130 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
const BACKEND_URL = 'http://127.0.0.1:5000';
document.addEventListener('DOMContentLoaded', function() {
const resumeForm = document.getElementById('resumeForm');
const resumeInput = document.getElementById('resumeInput');
const loading = document.getElementById('loading');
const summarySection = document.getElementById('summarySection');
const gapsSection = document.getElementById('gapsSection');
const roadmapSection = document.getElementById('roadmapSection');
const summaryDiv = document.getElementById('summary');
const gapsDiv = document.getElementById('gaps');
const roadmapDiv = document.getElementById('roadmap');
const getJobsBtn = document.getElementById('getJobsBtn');
const jobsSection = document.getElementById('jobsSection');
const linkedinJobsDiv = document.getElementById('linkedinJobs');
const naukriJobsDiv = document.getElementById('naukriJobs');
let resumeText = '';
let summary = '';
let keywords = '';
resumeForm.addEventListener('submit', async function(e) {
e.preventDefault();
if (!resumeInput.files.length) return;
loading.classList.remove('hidden');
summarySection.classList.add('hidden');
gapsSection.classList.add('hidden');
roadmapSection.classList.add('hidden');
getJobsBtn.classList.add('hidden');
jobsSection.classList.add('hidden');
linkedinJobsDiv.innerHTML = '';
naukriJobsDiv.innerHTML = '';
// 1. Upload resume and extract text
const formData = new FormData();
formData.append('resume', resumeInput.files[0]);
try {
const uploadRes = await fetch(`${BACKEND_URL}/api/upload_resume`, {
method: 'POST',
body: formData
});
const uploadData = await uploadRes.json();
if (!uploadRes.ok) throw new Error(uploadData.error || 'Upload failed');
resumeText = uploadData.resume_text;
} catch (err) {
loading.classList.add('hidden');
alert('Error uploading resume: ' + err.message);
return;
}
// 2. Analyze resume
try {
const analyzeRes = await fetch(`${BACKEND_URL}/api/analyze_resume`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ resume_text: resumeText })
});
const analyzeData = await analyzeRes.json();
if (!analyzeRes.ok) throw new Error(analyzeData.error || 'Analysis failed');
summary = analyzeData.summary;
summaryDiv.innerHTML = summary;
gapsDiv.innerHTML = analyzeData.gaps;
roadmapDiv.innerHTML = analyzeData.roadmap;
summarySection.classList.remove('hidden');
gapsSection.classList.remove('hidden');
roadmapSection.classList.remove('hidden');
getJobsBtn.classList.remove('hidden');
} catch (err) {
loading.classList.add('hidden');
alert('Error analyzing resume: ' + err.message);
return;
}
loading.classList.add('hidden');
});
getJobsBtn.addEventListener('click', async function() {
getJobsBtn.disabled = true;
loading.classList.remove('hidden');
jobsSection.classList.add('hidden');
linkedinJobsDiv.innerHTML = '';
naukriJobsDiv.innerHTML = '';
// 3. Get job keywords
try {
const keywordsRes = await fetch(`${BACKEND_URL}/api/job_keywords`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ summary })
});
const keywordsData = await keywordsRes.json();
if (!keywordsRes.ok) throw new Error(keywordsData.error || 'Keyword extraction failed');
keywords = keywordsData.keywords;
} catch (err) {
loading.classList.add('hidden');
getJobsBtn.disabled = false;
alert('Error extracting job keywords: ' + err.message);
return;
}
// 4. Fetch job recommendations
try {
const jobsRes = await fetch(`${BACKEND_URL}/api/job_recommendations`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ keywords })
});
const jobsData = await jobsRes.json();
if (!jobsRes.ok) throw new Error(jobsData.error || 'Job fetch failed');
// LinkedIn jobs
if (jobsData.linkedin_jobs && jobsData.linkedin_jobs.length) {
jobsData.linkedin_jobs.forEach(job => {
const jobDiv = document.createElement('div');
jobDiv.className = 'job-card';
jobDiv.innerHTML = `<strong>${job.title}</strong> at <em>${job.companyName}</em><br>📍 ${job.location}<br><a href="${job.link}" target="_blank">View Job</a>`;
linkedinJobsDiv.appendChild(jobDiv);
});
} else {
linkedinJobsDiv.innerHTML = '<em>No LinkedIn jobs found.</em>';
}
// Naukri jobs
if (jobsData.naukri_jobs && jobsData.naukri_jobs.length) {
jobsData.naukri_jobs.forEach(job => {
const jobDiv = document.createElement('div');
jobDiv.className = 'job-card';
jobDiv.innerHTML = `<strong>${job.title}</strong> at <em>${job.companyName}</em><br>📍 ${job.location}<br><a href="${job.url}" target="_blank">View Job</a>`;
naukriJobsDiv.appendChild(jobDiv);
});
} else {
naukriJobsDiv.innerHTML = '<em>No Naukri jobs found.</em>';
}
jobsSection.classList.remove('hidden');
} catch (err) {
alert('Error fetching jobs: ' + err.message);
}
loading.classList.add('hidden');
getJobsBtn.disabled = false;
});
});