mohammed3536 commited on
Commit
95a7b2d
·
verified ·
1 Parent(s): 17acf5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
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 choices and isinstance(choices, list):
79
- message = choices[0].get('message', {})
80
- content = message.get('content', "Unable to generate a question..")
81
- options = message.get('options', [])
82
- correct_answer = message.get('correct_answer', "Unknown")
 
83
 
84
- generated_question['content'] = content
85
- generated_question['options'] = options
86
- generated_question['correct_answer'] = correct_answer
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')