Spaces:
Running
Running
Update quiz_generation.py
Browse files- quiz_generation.py +0 -78
quiz_generation.py
CHANGED
@@ -29,84 +29,6 @@ def generate_quiz_questions(prompt):
|
|
29 |
|
30 |
return quiz
|
31 |
|
32 |
-
'''
|
33 |
-
def generate_quiz_url(prompt_text, form_service):
|
34 |
-
# Generate quiz questions based on the transcribed text
|
35 |
-
text = generate_quiz_questions(prompt_text)
|
36 |
-
|
37 |
-
# Questions, choices, and correct answers
|
38 |
-
questions = re.findall(r"🔹 (.*?)\n", text)
|
39 |
-
choices = re.findall(r"🔸 (.*?)\n", text)
|
40 |
-
answers = re.findall(r"✔️ (.*?)\n", text)
|
41 |
-
|
42 |
-
# Remove the '**' from the questions list (they are not part of the question), choices, and correct answers
|
43 |
-
questions = [question.replace('**', '') for question in questions]
|
44 |
-
answers = [answer.replace('**', '') for answer in answers]
|
45 |
-
|
46 |
-
questions_list = []
|
47 |
-
|
48 |
-
# Fill the questions_list variable
|
49 |
-
for i, question in enumerate(questions):
|
50 |
-
choices_for_question = choices[i * 4:(i + 1) * 4]
|
51 |
-
correct_answer = answers[i] if i < len(answers) else ""
|
52 |
-
|
53 |
-
question_dict = {
|
54 |
-
"question": question,
|
55 |
-
"choices": choices_for_question,
|
56 |
-
"correct_answer": correct_answer
|
57 |
-
}
|
58 |
-
|
59 |
-
questions_list.append(question_dict)
|
60 |
-
|
61 |
-
# Create the initial form
|
62 |
-
result = form_service.forms().create(body=NEW_FORM).execute()
|
63 |
-
|
64 |
-
# Add the questions to the form
|
65 |
-
question_requests = []
|
66 |
-
for index, question in enumerate(questions_list):
|
67 |
-
new_question = {
|
68 |
-
"createItem": {
|
69 |
-
"item": {
|
70 |
-
"title": question["question"],
|
71 |
-
"questionItem": {
|
72 |
-
"question": {
|
73 |
-
"required": True,
|
74 |
-
"choiceQuestion": {
|
75 |
-
"type": "RADIO",
|
76 |
-
"options": [
|
77 |
-
{"value": choice} for choice in question["choices"]
|
78 |
-
],
|
79 |
-
"shuffle": True
|
80 |
-
}
|
81 |
-
}
|
82 |
-
}
|
83 |
-
},
|
84 |
-
"location": {
|
85 |
-
"index": index
|
86 |
-
}
|
87 |
-
}
|
88 |
-
}
|
89 |
-
question_requests.append(new_question)
|
90 |
-
|
91 |
-
NEW_QUESTIONS = {
|
92 |
-
"requests": question_requests
|
93 |
-
}
|
94 |
-
|
95 |
-
question_setting = form_service.forms().batchUpdate(formId=result["formId"], body=NEW_QUESTIONS).execute()
|
96 |
-
|
97 |
-
# Retrieve the updated form result
|
98 |
-
get_result = form_service.forms().get(formId=result["formId"]).execute()
|
99 |
-
|
100 |
-
# Get the form ID
|
101 |
-
form_id = get_result["formId"]
|
102 |
-
|
103 |
-
# Construct the quiz link using the form ID
|
104 |
-
form_url = result["responderUri"]
|
105 |
-
|
106 |
-
return form_url
|
107 |
-
'''
|
108 |
-
|
109 |
-
|
110 |
|
111 |
def generate_quiz_url(prompt_text, form_service):
|
112 |
# Generate quiz questions based on the transcribed text
|
|
|
29 |
|
30 |
return quiz
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def generate_quiz_url(prompt_text, form_service):
|
34 |
# Generate quiz questions based on the transcribed text
|