yunzi7 commited on
Commit
d8529e7
โ€ข
1 Parent(s): 53ce00a

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
- 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
 
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
- session['questions_and_answers'] = questions_and_answers
 
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.get("generated_quizzes", [])
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[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>
 
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.get("quiz_generated"):
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)