Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -152,10 +152,16 @@ def build_level_label(level, mode):
|
|
| 152 |
def grade_answers(passage, questions, answers):
|
| 153 |
client = get_llm_client()
|
| 154 |
if not client: return _fallback_grade(questions, answers)
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
sys_p = ("Grade reading-comp answers on meaning only. Spelling OK. "
|
| 158 |
-
"
|
|
|
|
|
|
|
| 159 |
"Return ONLY JSON: correct_count(float), total_questions(int), "
|
| 160 |
"percent(float 0-100), feedback(list of strings, one per active question).")
|
| 161 |
try:
|
|
@@ -218,6 +224,7 @@ def grade_english_rewrite(questions, model_answers, rewrites):
|
|
| 218 |
sys_p = ("Check if each student rewrite is grammatically correct, complete, "
|
| 219 |
"captures meaning. Ignore spaces; minor spelling OK; "
|
| 220 |
"must start capital, end full stop. "
|
|
|
|
| 221 |
"Return ONLY JSON: correct_count(int), total(int), feedback(list).")
|
| 222 |
try:
|
| 223 |
r = client.chat.completions.create(
|
|
@@ -446,27 +453,25 @@ with gr.Blocks(title="Reading Comprehension Quiz", theme=gr.themes.Soft()) as de
|
|
| 446 |
tick = gr.Timer(value=1)
|
| 447 |
|
| 448 |
def cb_tick(state):
|
|
|
|
| 449 |
if state.get("ma_shown_at") is None:
|
| 450 |
-
return
|
| 451 |
if state.get("text_mode") != "disappearing":
|
| 452 |
-
return
|
| 453 |
|
| 454 |
elapsed = time.time() - state["ma_shown_at"]
|
| 455 |
updates = []
|
| 456 |
-
changed = False
|
| 457 |
for i in range(MAX_QUESTIONS):
|
| 458 |
if state["ma_hidden"][i]:
|
| 459 |
updates.append(gr.update())
|
| 460 |
elif elapsed >= HIDE_DELAY[i]:
|
| 461 |
state["ma_hidden"][i] = True
|
| 462 |
updates.append(gr.update(
|
| 463 |
-
value=f"*Q{i+1} — model answer hidden*",
|
| 464 |
visible=True))
|
| 465 |
-
changed = True
|
| 466 |
else:
|
| 467 |
-
rem = int(HIDE_DELAY[i] - elapsed)
|
| 468 |
updates.append(gr.update())
|
| 469 |
-
return state, updates
|
| 470 |
|
| 471 |
tick.tick(cb_tick, inputs=[sess], outputs=[sess, *ma_cards])
|
| 472 |
except AttributeError:
|
|
|
|
| 152 |
def grade_answers(passage, questions, answers):
|
| 153 |
client = get_llm_client()
|
| 154 |
if not client: return _fallback_grade(questions, answers)
|
| 155 |
+
lines = []
|
| 156 |
+
for i,(q,a) in enumerate(zip(questions,answers)):
|
| 157 |
+
if not q.strip(): continue
|
| 158 |
+
ans_text = a.strip() if a.strip() else "[NO ANSWER — mark as 0, incorrect]"
|
| 159 |
+
lines.append(f"Q{i+1}: {q}\nA{i+1}: {ans_text}")
|
| 160 |
+
qa = "\n".join(lines)
|
| 161 |
sys_p = ("Grade reading-comp answers on meaning only. Spelling OK. "
|
| 162 |
+
"STRICT RULE: Any answer marked [NO ANSWER] must receive 0 credit and "
|
| 163 |
+
"be marked incorrect. Do not infer or assume any answer. "
|
| 164 |
+
"Partial credit allowed for partial answers. "
|
| 165 |
"Return ONLY JSON: correct_count(float), total_questions(int), "
|
| 166 |
"percent(float 0-100), feedback(list of strings, one per active question).")
|
| 167 |
try:
|
|
|
|
| 224 |
sys_p = ("Check if each student rewrite is grammatically correct, complete, "
|
| 225 |
"captures meaning. Ignore spaces; minor spelling OK; "
|
| 226 |
"must start capital, end full stop. "
|
| 227 |
+
"STRICT RULE: blank or missing rewrites must score 0 — do not give credit. "
|
| 228 |
"Return ONLY JSON: correct_count(int), total(int), feedback(list).")
|
| 229 |
try:
|
| 230 |
r = client.chat.completions.create(
|
|
|
|
| 453 |
tick = gr.Timer(value=1)
|
| 454 |
|
| 455 |
def cb_tick(state):
|
| 456 |
+
no_change = (state, *([gr.update()] * MAX_QUESTIONS))
|
| 457 |
if state.get("ma_shown_at") is None:
|
| 458 |
+
return no_change
|
| 459 |
if state.get("text_mode") != "disappearing":
|
| 460 |
+
return no_change
|
| 461 |
|
| 462 |
elapsed = time.time() - state["ma_shown_at"]
|
| 463 |
updates = []
|
|
|
|
| 464 |
for i in range(MAX_QUESTIONS):
|
| 465 |
if state["ma_hidden"][i]:
|
| 466 |
updates.append(gr.update())
|
| 467 |
elif elapsed >= HIDE_DELAY[i]:
|
| 468 |
state["ma_hidden"][i] = True
|
| 469 |
updates.append(gr.update(
|
| 470 |
+
value=f"*Q{i+1} — model answer hidden.*",
|
| 471 |
visible=True))
|
|
|
|
| 472 |
else:
|
|
|
|
| 473 |
updates.append(gr.update())
|
| 474 |
+
return (state, *updates)
|
| 475 |
|
| 476 |
tick.tick(cb_tick, inputs=[sess], outputs=[sess, *ma_cards])
|
| 477 |
except AttributeError:
|