abhidgp1978 commited on
Commit
4d7e2ad
·
verified ·
1 Parent(s): daaed6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -7,6 +7,7 @@ import requests
7
  import tempfile
8
 
9
  import gradio as gr
 
10
  from huggingface_hub import HfApi, hf_hub_download
11
 
12
  # ---------- CONFIG ----------
@@ -99,7 +100,7 @@ def parse_questions(text):
99
  for line in lines:
100
  if line.strip() == "":
101
  continue
102
- if line[0].isdigit() and (line[1] == ')' or line[2] == ')'):
103
  parts = line.split(")", 1)
104
  if len(parts) > 1:
105
  questions.append(parts[1].strip())
@@ -131,9 +132,6 @@ def analyze_answers(questions, answers, time_taken_seconds):
131
  with gr.Blocks() as demo:
132
  gr.Markdown("# TeachMate AI")
133
 
134
- # Store student results globally
135
- student_results = []
136
-
137
  with gr.Tabs():
138
  # Teacher tab
139
  with gr.TabItem("Teacher"):
@@ -152,6 +150,8 @@ with gr.Blocks() as demo:
152
  status = gr.Textbox(label="Status / Logs", interactive=False)
153
  results_out = gr.Textbox(label="Student Results & Attention Warnings", lines=10, interactive=False)
154
 
 
 
155
  def on_generate(name, email, subject, grade, brief):
156
  if not brief.strip():
157
  return "Please enter a brief"
@@ -173,10 +173,10 @@ with gr.Blocks() as demo:
173
  return msg
174
 
175
  def update_teacher_results():
176
- if not student_results:
177
  return "No student submissions yet."
178
  lines = []
179
- for r in student_results:
180
  line = (f"Student: {r['student_name']} | Grade: {r['student_grade']} | "
181
  f"Score: {r['score']}/{r['total_questions']} | "
182
  f"Attention: {'YES' if r['needs_attention'] else 'NO'}")
@@ -186,9 +186,6 @@ with gr.Blocks() as demo:
186
  gen_btn.click(on_generate, inputs=[name_in, email_in, subject_in, grade_in, brief_in], outputs=generated_out)
187
  save_btn.click(on_save, inputs=[name_in, email_in, subject_in, grade_in, brief_in, generated_out], outputs=status)
188
 
189
- timer = gr.Timer(interval=10)
190
- timer.tick(update_teacher_results, outputs=results_out)
191
-
192
  # Student tab
193
  with gr.TabItem("Student"):
194
  with gr.Row():
@@ -233,15 +230,16 @@ with gr.Blocks() as demo:
233
  time_taken = time.time() - start
234
  ans_list = answers.splitlines()
235
  res, needs_attention = analyze_answers(questions, ans_list, time_taken)
236
- # Append to global student_results list
237
- student_results.append({
 
 
238
  "student_name": student_name_val,
239
  "student_grade": student_grade_val,
240
  "score": sum(1 for a in ans_list if a.strip()),
241
  "total_questions": len(questions),
242
  "needs_attention": needs_attention
243
  })
244
- # Return score for student only
245
  return res
246
 
247
  student_subject.change(load_homework_list, inputs=[student_subject, student_grade], outputs=[homework_dd, homework_dd])
@@ -262,5 +260,9 @@ with gr.Blocks() as demo:
262
 
263
  get_hint_btn.click(generate_hint, inputs=rough_input, outputs=hint_output)
264
 
 
 
 
 
265
  if __name__ == "__main__":
266
  demo.launch()
 
7
  import tempfile
8
 
9
  import gradio as gr
10
+ import pandas as pd
11
  from huggingface_hub import HfApi, hf_hub_download
12
 
13
  # ---------- CONFIG ----------
 
100
  for line in lines:
101
  if line.strip() == "":
102
  continue
103
+ if line[0].isdigit() and (line[1] == ')' or (len(line) > 2 and line[2] == ')')):
104
  parts = line.split(")", 1)
105
  if len(parts) > 1:
106
  questions.append(parts[1].strip())
 
132
  with gr.Blocks() as demo:
133
  gr.Markdown("# TeachMate AI")
134
 
 
 
 
135
  with gr.Tabs():
136
  # Teacher tab
137
  with gr.TabItem("Teacher"):
 
150
  status = gr.Textbox(label="Status / Logs", interactive=False)
151
  results_out = gr.Textbox(label="Student Results & Attention Warnings", lines=10, interactive=False)
152
 
153
+ student_results = []
154
+
155
  def on_generate(name, email, subject, grade, brief):
156
  if not brief.strip():
157
  return "Please enter a brief"
 
173
  return msg
174
 
175
  def update_teacher_results():
176
+ if not getattr(demo, "student_results", []):
177
  return "No student submissions yet."
178
  lines = []
179
+ for r in demo.student_results:
180
  line = (f"Student: {r['student_name']} | Grade: {r['student_grade']} | "
181
  f"Score: {r['score']}/{r['total_questions']} | "
182
  f"Attention: {'YES' if r['needs_attention'] else 'NO'}")
 
186
  gen_btn.click(on_generate, inputs=[name_in, email_in, subject_in, grade_in, brief_in], outputs=generated_out)
187
  save_btn.click(on_save, inputs=[name_in, email_in, subject_in, grade_in, brief_in, generated_out], outputs=status)
188
 
 
 
 
189
  # Student tab
190
  with gr.TabItem("Student"):
191
  with gr.Row():
 
230
  time_taken = time.time() - start
231
  ans_list = answers.splitlines()
232
  res, needs_attention = analyze_answers(questions, ans_list, time_taken)
233
+ # Append to global student_results on teacher tab
234
+ if not hasattr(demo, "student_results"):
235
+ demo.student_results = []
236
+ demo.student_results.append({
237
  "student_name": student_name_val,
238
  "student_grade": student_grade_val,
239
  "score": sum(1 for a in ans_list if a.strip()),
240
  "total_questions": len(questions),
241
  "needs_attention": needs_attention
242
  })
 
243
  return res
244
 
245
  student_subject.change(load_homework_list, inputs=[student_subject, student_grade], outputs=[homework_dd, homework_dd])
 
260
 
261
  get_hint_btn.click(generate_hint, inputs=rough_input, outputs=hint_output)
262
 
263
+ # Update teacher results periodically
264
+ timer = gr.Timer(10) # Every 10 seconds
265
+ timer.tick(update_teacher_results, outputs=results_out)
266
+
267
  if __name__ == "__main__":
268
  demo.launch()