Spaces:
Runtime error
Runtime error
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=""" | |
<instruction> | |
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('<response>') | |
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 | |