Spaces:
Runtime error
Runtime error
add quiz
Browse files
ice_breaking_challenge/background_task.py
CHANGED
@@ -29,11 +29,13 @@ def generate_quiz(data):
|
|
29 |
Using the text: {question} {answer}, create a new multiple-choice question with 4 answer options.
|
30 |
"""
|
31 |
for row in selected_data:
|
32 |
-
question, answer = row
|
33 |
|
34 |
input_text = template_input.format(question=question, answer=answer)
|
35 |
|
36 |
response = model.generate(input_text, max_length=512)
|
|
|
|
|
37 |
|
38 |
generated_quizzes.append(response)
|
39 |
|
|
|
29 |
Using the text: {question} {answer}, create a new multiple-choice question with 4 answer options.
|
30 |
"""
|
31 |
for row in selected_data:
|
32 |
+
question, answer, name = row
|
33 |
|
34 |
input_text = template_input.format(question=question, answer=answer)
|
35 |
|
36 |
response = model.generate(input_text, max_length=512)
|
37 |
+
# parsing response
|
38 |
+
# name + parsed response
|
39 |
|
40 |
generated_quizzes.append(response)
|
41 |
|
ice_breaking_challenge/quiz.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Blueprint, render_template, session
|
2 |
+
|
3 |
+
bp = Blueprint("quiz", __name__, url_prefix="/quiz")
|
4 |
+
|
5 |
+
@bp.route("/", methods=["GET"])
|
6 |
+
def quiz():
|
7 |
+
"""quiz"""
|
8 |
+
quizzes = session.get("generated_quizzes", [])
|
9 |
+
return render_template("quiz.html", quizzes=quizzes, length=len(quizzes))
|
10 |
+
|
11 |
+
@bp.route("/finish", methods=["GET"])
|
12 |
+
def finish():
|
13 |
+
return render_template("finish.html")
|
ice_breaking_challenge/templates/finish.html
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends 'base.html' %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
<h1>ํด์ฆ๊ฐ ๋๋ฌ์ต๋๋ค!</h1>
|
5 |
+
<p>์ฆ๊ฑฐ์ฐ์
จ๋์? ๋ง์ด ์นํด์ง์
จ๋์? ๊ฐ์ฌํฉ๋๋ค!</p>
|
6 |
+
<p>์ฐธ์ฌํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. ์์ผ๋ก๋ ์ข์ ์๊ฐ ๋์ธ์!</p>
|
7 |
+
{% endblock %}
|
ice_breaking_challenge/templates/quiz.html
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{% extends 'base.html' %}
|
2 |
+
|
3 |
+
{% block content %}
|
4 |
+
<h1>ํด์ฆ ์์ฑ ๊ฒฐ๊ณผ</h1>
|
5 |
+
|
6 |
+
{% if quizzes %}
|
7 |
+
<ul>
|
8 |
+
{% for quiz in quizzes %}
|
9 |
+
<li>
|
10 |
+
<h2>๋ฌธ์ ์ฃผ์ธ: {{ quiz[0] }}</h2> <!-- ์ด๋ฆ ๋ถ๋ถ -->
|
11 |
+
<h3>์ง๋ฌธ: {{ quiz[1] }}</h3> <!-- ์ง๋ฌธ ๋ถ๋ถ -->
|
12 |
+
<ul>
|
13 |
+
{% for option in quiz[2] %} <!-- 4์ง์ ๋ค ๋ณด๊ธฐ -->
|
14 |
+
<li>{{ option }}</li>
|
15 |
+
{% endfor %}
|
16 |
+
</ul>
|
17 |
+
<button onclick="showAnswer('{{ loop.index0 }}')">์ ๋ต ๋ณด๊ธฐ</button>
|
18 |
+
<p id="answer-{{ loop.index0 }}" style="display: none;">์ ๋ต: {{ quiz[3] }}</p> <!-- ์ ๋ต -->
|
19 |
+
</li>
|
20 |
+
{% endfor %}
|
21 |
+
</ul>
|
22 |
+
{% else %}
|
23 |
+
<p>ํด์ฆ๊ฐ ์์ต๋๋ค. ๋ค์ ์๋ํด ์ฃผ์ธ์.</p>
|
24 |
+
{% endif %}
|
25 |
+
|
26 |
+
<script>
|
27 |
+
let currentQuizIndex = 0;
|
28 |
+
|
29 |
+
function showAnswer(index) {
|
30 |
+
const answer = document.getElementById(`answer-${index}`);
|
31 |
+
if (answer.style.display === "none") {
|
32 |
+
answer.style.display = "block";
|
33 |
+
} else {
|
34 |
+
answer.style.display = "none";
|
35 |
+
}
|
36 |
+
currentQuizIndex++;
|
37 |
+
|
38 |
+
// ํด์ฆ๋ฅผ ๋ชจ๋ ํ๊ณ ๋๋ฉด ๋ง๋ฌด๋ฆฌ ํ์ด์ง๋ก ์ด๋
|
39 |
+
if (currentQuizIndex === { length }) {
|
40 |
+
setTimeout(() => {
|
41 |
+
window.location.href = "{{ url_for('quiz.finish') }}";
|
42 |
+
}, 3000); // 3์ด ํ ์๋ ์ด๋
|
43 |
+
}
|
44 |
+
}
|
45 |
+
</script>
|
46 |
+
{% endblock %}
|
ice_breaking_challenge/templates/topic.html
CHANGED
@@ -1,43 +1,23 @@
|
|
1 |
-
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
6 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
-
<title>Random Topic Recommendation</title>
|
8 |
-
<style>
|
9 |
-
body {
|
10 |
-
display: flex;
|
11 |
-
justify-content: center;
|
12 |
-
align-items: center;
|
13 |
-
height: 100vh;
|
14 |
-
font-family: Arial, sans-serif;
|
15 |
-
}
|
16 |
-
h1 {
|
17 |
-
font-size: 2em;
|
18 |
-
color: #333;
|
19 |
-
}
|
20 |
-
</style>
|
21 |
-
</head>
|
22 |
-
<body>
|
23 |
-
<h1 id="topic">์ฃผ์ ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค</h1>
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
function updateTopic() {
|
28 |
-
fetch('/get_topic')
|
29 |
-
.then(response => response.json())
|
30 |
-
.then(data => {
|
31 |
-
document.getElementById('topic').textContent = data.topic;
|
32 |
-
})
|
33 |
-
.catch(error => console.error('Error fetching topic:', error));
|
34 |
-
}
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
1 |
+
{% extends 'base.html' %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
{% block content %}
|
4 |
+
<h1 id="topic">์ฃผ์ ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
<script>
|
7 |
+
// ์ฃผ์ ์
๋ฐ์ดํธ ํจ์
|
8 |
+
function updateTopic() {
|
9 |
+
fetch('/get_topic')
|
10 |
+
.then(response => response.json())
|
11 |
+
.then(data => {
|
12 |
+
document.getElementById('topic').textContent = data.topic;
|
13 |
+
})
|
14 |
+
.catch(error => console.error('Error fetching topic:', error));
|
15 |
+
}
|
16 |
|
17 |
+
// ํ์ด์ง๊ฐ ๋ก๋๋ ๋ ์ฃผ์ ์
๋ฐ์ดํธ
|
18 |
+
updateTopic();
|
19 |
+
|
20 |
+
// 20์ด๋ง๋ค ์ฃผ์ ์
๋ฐ์ดํธ
|
21 |
+
setInterval(updateTopic, 20000);
|
22 |
+
</script>
|
23 |
+
{% endblock %}
|
ice_breaking_challenge/topic.py
CHANGED
@@ -5,12 +5,14 @@ import random
|
|
5 |
import time
|
6 |
|
7 |
bp = Blueprint("topic", __name__, url_prefix="topic")
|
8 |
-
topics = ["
|
|
|
|
|
9 |
|
10 |
@bp.route("/", methods=["GET"])
|
11 |
def topic() -> None:
|
12 |
if session.get("quiz_generated"):
|
13 |
-
return redirect(url_for("quiz.
|
14 |
else:
|
15 |
selected_topic = random.choice(topics)
|
16 |
time.sleep(20) # 20์ด ๋๊ธฐ ํ ๋ค์ ์ฃผ์ ๋ก
|
|
|
5 |
import time
|
6 |
|
7 |
bp = Blueprint("topic", __name__, url_prefix="topic")
|
8 |
+
topics = ["๋ฐ๋ง ๋ชจ๋๋ฅผ ํด๋ณด์๋ ๊ฑด ์ด๋ ์ธ์?", "์ค๋ ๋ฎ์ ํ ์ผ์ ๊ณต์ ํด๋ณด์ธ์!", "์์นจํ ์ธ๊ฐ์ธ๊ฐ์, ์ ๋
ํ ์ธ๊ฐ์ธ๊ฐ์?",
|
9 |
+
"MBTI๊ฐ ๋ฌด์์ธ๊ฐ์? ๋ํํด๋ณด๋ฉฐ ๋ง์ถฐ๋ณด์ธ์!", "์๋ก์ ์ทจ๋ฏธ๋ฅผ ํ ๊ฐ์ง์ฉ ๊ณต์ ํด๋ณผ๊น์?", "๋์ด๋๊ฐ ์ด๋ป๊ฒ ๋์ธ์? ๋๊ฐ์ด ์๋์ง ์ฐพ์๋ณผ๊น์?",
|
10 |
+
"์๋ก ์ด๋ฆ ๋์ ๋๋ค์์ ํ๋ ์ ํด์ ๋ถ๋ฌ๋ณผ๊น์?"]
|
11 |
|
12 |
@bp.route("/", methods=["GET"])
|
13 |
def topic() -> None:
|
14 |
if session.get("quiz_generated"):
|
15 |
+
return redirect(url_for("quiz.quiz"))
|
16 |
else:
|
17 |
selected_topic = random.choice(topics)
|
18 |
time.sleep(20) # 20์ด ๋๊ธฐ ํ ๋ค์ ์ฃผ์ ๋ก
|