mikaelJ46 commited on
Commit
52451d8
·
verified ·
1 Parent(s): 4d999d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py CHANGED
@@ -134,6 +134,74 @@ syllabus_topics = {
134
  }
135
 
136
  # ---------- 4. Generate Practice Questions (Customizable) ----------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  def generate_practice_questions(grade_level, topic, num_questions=10):
138
  """Generate multiple questions with robust text parsing (not JSON)"""
139
 
@@ -157,6 +225,10 @@ Each question should be:
157
  Start immediately with Q1. Do not include any introduction or explanation."""
158
 
159
  response, source = ask_ai(prompt, temperature=0.6)
 
 
 
 
160
 
161
  # Parse questions robustly using regex to support multi-digit numbers (Q1..Q10..)
162
  questions = []
 
134
  }
135
 
136
  # ---------- 4. Generate Practice Questions (Customizable) ----------
137
+ def generate_sample_questions(grade_level, topic, num_questions=10):
138
+ """Fallback: Generate sample questions locally when AI is unavailable"""
139
+ samples = {
140
+ "Integers & Operations": [
141
+ "Q1. Calculate the sum of -20 and -15.",
142
+ "Q2. A farmer bought 40 oranges and then sold 25 of them. What is the difference between the number of oranges bought and sold?",
143
+ "Q3. Simplify: 36 - (-10) + 5. Q10. Find the value of -2(8) + 15.",
144
+ "Q11. A car is parked at -10 meters. If it moves up a slope of 15 meters, what is its final position?",
145
+ "Q12. Calculate the product of -4 and 5.",
146
+ "Q13. A boat descends 12 meters below sea level, then rises 8 meters. What is its final position relative to sea level?",
147
+ "Q16. Simplify: 2(-3) + 5(-2).",
148
+ "Q17. A rabbit hops 7 meters forward and then 4 meters backward. What is the net distance covered by the rabbit?",
149
+ "Q18. Calculate the value of 2/3(-18) + 5.",
150
+ "Q19. A plane descends 300 meters and then ascends 200 meters. What is the plane's final position relative to the initial descent point?",
151
+ ],
152
+ "Fractions - Addition & Subtraction": [
153
+ "Q1. Add 1/4 and 1/3.",
154
+ "Q2. Subtract 2/5 from 3/5.",
155
+ "Q3. What is 1/2 + 1/4 + 1/8?",
156
+ "Q4. Calculate 7/8 - 1/4.",
157
+ "Q5. Find the sum of 2/3 and 1/6.",
158
+ "Q6. Subtract 3/10 from 9/10.",
159
+ "Q7. Add 1/5, 2/5, and 1/5.",
160
+ "Q8. What is 5/6 - 1/3?",
161
+ "Q9. Calculate 3/4 + 2/8.",
162
+ "Q10. Find 11/12 - 1/4.",
163
+ ],
164
+ "Decimals & Percentages": [
165
+ "Q1. Convert 0.25 to a percentage.",
166
+ "Q2. What is 25% of 80?",
167
+ "Q3. Convert 3/4 to a decimal.",
168
+ "Q4. Calculate 15% of 200.",
169
+ "Q5. What decimal is equivalent to 60%?",
170
+ "Q6. Find 10% of 450.",
171
+ "Q7. Convert 0.875 to a percentage.",
172
+ "Q8. What is 50% of 64?",
173
+ "Q9. Calculate 30% of 150.",
174
+ "Q10. Convert 45% to a decimal.",
175
+ ],
176
+ "Geometry - Angles & Properties": [
177
+ "Q1. What is the sum of angles in a triangle?",
178
+ "Q2. If one angle of a triangle is 60° and another is 50°, find the third angle.",
179
+ "Q3. What are the properties of a rectangle?",
180
+ "Q4. Calculate the perimeter of a square with side 5 cm.",
181
+ "Q5. What is the sum of angles in a quadrilateral?",
182
+ "Q6. If two angles are complementary, and one is 35°, what is the other?",
183
+ "Q7. Define a right angle.",
184
+ "Q8. What is the area of a triangle with base 8 cm and height 6 cm?",
185
+ "Q9. Calculate the perimeter of a rectangle with length 10 cm and width 6 cm.",
186
+ "Q10. What are supplementary angles?",
187
+ ],
188
+ }
189
+
190
+ # Use sample questions for the given topic, or create generic ones
191
+ topic_key = None
192
+ for key in samples:
193
+ if key.lower() in topic.lower() or topic.lower() in key.lower():
194
+ topic_key = key
195
+ break
196
+
197
+ if topic_key:
198
+ qs = samples[topic_key][:num_questions]
199
+ else:
200
+ qs = [f"Q{i+1}. Sample question {i+1} on {topic}." for i in range(num_questions)]
201
+
202
+ return "\n\n".join(qs)
203
+
204
+
205
  def generate_practice_questions(grade_level, topic, num_questions=10):
206
  """Generate multiple questions with robust text parsing (not JSON)"""
207
 
 
225
  Start immediately with Q1. Do not include any introduction or explanation."""
226
 
227
  response, source = ask_ai(prompt, temperature=0.6)
228
+
229
+ # Fallback: if AI fails, generate sample questions locally
230
+ if "All AI services failed" in response or response.startswith("⚠️"):
231
+ response = generate_sample_questions(grade_level, topic, num_questions)
232
 
233
  # Parse questions robustly using regex to support multi-digit numbers (Q1..Q10..)
234
  questions = []