Rathapoom commited on
Commit
9f4a1d9
·
verified ·
1 Parent(s): a28ec90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -26,7 +26,7 @@ def generate_questions_with_retry(knowledge_material, question_type, cognitive_l
26
  while retries < max_retries:
27
  try:
28
  response = client.chat.completions.create(
29
- model="gpt-4o-mini",
30
  messages=[
31
  {"role": "system", "content": "You are a helpful assistant for generating exam questions."},
32
  {"role": "user", "content": prompt}
@@ -55,11 +55,19 @@ else:
55
  # Main App after login
56
  st.title(f"Welcome, {st.session_state['username']}! Generate your exam questions")
57
 
58
- # Input field for knowledge material (text)
59
  knowledge_material = st.text_area("Enter knowledge material to generate exam questions:")
60
-
61
- # File uploader for PDFs (Optional: Only if you want to implement PDF input later)
 
 
 
 
62
  uploaded_file = st.file_uploader("Upload a file (PDF)", type="pdf")
 
 
 
 
63
 
64
  # Select question type
65
  question_type = st.selectbox("Select question type:",
@@ -69,7 +77,7 @@ else:
69
  cognitive_level = st.selectbox("Select cognitive level:",
70
  ["Recall", "Understanding", "Application", "Analysis", "Synthesis", "Evaluation"])
71
 
72
- # Extra input field for additional instructions (now placed below cognitive level)
73
  extra_instructions = st.text_area("Enter additional instructions (e.g., how you want the questions to be phrased):")
74
 
75
  # Generate questions button
@@ -77,7 +85,7 @@ else:
77
  st.session_state['previous_questions'] = []
78
 
79
  if st.button("Generate Questions"):
80
- if knowledge_material:
81
  # Generate questions with retry logic
82
  questions = generate_questions_with_retry(knowledge_material, question_type, cognitive_level, extra_instructions)
83
 
@@ -96,11 +104,11 @@ else:
96
  mime='text/plain'
97
  )
98
  else:
99
- st.warning("Please enter the knowledge material.")
100
 
101
  # Button to generate more questions based on the same material
102
  if st.button("Generate More Questions"):
103
- if knowledge_material:
104
  # Regenerate new questions, trying to avoid repeated content
105
  questions = generate_questions_with_retry(knowledge_material, question_type, cognitive_level, extra_instructions)
106
 
@@ -121,3 +129,5 @@ else:
121
  )
122
  else:
123
  st.warning("New questions seem to overlap with the previous ones. Try adjusting the instructions.")
 
 
 
26
  while retries < max_retries:
27
  try:
28
  response = client.chat.completions.create(
29
+ model="GPT-4o mini",
30
  messages=[
31
  {"role": "system", "content": "You are a helpful assistant for generating exam questions."},
32
  {"role": "user", "content": prompt}
 
55
  # Main App after login
56
  st.title(f"Welcome, {st.session_state['username']}! Generate your exam questions")
57
 
58
+ # Input field for knowledge material (text) with 3,000-word limit
59
  knowledge_material = st.text_area("Enter knowledge material to generate exam questions:")
60
+
61
+ # Word count check
62
+ if len(knowledge_material.split()) > 3000:
63
+ st.warning("Please limit the knowledge material to 3,000 words or fewer.")
64
+
65
+ # File uploader for PDFs (limited to 5 MB)
66
  uploaded_file = st.file_uploader("Upload a file (PDF)", type="pdf")
67
+
68
+ if uploaded_file is not None:
69
+ if uploaded_file.size > 5 * 1024 * 1024: # 5 MB limit
70
+ st.warning("File size exceeds 5 MB. Please upload a smaller file.")
71
 
72
  # Select question type
73
  question_type = st.selectbox("Select question type:",
 
77
  cognitive_level = st.selectbox("Select cognitive level:",
78
  ["Recall", "Understanding", "Application", "Analysis", "Synthesis", "Evaluation"])
79
 
80
+ # Extra input field for additional instructions (placed below cognitive level)
81
  extra_instructions = st.text_area("Enter additional instructions (e.g., how you want the questions to be phrased):")
82
 
83
  # Generate questions button
 
85
  st.session_state['previous_questions'] = []
86
 
87
  if st.button("Generate Questions"):
88
+ if len(knowledge_material.split()) <= 3000:
89
  # Generate questions with retry logic
90
  questions = generate_questions_with_retry(knowledge_material, question_type, cognitive_level, extra_instructions)
91
 
 
104
  mime='text/plain'
105
  )
106
  else:
107
+ st.warning("Please reduce the word count to 3,000 or fewer.")
108
 
109
  # Button to generate more questions based on the same material
110
  if st.button("Generate More Questions"):
111
+ if len(knowledge_material.split()) <= 3000:
112
  # Regenerate new questions, trying to avoid repeated content
113
  questions = generate_questions_with_retry(knowledge_material, question_type, cognitive_level, extra_instructions)
114
 
 
129
  )
130
  else:
131
  st.warning("New questions seem to overlap with the previous ones. Try adjusting the instructions.")
132
+ else:
133
+ st.warning("Please reduce the word count to 3,000 or fewer.")