Neurolingua commited on
Commit
5ec95b8
·
verified ·
1 Parent(s): e83353c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -201,31 +201,34 @@ def get_student_profile():
201
 
202
 
203
  import re
204
-
205
  def calculate_score_and_grade(llm_response):
206
- pattern = r'Assigned marks: (\d+)/(\d+)'
207
- matches = re.findall(pattern, llm_response)
208
 
209
- total_score = sum(int(score) for score, max_score in matches)
210
- max_possible_score = sum(int(max_score) for score, max_score in matches)
 
211
 
 
212
  percentage = (total_score / max_possible_score) * 100 if max_possible_score > 0 else 0
213
 
 
214
  if percentage > 90:
215
- grade = 'O'
216
  elif 80 <= percentage <= 90:
217
- grade = 'A'
218
  elif 70 <= percentage < 80:
219
- grade = 'B'
220
  elif 60 <= percentage < 70:
221
- grade = 'C'
222
  elif 50 <= percentage < 60:
223
- grade = 'D'
224
  else:
225
  grade = 'Fail'
226
 
227
  return total_score, max_possible_score, percentage, grade
228
 
 
229
  @app.route('/assign_grade', methods=['POST'])
230
  def assign_grade():
231
  data = request.json
@@ -463,7 +466,6 @@ def generate_paper():
463
 
464
  return render_template('teacher_paper_gen.html')
465
 
466
-
467
  @app.route('/eval', methods=['GET', 'POST'])
468
  def eval():
469
  if request.method == 'POST':
@@ -502,7 +504,7 @@ def eval():
502
  print(f"Answer Text: {answer_text}") # Debugging line
503
  print(f"Evaluation Result: {evaluation_result}") # Debugging line
504
 
505
- return render_template('teacher_eval.html', result=evaluation_result)
506
 
507
  return render_template('teacher_eval.html')
508
 
 
201
 
202
 
203
  import re
 
204
  def calculate_score_and_grade(llm_response):
205
+ # Extract all the marks using a regular expression
206
+ marks = re.findall(r'(\d+)/(\d+)', llm_response)
207
 
208
+ # Calculate total score and maximum possible score
209
+ total_score = sum(int(mark[0]) for mark in marks)
210
+ max_possible_score = sum(int(mark[1]) for mark in marks)
211
 
212
+ # Calculate the percentage
213
  percentage = (total_score / max_possible_score) * 100 if max_possible_score > 0 else 0
214
 
215
+ # Determine the grade based on the percentage
216
  if percentage > 90:
217
+ grade = 'O-grade'
218
  elif 80 <= percentage <= 90:
219
+ grade = 'A-grade'
220
  elif 70 <= percentage < 80:
221
+ grade = 'B-grade'
222
  elif 60 <= percentage < 70:
223
+ grade = 'C-grade'
224
  elif 50 <= percentage < 60:
225
+ grade = 'D-grade'
226
  else:
227
  grade = 'Fail'
228
 
229
  return total_score, max_possible_score, percentage, grade
230
 
231
+
232
  @app.route('/assign_grade', methods=['POST'])
233
  def assign_grade():
234
  data = request.json
 
466
 
467
  return render_template('teacher_paper_gen.html')
468
 
 
469
  @app.route('/eval', methods=['GET', 'POST'])
470
  def eval():
471
  if request.method == 'POST':
 
504
  print(f"Answer Text: {answer_text}") # Debugging line
505
  print(f"Evaluation Result: {evaluation_result}") # Debugging line
506
 
507
+ return render_template('teacher_result.html', result=evaluation_result)
508
 
509
  return render_template('teacher_eval.html')
510