Neurolingua commited on
Commit
84e884f
·
verified ·
1 Parent(s): f1166a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -2,6 +2,7 @@ import joblib
2
  from flask import Flask, render_template, request, jsonify,session
3
  from werkzeug.utils import secure_filename
4
  import os
 
5
  from student_functions import extract_text_from_pdf_s,generate_ai_response,generate_project_idea,generate_project_idea_questions,generate_quiz,generate_response_from_pdf,generate_step_by_step_explanation,study_plan,ConversationBufferMemory,get_first_youtube_video_link,content_translate,summarise_text,content_translate
6
  from teacher_function import evaluate,extract_text_from_image,extract_text_from_pdf,generate_questions_from_text,generate_student_report,generate_timetable_module,cluster_topics,generate_timetable_weak
7
  import shutil
@@ -199,15 +200,20 @@ def get_student_profile():
199
  return jsonify({'status': 'error', 'message': 'Student not found'}), 404
200
 
201
 
 
 
202
  def calculate_score_and_grade(llm_response):
203
- total_score=llm_response.split('\n')[1].split(' ')[-1]
204
- max_possible_score=llm_response.split('\n')[0].split(' ')[-1]
205
 
206
- total_score = int(total_score)
207
- max_possible_score = int(max_possible_score)
 
208
 
209
- percentage = (max_possible_score/total_score) * 100 if max_possible_score > 0 else 0
 
210
 
 
211
  if percentage > 90:
212
  grade = 'O-grade'
213
  elif 80 <= percentage <= 90:
@@ -223,6 +229,8 @@ def calculate_score_and_grade(llm_response):
223
 
224
  return total_score, max_possible_score, percentage, grade
225
 
 
 
226
  @app.route('/student_reward_points')
227
  def student_reward_points():
228
  return render_template('student_reward_points.html')
 
2
  from flask import Flask, render_template, request, jsonify,session
3
  from werkzeug.utils import secure_filename
4
  import os
5
+ import re
6
  from student_functions import extract_text_from_pdf_s,generate_ai_response,generate_project_idea,generate_project_idea_questions,generate_quiz,generate_response_from_pdf,generate_step_by_step_explanation,study_plan,ConversationBufferMemory,get_first_youtube_video_link,content_translate,summarise_text,content_translate
7
  from teacher_function import evaluate,extract_text_from_image,extract_text_from_pdf,generate_questions_from_text,generate_student_report,generate_timetable_module,cluster_topics,generate_timetable_weak
8
  import shutil
 
200
  return jsonify({'status': 'error', 'message': 'Student not found'}), 404
201
 
202
 
203
+ import re
204
+
205
  def calculate_score_and_grade(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:
218
  grade = 'O-grade'
219
  elif 80 <= percentage <= 90:
 
229
 
230
  return total_score, max_possible_score, percentage, grade
231
 
232
+
233
+
234
  @app.route('/student_reward_points')
235
  def student_reward_points():
236
  return render_template('student_reward_points.html')