Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- static/index.html +45 -0
- static/main.js +149 -0
static/index.html
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
6 |
+
<title>Career Capability Checker</title>
|
7 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
|
8 |
+
<link rel="stylesheet" href="/static/styles.css">
|
9 |
+
<script src="/static/main.js" defer></script>
|
10 |
+
</head>
|
11 |
+
<body class="bg-light">
|
12 |
+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
13 |
+
<div class="container-fluid">
|
14 |
+
<a class="navbar-brand" href="/">CareerPath</a>
|
15 |
+
</div>
|
16 |
+
</nav>
|
17 |
+
<div class="container py-4">
|
18 |
+
<div id="app">
|
19 |
+
<div id="form-container">
|
20 |
+
<div class="card">
|
21 |
+
<div class="card-body">
|
22 |
+
<h2 class="card-title text-center"><i class="bi bi-compass"></i> Determine Your Path</h2>
|
23 |
+
<p class="text-muted text-center">Enter your desired career and qualifications</p>
|
24 |
+
<form id="start-form" class="row g-3">
|
25 |
+
<div class="col-12">
|
26 |
+
<label for="career" class="form-label">Desired Career</label>
|
27 |
+
<input type="text" class="form-control" id="career" name="career" required>
|
28 |
+
</div>
|
29 |
+
<div class="col-12">
|
30 |
+
<label for="qualifications" class="form-label">Current Qualifications</label>
|
31 |
+
<textarea class="form-control" id="qualifications" name="qualifications" rows="3" required></textarea>
|
32 |
+
</div>
|
33 |
+
<div class="col-12 text-center">
|
34 |
+
<button type="submit" class="btn btn-success btn-lg">Next Step <i class="bi bi-arrow-right"></i></button>
|
35 |
+
</div>
|
36 |
+
</form>
|
37 |
+
</div>
|
38 |
+
</div>
|
39 |
+
</div>
|
40 |
+
<div id="questions-container" style="display:none;"></div>
|
41 |
+
<div id="result-container" style="display:none;"></div>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
</body>
|
45 |
+
</html>
|
static/main.js
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
document.addEventListener("DOMContentLoaded", () => {
|
2 |
+
const formContainer = document.getElementById("form-container");
|
3 |
+
const questionsContainer = document.getElementById("questions-container");
|
4 |
+
const resultContainer = document.getElementById("result-container");
|
5 |
+
|
6 |
+
let career = "";
|
7 |
+
let qualifications = "";
|
8 |
+
let questions = [];
|
9 |
+
|
10 |
+
// Handle form submission
|
11 |
+
document.getElementById("start-form").addEventListener("submit", async (e) => {
|
12 |
+
e.preventDefault();
|
13 |
+
career = document.getElementById("career").value;
|
14 |
+
qualifications = document.getElementById("qualifications").value;
|
15 |
+
|
16 |
+
// Fetch questions from the server
|
17 |
+
const response = await fetch("/start", {
|
18 |
+
method: "POST",
|
19 |
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
20 |
+
body: new URLSearchParams({ career, qualifications }),
|
21 |
+
});
|
22 |
+
const data = await response.json();
|
23 |
+
questions = data.questions; // Save questions for later
|
24 |
+
renderQuestions(questions);
|
25 |
+
});
|
26 |
+
|
27 |
+
function renderQuestions(questions) {
|
28 |
+
formContainer.style.display = "none";
|
29 |
+
questionsContainer.style.display = "block";
|
30 |
+
resultContainer.style.display = "none";
|
31 |
+
|
32 |
+
questionsContainer.innerHTML = `
|
33 |
+
<h2 class="text-center"><i class="bi bi-question-circle"></i> Psychological Assessment</h2>
|
34 |
+
<form id="questions-form">
|
35 |
+
${questions
|
36 |
+
.map(
|
37 |
+
(q, idx) => `
|
38 |
+
<div class="mb-4">
|
39 |
+
<p><strong id="question_${idx}">Q${idx + 1}: ${q.question}</strong></p>
|
40 |
+
${Object.entries(q.choices)
|
41 |
+
.map(
|
42 |
+
([key, value]) => `
|
43 |
+
<div class="form-check">
|
44 |
+
<input type="radio" name="q_${idx}" value="${value}" id="q_${idx}_${key}" required>
|
45 |
+
<label for="q_${idx}_${key}">${value}</label>
|
46 |
+
</div>
|
47 |
+
`
|
48 |
+
)
|
49 |
+
.join("")}
|
50 |
+
</div>
|
51 |
+
`
|
52 |
+
)
|
53 |
+
.join("")}
|
54 |
+
<div class="text-center">
|
55 |
+
<button type="submit" class="btn btn-primary btn-lg">Submit <i class="bi bi-check-circle"></i></button>
|
56 |
+
</div>
|
57 |
+
</form>
|
58 |
+
`;
|
59 |
+
|
60 |
+
document.getElementById("questions-form").addEventListener("submit", handleQuestionsSubmit);
|
61 |
+
}
|
62 |
+
|
63 |
+
async function handleQuestionsSubmit(e) {
|
64 |
+
e.preventDefault();
|
65 |
+
const formData = new FormData(e.target);
|
66 |
+
const answers = [];
|
67 |
+
|
68 |
+
for (let idx = 0; idx < questions.length; idx++) {
|
69 |
+
const questionText = questions[idx].question;
|
70 |
+
const selectedAnswerText = formData.get(`q_${idx}`); // Get the selected answer text
|
71 |
+
if (selectedAnswerText) {
|
72 |
+
answers.push({
|
73 |
+
question: questionText,
|
74 |
+
answer: selectedAnswerText,
|
75 |
+
});
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
// Send the full payload with career, qualifications, and answers
|
80 |
+
const payload = {
|
81 |
+
career,
|
82 |
+
qualifications,
|
83 |
+
answers,
|
84 |
+
};
|
85 |
+
|
86 |
+
const response = await fetch("/evaluate", {
|
87 |
+
method: "POST",
|
88 |
+
headers: { "Content-Type": "application/json" },
|
89 |
+
body: JSON.stringify(payload),
|
90 |
+
});
|
91 |
+
const data = await response.json();
|
92 |
+
|
93 |
+
// Render results
|
94 |
+
renderResult(data.result);
|
95 |
+
}
|
96 |
+
|
97 |
+
function renderResult(result) {
|
98 |
+
const { capable, roadmap, evaluation_report, motivation, alternatives } = result;
|
99 |
+
|
100 |
+
formContainer.style.display = "none";
|
101 |
+
questionsContainer.style.display = "none";
|
102 |
+
resultContainer.style.display = "block";
|
103 |
+
|
104 |
+
// Capable or Not
|
105 |
+
const header = `
|
106 |
+
<h2 class="text-center text-${capable ? "success" : "danger"}">
|
107 |
+
${capable ? "You Are Capable!" : "Consider Alternatives"}
|
108 |
+
</h2>
|
109 |
+
`;
|
110 |
+
|
111 |
+
// Evaluation Report and Motivation
|
112 |
+
const evaluationReport = `
|
113 |
+
<h3>Evaluation Report</h3>
|
114 |
+
<p>${evaluation_report || "No evaluation report provided."}</p>
|
115 |
+
<h3>Motivation</h3>
|
116 |
+
<p>${motivation || "No motivational message provided."}</p>
|
117 |
+
`;
|
118 |
+
|
119 |
+
// Roadmap (only if capable is true)
|
120 |
+
const roadmapSection = capable && roadmap
|
121 |
+
? `
|
122 |
+
<h3>Roadmap</h3>
|
123 |
+
<ul>${roadmap.map((step) => `<li>${step}</li>`).join("")}</ul>
|
124 |
+
`
|
125 |
+
: "";
|
126 |
+
|
127 |
+
// Alternatives (only if capable is false)
|
128 |
+
const alternativesSection = !capable && alternatives
|
129 |
+
? `
|
130 |
+
<h3>Alternative Careers</h3>
|
131 |
+
<ul>${alternatives.map((alt) => `<li>${alt}</li>`).join("")}</ul>
|
132 |
+
`
|
133 |
+
: capable
|
134 |
+
? ""
|
135 |
+
: "<p>No alternatives provided.</p>";
|
136 |
+
|
137 |
+
resultContainer.innerHTML = `
|
138 |
+
${header}
|
139 |
+
${evaluationReport}
|
140 |
+
${roadmapSection}
|
141 |
+
${alternativesSection}
|
142 |
+
<div class="text-center mt-4">
|
143 |
+
<button onclick="location.reload()" class="btn btn-secondary">Restart</button>
|
144 |
+
</div>
|
145 |
+
`;
|
146 |
+
}
|
147 |
+
|
148 |
+
});
|
149 |
+
|