Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,23 +73,26 @@ def generate_question_with_chatgpt(context, topic):
|
|
| 73 |
print("API Response:", result) # Print the API response for debugging
|
| 74 |
|
| 75 |
# Modify the logic based on the actual structure of the 'result'
|
| 76 |
-
if 'choices' in result
|
| 77 |
-
|
| 78 |
-
if
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
return generated_question
|
| 91 |
|
| 92 |
|
|
|
|
| 93 |
def main():
|
| 94 |
# Title of the Application
|
| 95 |
st.header("🤖CB Quiz Generator🧠", divider='rainbow')
|
|
|
|
| 73 |
print("API Response:", result) # Print the API response for debugging
|
| 74 |
|
| 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:
|
| 79 |
+
choice = choices[0]
|
| 80 |
+
if 'message' in choice and isinstance(choice['message'], dict):
|
| 81 |
+
message = choice['message']
|
| 82 |
+
content = message.get('content')
|
| 83 |
+
|
| 84 |
+
if content:
|
| 85 |
+
options = message.get('options', [])
|
| 86 |
+
correct_answer = message.get('correct_answer', "Unknown")
|
| 87 |
+
|
| 88 |
+
generated_question['content'] = content
|
| 89 |
+
generated_question['options'] = options if isinstance(options, list) else []
|
| 90 |
+
generated_question['correct_answer'] = correct_answer
|
| 91 |
|
| 92 |
return generated_question
|
| 93 |
|
| 94 |
|
| 95 |
+
|
| 96 |
def main():
|
| 97 |
# Title of the Application
|
| 98 |
st.header("🤖CB Quiz Generator🧠", divider='rainbow')
|