Update app.py
Browse files
app.py
CHANGED
|
@@ -203,33 +203,40 @@ def get_student_profile():
|
|
| 203 |
import re
|
| 204 |
|
| 205 |
def calculate_score_and_grade(llm_response):
|
| 206 |
-
|
| 207 |
-
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 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:
|
| 218 |
-
grade = 'O
|
| 219 |
elif 80 <= percentage <= 90:
|
| 220 |
-
grade = 'A
|
| 221 |
elif 70 <= percentage < 80:
|
| 222 |
-
grade = 'B
|
| 223 |
elif 60 <= percentage < 70:
|
| 224 |
-
grade = 'C
|
| 225 |
elif 50 <= percentage < 60:
|
| 226 |
-
grade = 'D
|
| 227 |
else:
|
| 228 |
grade = 'Fail'
|
| 229 |
|
| 230 |
return total_score, max_possible_score, percentage, grade
|
| 231 |
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
@app.route('/student_reward_points')
|
| 235 |
def student_reward_points():
|
|
@@ -406,17 +413,6 @@ def generate_questions():
|
|
| 406 |
|
| 407 |
return jsonify({'questions': complete_questions})
|
| 408 |
|
| 409 |
-
@app.route('/assign_grade', methods=['POST'])
|
| 410 |
-
def assign_grade():
|
| 411 |
-
data = request.json
|
| 412 |
-
result = data['result']
|
| 413 |
-
total_score, max_possible_score, percentage, grade = calculate_score_and_grade(result)
|
| 414 |
-
return jsonify({
|
| 415 |
-
'total_score': total_score,
|
| 416 |
-
'max_possible_score': max_possible_score,
|
| 417 |
-
'percentage': percentage,
|
| 418 |
-
'grade': grade
|
| 419 |
-
})
|
| 420 |
|
| 421 |
@app.route('/generate_timetable', methods=['POST'])
|
| 422 |
def generate_timetable():
|
|
@@ -496,7 +492,6 @@ def eval():
|
|
| 496 |
answer_text = extract_text_from_pdf(answer_path)
|
| 497 |
else:
|
| 498 |
answer_text = extract_text_from_image(answer_path)
|
| 499 |
-
print(question_text,answer_text)
|
| 500 |
|
| 501 |
elif input_type == 'text':
|
| 502 |
question_text = request.form['question_text']
|
|
@@ -507,7 +502,7 @@ def eval():
|
|
| 507 |
print(f"Answer Text: {answer_text}") # Debugging line
|
| 508 |
print(f"Evaluation Result: {evaluation_result}") # Debugging line
|
| 509 |
|
| 510 |
-
return render_template('
|
| 511 |
|
| 512 |
return render_template('teacher_eval.html')
|
| 513 |
|
|
|
|
| 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
|
| 232 |
+
result = data['result']
|
| 233 |
+
total_score, max_possible_score, percentage, grade = calculate_score_and_grade(result)
|
| 234 |
+
return jsonify({
|
| 235 |
+
'total_score': total_score,
|
| 236 |
+
'max_possible_score': max_possible_score,
|
| 237 |
+
'percentage': percentage,
|
| 238 |
+
'grade': grade
|
| 239 |
+
})
|
| 240 |
|
| 241 |
@app.route('/student_reward_points')
|
| 242 |
def student_reward_points():
|
|
|
|
| 413 |
|
| 414 |
return jsonify({'questions': complete_questions})
|
| 415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
|
| 417 |
@app.route('/generate_timetable', methods=['POST'])
|
| 418 |
def generate_timetable():
|
|
|
|
| 492 |
answer_text = extract_text_from_pdf(answer_path)
|
| 493 |
else:
|
| 494 |
answer_text = extract_text_from_image(answer_path)
|
|
|
|
| 495 |
|
| 496 |
elif input_type == 'text':
|
| 497 |
question_text = request.form['question_text']
|
|
|
|
| 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 |
|