mikaelJ46 commited on
Commit
77e1f78
·
verified ·
1 Parent(s): 1734ffd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -3
app.py CHANGED
@@ -462,6 +462,9 @@ class StudentSession:
462
 
463
  session = StudentSession()
464
 
 
 
 
465
  # ---------- 7. Download Functions ----------
466
  def download_questions_file(questions_list, topic, grade_level, subject=None):
467
  """Download questions as text file"""
@@ -901,12 +904,50 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
901
  if canvas_input is not None:
902
  # Map the same canvas image to all question indices so each question gets graded
903
  session.current_answers = {i: canvas_input for i in range(len(session.current_questions))}
904
- return f" Canvas submission received with {len(session.current_questions)} questions. Processing..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
905
 
906
  elif upload_input is not None:
907
  # Map the uploaded image to all question indices so AI can analyse each part
908
  session.current_answers = {i: upload_input for i in range(len(session.current_questions))}
909
- return f" Photo submission received with {len(session.current_questions)} questions. Processing..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
910
 
911
  elif typed_input and typed_input.strip():
912
  # Parse typed answers with improved logic
@@ -969,7 +1010,26 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
969
  if session.current_answers:
970
  answered = len(session.current_answers)
971
  total = len(session.current_questions)
972
- return f"✅ Received {answered}/{total} answer(s). Processing for AI correction..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
  else:
974
  return "⚠️ Could not find any answers. Please type your answers using one of the suggested formats."
975
  else:
@@ -1059,6 +1119,28 @@ with gr.Blocks(title="UNEB Exam Prep - Primary 6 & 7", theme=gr.themes.Soft(), c
1059
  outputs=download_feedback_btn
1060
  )
1061
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1062
  # Follow-up handler: student asks a question about the feedback
1063
  def send_followup(question_text):
1064
  if not session.last_feedback:
 
462
 
463
  session = StudentSession()
464
 
465
+ # In-memory submissions store for student results
466
+ submissions_storage = []
467
+
468
  # ---------- 7. Download Functions ----------
469
  def download_questions_file(questions_list, topic, grade_level, subject=None):
470
  """Download questions as text file"""
 
904
  if canvas_input is not None:
905
  # Map the same canvas image to all question indices so each question gets graded
906
  session.current_answers = {i: canvas_input for i in range(len(session.current_questions))}
907
+ # Automatically grade and store results
908
+ feedback = grade_student_answers(
909
+ session.current_questions,
910
+ session.current_answers,
911
+ session.current_grade,
912
+ session.current_topic,
913
+ getattr(session, 'current_subject', None)
914
+ )
915
+ session.last_feedback = feedback
916
+ session.correction_conversation = [{'role':'assistant', 'content': feedback}]
917
+ # Save to submissions storage
918
+ submissions_storage.append({
919
+ 'student': session.student_name,
920
+ 'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
921
+ 'subject': getattr(session, 'current_subject', None),
922
+ 'grade_level': session.current_grade,
923
+ 'topic': session.current_topic,
924
+ 'answers': 'image',
925
+ 'feedback': feedback
926
+ })
927
+ return f"✅ Canvas submission received and graded. View feedback in 'AI Correction' tab."
928
 
929
  elif upload_input is not None:
930
  # Map the uploaded image to all question indices so AI can analyse each part
931
  session.current_answers = {i: upload_input for i in range(len(session.current_questions))}
932
+ feedback = grade_student_answers(
933
+ session.current_questions,
934
+ session.current_answers,
935
+ session.current_grade,
936
+ session.current_topic,
937
+ getattr(session, 'current_subject', None)
938
+ )
939
+ session.last_feedback = feedback
940
+ session.correction_conversation = [{'role':'assistant', 'content': feedback}]
941
+ submissions_storage.append({
942
+ 'student': session.student_name,
943
+ 'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
944
+ 'subject': getattr(session, 'current_subject', None),
945
+ 'grade_level': session.current_grade,
946
+ 'topic': session.current_topic,
947
+ 'answers': 'image',
948
+ 'feedback': feedback
949
+ })
950
+ return f"✅ Photo submission received and graded. View feedback in 'AI Correction' tab."
951
 
952
  elif typed_input and typed_input.strip():
953
  # Parse typed answers with improved logic
 
1010
  if session.current_answers:
1011
  answered = len(session.current_answers)
1012
  total = len(session.current_questions)
1013
+ # Automatically grade textual answers as well
1014
+ feedback = grade_student_answers(
1015
+ session.current_questions,
1016
+ session.current_answers,
1017
+ session.current_grade,
1018
+ session.current_topic,
1019
+ getattr(session, 'current_subject', None)
1020
+ )
1021
+ session.last_feedback = feedback
1022
+ session.correction_conversation = [{'role':'assistant', 'content': feedback}]
1023
+ submissions_storage.append({
1024
+ 'student': session.student_name,
1025
+ 'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
1026
+ 'subject': getattr(session, 'current_subject', None),
1027
+ 'grade_level': session.current_grade,
1028
+ 'topic': session.current_topic,
1029
+ 'answers': session.current_answers,
1030
+ 'feedback': feedback
1031
+ })
1032
+ return f"✅ Received {answered}/{total} answer(s) and graded. View feedback in 'AI Correction' tab."
1033
  else:
1034
  return "⚠️ Could not find any answers. Please type your answers using one of the suggested formats."
1035
  else:
 
1119
  outputs=download_feedback_btn
1120
  )
1121
 
1122
+ # View student results from submissions_storage
1123
+ results_output = gr.Markdown()
1124
+ results_btn = gr.Button(" Show My Results", variant="secondary")
1125
+
1126
+ def view_student_results(name):
1127
+ student = name if name else session.student_name
1128
+ items = [s for s in submissions_storage if s.get('student') == student]
1129
+ if not items:
1130
+ return f"No submissions found for {student}."
1131
+ out = f"### 📋 Submissions for {student}\n"
1132
+ for it in sorted(items, key=lambda x: x['timestamp'], reverse=True):
1133
+ subj = it.get('subject') or 'N/A'
1134
+ ts = it.get('timestamp')
1135
+ topic = it.get('topic') or 'N/A'
1136
+ fb = it.get('feedback')
1137
+ # show a short preview of feedback
1138
+ preview = fb[:300] + ("..." if len(str(fb)) > 300 else "")
1139
+ out += f"\n- {ts} | {subj} | {topic}\n\n {preview}\n"
1140
+ return out
1141
+
1142
+ results_btn.click(fn=view_student_results, inputs=[student_name_input], outputs=results_output)
1143
+
1144
  # Follow-up handler: student asks a question about the feedback
1145
  def send_followup(question_text):
1146
  if not session.last_feedback: