Spaces:
Runtime error
Runtime error
File size: 1,307 Bytes
658dbbd d8529e7 658dbbd d8529e7 658dbbd d8529e7 658dbbd d8529e7 658dbbd 53ce00a 658dbbd 7ff0925 658dbbd 7ff0925 658dbbd 7ff0925 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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
|