Delete templates
Browse files- templates/index.html +0 -60
- templates/quiz.html +0 -222
templates/index.html
DELETED
@@ -1,60 +0,0 @@
|
|
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.0">
|
6 |
-
<title>Generate Quiz</title>
|
7 |
-
<style>
|
8 |
-
body {
|
9 |
-
font-family: Arial, sans-serif;
|
10 |
-
background-color: #f0f0f0;
|
11 |
-
color: #333;
|
12 |
-
margin: 20px;
|
13 |
-
}
|
14 |
-
h2 {
|
15 |
-
background-color: #ffc107;
|
16 |
-
padding: 10px;
|
17 |
-
border-radius: 5px;
|
18 |
-
}
|
19 |
-
form {
|
20 |
-
background-color: #fff;
|
21 |
-
padding: 20px;
|
22 |
-
border-radius: 5px;
|
23 |
-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
24 |
-
margin-bottom: 20px;
|
25 |
-
}
|
26 |
-
label {
|
27 |
-
display: block;
|
28 |
-
margin-bottom: 10px;
|
29 |
-
}
|
30 |
-
textarea {
|
31 |
-
width: 100%;
|
32 |
-
padding: 10px;
|
33 |
-
border: 2px solid #ffc107;
|
34 |
-
border-radius: 4px;
|
35 |
-
resize: vertical;
|
36 |
-
min-height: 150px;
|
37 |
-
background-color: #f0f0f0;
|
38 |
-
}
|
39 |
-
input[type="submit"] {
|
40 |
-
background-color: #ffc107;
|
41 |
-
color: #333;
|
42 |
-
border: none;
|
43 |
-
padding: 10px 20px;
|
44 |
-
cursor: pointer;
|
45 |
-
border-radius: 4px;
|
46 |
-
}
|
47 |
-
input[type="submit"]:hover {
|
48 |
-
background-color: #ffca28;
|
49 |
-
}
|
50 |
-
</style>
|
51 |
-
</head>
|
52 |
-
<body>
|
53 |
-
<h2>Generate Quiz</h2>
|
54 |
-
<form action="/" method="post">
|
55 |
-
<label for="context">Context:</label><br>
|
56 |
-
<textarea id="context" name="context" rows="20" required></textarea><br><br>
|
57 |
-
<input type="submit" value="Generate Quiz">
|
58 |
-
</form>
|
59 |
-
</body>
|
60 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates/quiz.html
DELETED
@@ -1,222 +0,0 @@
|
|
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.0">
|
6 |
-
<title>Quiz Generator</title>
|
7 |
-
<style>
|
8 |
-
body {
|
9 |
-
font-family: Arial, sans-serif;
|
10 |
-
line-height: 1.6;
|
11 |
-
padding: 20px;
|
12 |
-
}
|
13 |
-
#app {
|
14 |
-
max-width: 800px;
|
15 |
-
margin: 0 auto;
|
16 |
-
}
|
17 |
-
button {
|
18 |
-
padding: 10px 20px;
|
19 |
-
background-color: #4CAF50;
|
20 |
-
color: white;
|
21 |
-
border: none;
|
22 |
-
cursor: pointer;
|
23 |
-
border-radius: 4px;
|
24 |
-
font-size: 14px;
|
25 |
-
}
|
26 |
-
button:hover {
|
27 |
-
background-color: #45a049;
|
28 |
-
}
|
29 |
-
.quiz-section {
|
30 |
-
margin-top: 20px;
|
31 |
-
}
|
32 |
-
.quiz-question {
|
33 |
-
margin-bottom: 20px;
|
34 |
-
border: 1px solid #ccc;
|
35 |
-
padding: 15px;
|
36 |
-
border-radius: 4px;
|
37 |
-
background-color: #f9f9f9;
|
38 |
-
}
|
39 |
-
.quiz-question strong {
|
40 |
-
font-weight: bold;
|
41 |
-
}
|
42 |
-
.quiz-answer {
|
43 |
-
margin-top: 10px;
|
44 |
-
font-style: italic;
|
45 |
-
display: none;
|
46 |
-
}
|
47 |
-
#submitQuiz {
|
48 |
-
display: none;
|
49 |
-
margin-top: 20px;
|
50 |
-
text-align: center;
|
51 |
-
}
|
52 |
-
</style>
|
53 |
-
</head>
|
54 |
-
<body>
|
55 |
-
<div id="app">
|
56 |
-
<div id="quizSection" class="quiz-section"></div>
|
57 |
-
|
58 |
-
<div id="submitQuiz">
|
59 |
-
<button onclick="submitQuiz()">Submit Quiz</button>
|
60 |
-
</div>
|
61 |
-
</div>
|
62 |
-
|
63 |
-
<script>
|
64 |
-
// Use the passed response JSON directly
|
65 |
-
let textWithAnswers = `{{ textWithAnswers|tojson|safe }}`;
|
66 |
-
window.onload = function() {
|
67 |
-
document.getElementById('quizText').value = textWithAnswers;
|
68 |
-
generateQuiz();
|
69 |
-
};
|
70 |
-
|
71 |
-
function handletext(text) {
|
72 |
-
let lines = text.split(/\n+/);
|
73 |
-
let filteredLines = [];
|
74 |
-
let questionCount = 0;
|
75 |
-
let answersAndExplanations = [];
|
76 |
-
|
77 |
-
lines.forEach(line => {
|
78 |
-
line = line.trim();
|
79 |
-
|
80 |
-
if (line.startsWith("Question:")) {
|
81 |
-
filteredLines.push(line);
|
82 |
-
questionCount++;
|
83 |
-
} else if (line.startsWith("Choices:")) {
|
84 |
-
filteredLines.push(line);
|
85 |
-
} else if (line.startsWith("Answer:")) {
|
86 |
-
let answer = line.split(":")[1].trim();
|
87 |
-
answersAndExplanations.push({ Answer: answer });
|
88 |
-
} else if (line.startsWith("Explanation:")) {
|
89 |
-
let explanation = line.split(":")[1].trim();
|
90 |
-
answersAndExplanations[answersAndExplanations.length - 1].Explanation = explanation;
|
91 |
-
} else if (line.match(/^[A-D]\)\s*/)) {
|
92 |
-
filteredLines.push(line);
|
93 |
-
} else if (line.startsWith(" ")) {
|
94 |
-
} else {
|
95 |
-
filteredLines.push(line);
|
96 |
-
}
|
97 |
-
});
|
98 |
-
|
99 |
-
let filteredText = filteredLines.join("\n");
|
100 |
-
|
101 |
-
console.log(filteredText);
|
102 |
-
|
103 |
-
return {
|
104 |
-
filteredText: filteredText,
|
105 |
-
answersAndExplanations: answersAndExplanations
|
106 |
-
};
|
107 |
-
}
|
108 |
-
|
109 |
-
function generateQuiz() {
|
110 |
-
let quizText = document.getElementById('quizText').value;
|
111 |
-
let { filteredText, answersAndExplanations } = handletext(quizText);
|
112 |
-
|
113 |
-
document.getElementById('inputSection').style.display = 'none';
|
114 |
-
|
115 |
-
let quizSection = document.getElementById('quizSection');
|
116 |
-
quizSection.innerHTML = '';
|
117 |
-
|
118 |
-
let questions = filteredText.split(/\d+\.\s+/).filter(q => q.trim() !== '');
|
119 |
-
|
120 |
-
questions.forEach((question, index) => {
|
121 |
-
let parts = question.split('Choices:');
|
122 |
-
let questionText = parts[0].replace('Question:', '').trim();
|
123 |
-
let choicesText = parts[1].trim();
|
124 |
-
|
125 |
-
let div = document.createElement('div');
|
126 |
-
div.className = 'quiz-question';
|
127 |
-
div.innerHTML = `<strong>${index + 1}: ${questionText}</strong>`;
|
128 |
-
|
129 |
-
let choices = choicesText.split(/\s*[A-D]\)\s*/).filter(choice => choice.trim() !== '');
|
130 |
-
let labels = choicesText.match(/\s*[A-D]\)\s*/g);
|
131 |
-
choices.forEach((choice, i) => {
|
132 |
-
let label = labels[i].trim().charAt(0);
|
133 |
-
|
134 |
-
let choiceDiv = document.createElement('div');
|
135 |
-
|
136 |
-
let input = document.createElement('input');
|
137 |
-
input.type = 'radio';
|
138 |
-
input.name = `question_${index + 1}`;
|
139 |
-
input.value = label;
|
140 |
-
input.id = `q${index + 1}_${label}`;
|
141 |
-
input.setAttribute('data-answered', 'false');
|
142 |
-
|
143 |
-
let choiceLabel = document.createElement('label');
|
144 |
-
choiceLabel.setAttribute('for', `q${index + 1}_${label}`);
|
145 |
-
choiceLabel.textContent = `${label}) ${choice}`;
|
146 |
-
|
147 |
-
choiceDiv.appendChild(input);
|
148 |
-
choiceDiv.appendChild(choiceLabel);
|
149 |
-
|
150 |
-
div.appendChild(choiceDiv);
|
151 |
-
|
152 |
-
input.addEventListener('change', function() {
|
153 |
-
input.setAttribute('data-answered', 'true');
|
154 |
-
});
|
155 |
-
});
|
156 |
-
|
157 |
-
let answerDiv = document.createElement('div');
|
158 |
-
answerDiv.className = 'quiz-answer';
|
159 |
-
answerDiv.style.display = 'none';
|
160 |
-
div.appendChild(answerDiv);
|
161 |
-
|
162 |
-
let explanationDiv = document.createElement('div');
|
163 |
-
explanationDiv.className = 'quiz-answer';
|
164 |
-
explanationDiv.style.display = 'none';
|
165 |
-
div.appendChild(explanationDiv);
|
166 |
-
|
167 |
-
quizSection.appendChild(div);
|
168 |
-
});
|
169 |
-
|
170 |
-
document.getElementById('submitQuiz').style.display = 'block';
|
171 |
-
}
|
172 |
-
|
173 |
-
function validateQuiz() {
|
174 |
-
let quizSection = document.getElementById('quizSection');
|
175 |
-
let questions = quizSection.getElementsByClassName('quiz-question');
|
176 |
-
|
177 |
-
for (let i = 0; i < questions.length; i++) {
|
178 |
-
let inputs = questions[i].querySelectorAll('input[type="radio"]');
|
179 |
-
let answered = false;
|
180 |
-
|
181 |
-
for (let j = 0; j < inputs.length; j++) {
|
182 |
-
if (inputs[j].checked) {
|
183 |
-
answered = true;
|
184 |
-
break;
|
185 |
-
}
|
186 |
-
}
|
187 |
-
|
188 |
-
if (!answered) {
|
189 |
-
return false;
|
190 |
-
}
|
191 |
-
}
|
192 |
-
|
193 |
-
return true;
|
194 |
-
}
|
195 |
-
|
196 |
-
function submitQuiz() {
|
197 |
-
if (!validateQuiz()) {
|
198 |
-
alert('Please answer all questions before submitting.');
|
199 |
-
return;
|
200 |
-
}
|
201 |
-
|
202 |
-
let quizSection = document.getElementById('quizSection');
|
203 |
-
let answerDivs = quizSection.getElementsByClassName('quiz-answer');
|
204 |
-
let quizText = document.getElementById('quizText').value;
|
205 |
-
let { filteredText, answersAndExplanations } = handletext(quizText);
|
206 |
-
|
207 |
-
for (let i = 0; i < answerDivs.length; i += 2) {
|
208 |
-
let answer = answersAndExplanations[i / 2]?.Answer || '';
|
209 |
-
let explanation = answersAndExplanations[i / 2]?.Explanation || '';
|
210 |
-
|
211 |
-
answerDivs[i].style.display = 'block';
|
212 |
-
answerDivs[i].innerHTML = `Answer: ${answer}`;
|
213 |
-
|
214 |
-
answerDivs[i + 1].style.display = 'block';
|
215 |
-
answerDivs[i + 1].innerHTML = `Explanation: ${explanation}`;
|
216 |
-
}
|
217 |
-
|
218 |
-
document.getElementById('submitQuiz').style.display = 'none';
|
219 |
-
}
|
220 |
-
</script>
|
221 |
-
</body>
|
222 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|