Neurolingua commited on
Commit
ae54bde
1 Parent(s): 9bae946

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -201,17 +201,28 @@ def get_student_profile():
201
 
202
 
203
  import re
204
- def calculate_score_and_grade(llm_response):
 
 
205
  print(llm_response)
 
206
  # Extract all the marks using a regular expression
207
  marks = re.findall(r'(\d+)/(\d+)', llm_response)
 
 
 
 
208
 
209
  # Calculate total score and maximum possible score
210
  total_score = sum(int(mark[0]) for mark in marks)
211
  max_possible_score = sum(int(mark[1]) for mark in marks)
212
 
 
 
 
 
213
  # Calculate the percentage
214
- percentage = (total_score / max_possible_score) * 100 if max_possible_score > 0 else 0
215
 
216
  # Determine the grade based on the percentage
217
  if percentage > 90:
@@ -234,7 +245,7 @@ def calculate_score_and_grade(llm_response):
234
  def assign_grade():
235
  data = request.json
236
  result = data['result']
237
- total_score, max_possible_score, percentage, grade = calculate_score_and_grade(result)
238
  return jsonify({
239
  'total_score': total_score,
240
  'max_possible_score': max_possible_score,
 
201
 
202
 
203
  import re
204
+ import re
205
+
206
+ def calculate_score_and_grades(llm_response):
207
  print(llm_response)
208
+
209
  # Extract all the marks using a regular expression
210
  marks = re.findall(r'(\d+)/(\d+)', llm_response)
211
+
212
+ if not marks:
213
+ # Handle the case where no marks are found
214
+ return 0, 0, 0, 'No grade'
215
 
216
  # Calculate total score and maximum possible score
217
  total_score = sum(int(mark[0]) for mark in marks)
218
  max_possible_score = sum(int(mark[1]) for mark in marks)
219
 
220
+ # Prevent division by zero
221
+ if max_possible_score == 0:
222
+ return total_score, max_possible_score, 0, 'Fail'
223
+
224
  # Calculate the percentage
225
+ percentage = (total_score / max_possible_score) * 100
226
 
227
  # Determine the grade based on the percentage
228
  if percentage > 90:
 
245
  def assign_grade():
246
  data = request.json
247
  result = data['result']
248
+ total_score, max_possible_score, percentage, grade = calculate_score_and_grades(result)
249
  return jsonify({
250
  'total_score': total_score,
251
  'max_possible_score': max_possible_score,