mohammed3536 commited on
Commit
2e46dd2
1 Parent(s): 51b662a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -42,7 +42,11 @@ def generate_question_with_chatgpt(context):
42
  }
43
 
44
  # Initializing the default value
45
- generated_question = "Unable to generate a question.."
 
 
 
 
46
 
47
  data = {
48
  "model": "gpt-3.5-turbo",
@@ -57,16 +61,12 @@ def generate_question_with_chatgpt(context):
57
 
58
  if 'choices' in result:
59
  # Extract the generated question from the response
60
- generated_question = result["choices"][0]["message"]["content"]
61
-
62
- # Decode the byte string to Unicode string
63
- generated_question = generated_question.decode("utf-8")
 
64
 
65
- # Post-process the question if needed
66
- # Example: Ensure the question ends with a question mark
67
- if not generated_question.endswith('?'):
68
- generated_question += '?'
69
-
70
  return generated_question
71
 
72
  def main():
@@ -88,7 +88,7 @@ def main():
88
  # Display the generated Questions
89
  st.success(f"Generated {num_mcqs} Questions:")
90
  for i, generated_question in enumerate(mcqs, start=1):
91
- st.write(f"\nQuestion {i}: {generated_question}")
92
  st.write(f"Options: {', '.join(generated_question['options'])}")
93
  st.write(f"Correct Answer: {generated_question['correct_answer']}")
94
  else:
@@ -97,3 +97,4 @@ def main():
97
  if __name__ == "__main__":
98
  main()
99
 
 
 
42
  }
43
 
44
  # Initializing the default value
45
+ generated_question = {
46
+ 'content': "Unable to generate a question..",
47
+ 'options': [], # assuming options is a list
48
+ 'correct_answer': "Unknown"
49
+ }
50
 
51
  data = {
52
  "model": "gpt-3.5-turbo",
 
61
 
62
  if 'choices' in result:
63
  # Extract the generated question from the response
64
+ generated_question = {
65
+ 'content': result["choices"][0]["message"]["content"],
66
+ 'options': result["choices"][0]["message"].get("options", []),
67
+ 'correct_answer': result["choices"][0]["message"].get("correct_answer", "Unknown")
68
+ }
69
 
 
 
 
 
 
70
  return generated_question
71
 
72
  def main():
 
88
  # Display the generated Questions
89
  st.success(f"Generated {num_mcqs} Questions:")
90
  for i, generated_question in enumerate(mcqs, start=1):
91
+ st.write(f"\nQuestion {i}: {generated_question['content']}")
92
  st.write(f"Options: {', '.join(generated_question['options'])}")
93
  st.write(f"Correct Answer: {generated_question['correct_answer']}")
94
  else:
 
97
  if __name__ == "__main__":
98
  main()
99
 
100
+