Rathapoom commited on
Commit
e3da1c7
1 Parent(s): a9150c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -9,12 +9,14 @@ openai.api_key = st.secrets["OPENAI_API_KEY"]
9
  client = openai.OpenAI(api_key=openai.api_key)
10
 
11
  # Function to generate exam questions using OpenAI API with retry logic
12
- def generate_questions_with_retry(knowledge_material, question_type, cognitive_level, extra_instructions, case_based, max_retries=3):
13
  # Adjust the number of questions based on the type
14
  if question_type == "Multiple Choice":
15
  num_questions = 3
16
  elif question_type == "Fill in the Blank":
17
  num_questions = 10
 
 
18
  else: # Open-ended
19
  num_questions = 3
20
 
@@ -27,9 +29,11 @@ def generate_questions_with_retry(knowledge_material, question_type, cognitive_l
27
  if question_type != "Fill in the Blank":
28
  prompt += " Provide answers with short explanations."
29
 
30
- else:
31
- if question_type != "Fill in the Blank":
32
- prompt += " Provide answers with short explanations."
 
 
33
 
34
  retries = 0
35
  while retries < max_retries:
@@ -84,7 +88,12 @@ else:
84
 
85
  # Select question type
86
  question_type = st.selectbox("Select question type:",
87
- ["Multiple Choice", "Fill in the Blank", "Open-ended"])
 
 
 
 
 
88
 
89
  # Select cognitive level
90
  cognitive_level = st.selectbox("Select cognitive level:",
@@ -108,7 +117,8 @@ else:
108
  question_type,
109
  cognitive_level,
110
  extra_instructions,
111
- case_based
 
112
  )
113
 
114
  if questions:
@@ -137,7 +147,8 @@ else:
137
  question_type,
138
  cognitive_level,
139
  extra_instructions,
140
- case_based
 
141
  )
142
 
143
  # Check if the new set of questions is not the same as the previous set
 
9
  client = openai.OpenAI(api_key=openai.api_key)
10
 
11
  # Function to generate exam questions using OpenAI API with retry logic
12
+ def generate_questions_with_retry(knowledge_material, question_type, cognitive_level, extra_instructions, case_based, num_choices=None, max_retries=3):
13
  # Adjust the number of questions based on the type
14
  if question_type == "Multiple Choice":
15
  num_questions = 3
16
  elif question_type == "Fill in the Blank":
17
  num_questions = 10
18
+ elif question_type == "True/False":
19
+ num_questions = 5
20
  else: # Open-ended
21
  num_questions = 3
22
 
 
29
  if question_type != "Fill in the Blank":
30
  prompt += " Provide answers with short explanations."
31
 
32
+ if question_type == "Multiple Choice" and num_choices:
33
+ prompt += f" Each multiple choice question should have {num_choices} choices."
34
+
35
+ if question_type == "True/False":
36
+ prompt += " Generate True/False questions based on the provided material."
37
 
38
  retries = 0
39
  while retries < max_retries:
 
88
 
89
  # Select question type
90
  question_type = st.selectbox("Select question type:",
91
+ ["Multiple Choice", "Fill in the Blank", "Open-ended", "True/False"])
92
+
93
+ # For multiple choice, let users select the number of choices
94
+ num_choices = None
95
+ if question_type == "Multiple Choice":
96
+ num_choices = st.selectbox("Select the number of choices for each question:", [3, 4, 5])
97
 
98
  # Select cognitive level
99
  cognitive_level = st.selectbox("Select cognitive level:",
 
117
  question_type,
118
  cognitive_level,
119
  extra_instructions,
120
+ case_based,
121
+ num_choices
122
  )
123
 
124
  if questions:
 
147
  question_type,
148
  cognitive_level,
149
  extra_instructions,
150
+ case_based,
151
+ num_choices
152
  )
153
 
154
  # Check if the new set of questions is not the same as the previous set