yunzi7 commited on
Commit
658dbbd
β€’
1 Parent(s): ec7b19d

background job

Browse files
ice_breaking_challenge/background_task.py CHANGED
@@ -1,2 +1,42 @@
 
 
 
 
 
1
  def background_task():
2
- "continue"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: