Rishabh12j commited on
Commit
bbdcfde
·
verified ·
1 Parent(s): 97c91d1

Create content_generator.py

Browse files
Files changed (1) hide show
  1. content_generator.py +30 -0
content_generator.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from models import Model
2
+ from prompt import Prompt
3
+
4
+ def generate_notes(transcript):
5
+ return Model.openai_chatgpt(transcript=transcript, prompt=Prompt.prompt1())
6
+
7
+ def generate_quiz(transcript):
8
+ raw_quiz = Model.openai_chatgpt(transcript, Prompt.prompt1(ID='quiz'))
9
+ return parse_quiz_content(raw_quiz)
10
+
11
+ def parse_quiz_content(raw_quiz):
12
+ quiz_content = []
13
+ questions = raw_quiz.strip().split("\n\n")
14
+
15
+ for question in questions:
16
+ lines = question.split("\n")
17
+ if len(lines) < 6: # Question + 4 options + correct answer
18
+ continue
19
+
20
+ question_text = lines[0].split(".", 1)[-1].strip()
21
+ options = [line.split(")", 1)[-1].strip() for line in lines[1:5]]
22
+ correct_answer = lines[-1].split(":")[-1].strip()
23
+
24
+ quiz_content.append({
25
+ "question": question_text,
26
+ "options": options,
27
+ "correct_answer": correct_answer
28
+ })
29
+
30
+ return quiz_content[:10] # Ensure we return at most 10 questions