Spaces:
Runtime error
Runtime error
using global var
Browse files
ice_breaking_challenge/__init__.py
CHANGED
|
@@ -6,6 +6,8 @@ from ice_breaking_challenge.models.model_loader import load_model_with_lora
|
|
| 6 |
from ice_breaking_challenge.google_sheets import load_google_sheets
|
| 7 |
|
| 8 |
model = None
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def create_app(test_config=None):
|
| 11 |
"""Create and configure an instance of the Flask application."""
|
|
|
|
| 6 |
from ice_breaking_challenge.google_sheets import load_google_sheets
|
| 7 |
|
| 8 |
model = None
|
| 9 |
+
quiz_generated = dict
|
| 10 |
+
quiz_results = dict
|
| 11 |
|
| 12 |
def create_app(test_config=None):
|
| 13 |
"""Create and configure an instance of the Flask application."""
|
ice_breaking_challenge/background_task.py
CHANGED
|
@@ -1,22 +1,15 @@
|
|
| 1 |
from flask import session
|
| 2 |
import time
|
| 3 |
import random
|
| 4 |
-
from ice_breaking_challenge import model
|
| 5 |
|
| 6 |
-
def background_task():
|
| 7 |
"""Session์ ์ ์ฅ๋ ์๋ต์ ๋ฐํ์ผ๋ก Gemma ๋ชจ๋ธ์ ์ฌ์ฉํ ํด์ฆ ์์ฑ"""
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
data = session.get('questions_and_answers', [])
|
| 12 |
-
if not data:
|
| 13 |
-
print("No data found in session.")
|
| 14 |
-
return
|
| 15 |
-
|
| 16 |
-
generated_quizzes = generate_quiz(data)
|
| 17 |
-
session['generated_quizzes'] = generated_quizzes
|
| 18 |
# ํด์ฆ ์์ฑ ์๋ฃ
|
| 19 |
-
|
| 20 |
|
| 21 |
def generate_quiz(data):
|
| 22 |
global model
|
|
|
|
| 1 |
from flask import session
|
| 2 |
import time
|
| 3 |
import random
|
| 4 |
+
from ice_breaking_challenge import model, quiz_generated, quiz_results
|
| 5 |
|
| 6 |
+
def background_task(sid, qna):
|
| 7 |
"""Session์ ์ ์ฅ๋ ์๋ต์ ๋ฐํ์ผ๋ก Gemma ๋ชจ๋ธ์ ์ฌ์ฉํ ํด์ฆ ์์ฑ"""
|
| 8 |
+
quiz_generated[sid] = False
|
| 9 |
+
generated_quizzes = generate_quiz(qna)
|
| 10 |
+
quiz_results[sid] = generated_quizzes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# ํด์ฆ ์์ฑ ์๋ฃ
|
| 12 |
+
quiz_generated[sid] = True
|
| 13 |
|
| 14 |
def generate_quiz(data):
|
| 15 |
global model
|
ice_breaking_challenge/google_sheets.py
CHANGED
|
@@ -78,4 +78,4 @@ def get_questions_and_answers() -> list[list[str]]:
|
|
| 78 |
for question, answer in zip(questions, answers):
|
| 79 |
questions_and_answers.append([question, answer])
|
| 80 |
|
| 81 |
-
|
|
|
|
| 78 |
for question, answer in zip(questions, answers):
|
| 79 |
questions_and_answers.append([question, answer])
|
| 80 |
|
| 81 |
+
return questions_and_answers
|
ice_breaking_challenge/qr.py
CHANGED
|
@@ -34,8 +34,8 @@ def qr() -> None:
|
|
| 34 |
flash("ํด๋น ํ ๋ฒํธ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค.")
|
| 35 |
return render_template("index.html")
|
| 36 |
if counter[session.get("team_number")] == session["team_size"]:
|
| 37 |
-
get_questions_and_answers()
|
| 38 |
-
Thread(target=background_task).start()
|
| 39 |
return render_template("introduction.html")
|
| 40 |
else:
|
| 41 |
flash("์ค๋ฌธ์ ์๋ฃํ์ง ์์ ํ์์ด ์์ต๋๋ค.")
|
|
|
|
| 34 |
flash("ํด๋น ํ ๋ฒํธ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค.")
|
| 35 |
return render_template("index.html")
|
| 36 |
if counter[session.get("team_number")] == session["team_size"]:
|
| 37 |
+
qna = get_questions_and_answers()
|
| 38 |
+
Thread(target=background_task, args=(session.sid, qna)).start()
|
| 39 |
return render_template("introduction.html")
|
| 40 |
else:
|
| 41 |
flash("์ค๋ฌธ์ ์๋ฃํ์ง ์์ ํ์์ด ์์ต๋๋ค.")
|
ice_breaking_challenge/quiz.py
CHANGED
|
@@ -1,11 +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.
|
| 9 |
return render_template("quiz.html", quizzes=quizzes, length=len(quizzes))
|
| 10 |
|
| 11 |
@bp.route("/finish", methods=["GET"])
|
|
|
|
| 1 |
from flask import Blueprint, render_template, session
|
| 2 |
|
| 3 |
+
from ice_breaking_challenge import quiz_results
|
| 4 |
+
|
| 5 |
bp = Blueprint("quiz", __name__, url_prefix="/quiz")
|
| 6 |
|
| 7 |
@bp.route("/", methods=["GET"])
|
| 8 |
def quiz():
|
| 9 |
"""quiz"""
|
| 10 |
+
quizzes = quiz_results[session.sid]
|
| 11 |
return render_template("quiz.html", quizzes=quizzes, length=len(quizzes))
|
| 12 |
|
| 13 |
@bp.route("/finish", methods=["GET"])
|
ice_breaking_challenge/templates/quiz.html
CHANGED
|
@@ -7,15 +7,15 @@
|
|
| 7 |
<ul>
|
| 8 |
{% for quiz in quizzes %}
|
| 9 |
<li>
|
| 10 |
-
<h2>๋ฌธ์ ์ฃผ์ธ: {{ quiz[
|
| 11 |
-
<h3>์ง๋ฌธ: {{ quiz[
|
| 12 |
<ul>
|
| 13 |
-
{% for option in quiz[
|
| 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[
|
| 19 |
</li>
|
| 20 |
{% endfor %}
|
| 21 |
</ul>
|
|
|
|
| 7 |
<ul>
|
| 8 |
{% for quiz in quizzes %}
|
| 9 |
<li>
|
| 10 |
+
<h2>๋ฌธ์ ์ฃผ์ธ: {{ quiz[3] }}</h2> <!-- ์ด๋ฆ ๋ถ๋ถ -->
|
| 11 |
+
<h3>์ง๋ฌธ: {{ quiz[0] }}</h3> <!-- ์ง๋ฌธ ๋ถ๋ถ -->
|
| 12 |
<ul>
|
| 13 |
+
{% for option in quiz[1] %} <!-- 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[2] }}</p> <!-- ์ ๋ต -->
|
| 19 |
</li>
|
| 20 |
{% endfor %}
|
| 21 |
</ul>
|
ice_breaking_challenge/topic.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from flask import Blueprint, render_template, redirect, url_for
|
| 2 |
from flask import session
|
| 3 |
import random
|
|
|
|
| 4 |
|
| 5 |
import time
|
| 6 |
|
|
@@ -11,7 +12,7 @@ topics = ["๋ฐ๋ง ๋ชจ๋๋ฅผ ํด๋ณด์๋ ๊ฑด ์ด๋ ์ธ์?", "์ค๋ ๋ฎ์ ํ
|
|
| 11 |
|
| 12 |
@bp.route("/", methods=["GET"])
|
| 13 |
def topic() -> None:
|
| 14 |
-
if session.
|
| 15 |
return redirect(url_for("quiz.quiz"))
|
| 16 |
else:
|
| 17 |
selected_topic = random.choice(topics)
|
|
|
|
| 1 |
from flask import Blueprint, render_template, redirect, url_for
|
| 2 |
from flask import session
|
| 3 |
import random
|
| 4 |
+
from ice_breaking_challenge import quiz_generated
|
| 5 |
|
| 6 |
import time
|
| 7 |
|
|
|
|
| 12 |
|
| 13 |
@bp.route("/", methods=["GET"])
|
| 14 |
def topic() -> None:
|
| 15 |
+
if quiz_generated[session.sid]:
|
| 16 |
return redirect(url_for("quiz.quiz"))
|
| 17 |
else:
|
| 18 |
selected_topic = random.choice(topics)
|