from flask import session import time import random from ice_breaking_challenge import model, quiz_generated, quiz_results def background_task(sid, qna): """Session에 저장된 응답을 바탕으로 Gemma 모델을 사용한 퀴즈 생성""" quiz_generated[sid] = False generated_quizzes = generate_quiz(qna) quiz_results[sid] = generated_quizzes # 퀴즈 생성 완료 quiz_generated[sid] = True def generate_quiz(data): global model generated_quizzes = [] selected_data = random.sample(data, min(10, len(data))) template_input=""" Using the text: {question} {answer}, create a new multiple-choice question with 4 answer options. """ for row in selected_data: question, answer, name = row input_text = template_input.format(question=question, answer=answer) response = model.generate(input_text, max_length=512) lines = response.split('\n') index = lines.index('') question_generated = lines[index+1] multiple_choice_generated = lines[index + 2] answer_generated = lines[index + 3] generated_quizzes.append([question_generated, multiple_choice_generated, answer_generated]) return generated_quizzes