Spaces:
Runtime error
Runtime error
background job
Browse files
ice_breaking_challenge/background_task.py
CHANGED
@@ -1,2 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
def background_task():
|
2 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
session["quiz_generated"] = False
|
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 |
+
session["quiz_generated"] = True
|
20 |
+
|
21 |
+
def generate_quiz(data):
|
22 |
+
global model
|
23 |
+
generated_quizzes = []
|
24 |
+
|
25 |
+
selected_data = random.sample(data, min(10, len(data)))
|
26 |
+
|
27 |
+
template_input="""
|
28 |
+
<instruction>
|
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 |
+
|
40 |
+
return generated_quizzes
|
41 |
+
|
42 |
+
|
ice_breaking_challenge/qr.py
CHANGED
@@ -14,7 +14,7 @@ from threading import Thread
|
|
14 |
|
15 |
from .auth import login_required
|
16 |
from .db import get_db
|
17 |
-
from ice_breaking_challenge.google_sheets import get_team_numbers
|
18 |
|
19 |
from background_task import background_task
|
20 |
|
@@ -34,6 +34,7 @@ def qr() -> None:
|
|
34 |
flash("ν΄λΉ ν λ²νΈκ° μ‘΄μ¬νμ§ μμ΅λλ€.")
|
35 |
return render_template("index.html")
|
36 |
if counter[session.get("team_number")] == session["team_size"]:
|
|
|
37 |
Thread(target=background_task).start()
|
38 |
return render_template("introduction.html")
|
39 |
else:
|
|
|
14 |
|
15 |
from .auth import login_required
|
16 |
from .db import get_db
|
17 |
+
from ice_breaking_challenge.google_sheets import get_team_numbers, get_questions_and_answers
|
18 |
|
19 |
from background_task import background_task
|
20 |
|
|
|
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:
|
ice_breaking_challenge/topic.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
from flask import Blueprint, render_template, redirect, url_for
|
|
|
2 |
import random
|
3 |
|
4 |
import time
|
5 |
|
6 |
bp = Blueprint("topic", __name__, url_prefix="topic")
|
7 |
-
topics = ["MBTI", ""]
|
8 |
|
9 |
@bp.route("/", methods=["GET"])
|
10 |
def topic() -> None:
|
|
|
1 |
from flask import Blueprint, render_template, redirect, url_for
|
2 |
+
from flask import session
|
3 |
import random
|
4 |
|
5 |
import time
|
6 |
|
7 |
bp = Blueprint("topic", __name__, url_prefix="topic")
|
8 |
+
topics = ["MBTI", "μ§μ
"]
|
9 |
|
10 |
@bp.route("/", methods=["GET"])
|
11 |
def topic() -> None:
|