Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -75,19 +75,21 @@ def generate_question_with_chatgpt(context, topic):
|
|
75 |
# Modify the logic based on the actual structure of the 'result'
|
76 |
if 'choices' in result:
|
77 |
choices = result['choices']
|
78 |
-
if
|
79 |
-
message
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
|
88 |
return generated_question
|
89 |
|
90 |
|
|
|
91 |
def main():
|
92 |
# Title of the Application
|
93 |
st.header("🤖CB Quiz Generator🧠", divider='rainbow')
|
|
|
75 |
# Modify the logic based on the actual structure of the 'result'
|
76 |
if 'choices' in result:
|
77 |
choices = result['choices']
|
78 |
+
if isinstance(choices, list) and choices: # Check if 'choices' is a non-empty list
|
79 |
+
if 'message' in choices[0]:
|
80 |
+
message = choices[0]['message']
|
81 |
+
content = message.get('content', "Unable to generate a question..")
|
82 |
+
options = message.get('options', [])
|
83 |
+
correct_answer = message.get('correct_answer', "Unknown")
|
84 |
|
85 |
+
generated_question['content'] = content
|
86 |
+
generated_question['options'] = options
|
87 |
+
generated_question['correct_answer'] = correct_answer
|
88 |
|
89 |
return generated_question
|
90 |
|
91 |
|
92 |
+
|
93 |
def main():
|
94 |
# Title of the Application
|
95 |
st.header("🤖CB Quiz Generator🧠", divider='rainbow')
|