Tman212 commited on
Commit
f0e773d
·
verified ·
1 Parent(s): b75e50e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -15
app.py CHANGED
@@ -65,7 +65,7 @@ def get_coaching(rounded_scores):
65
  return html
66
 
67
  # ─── 2) Scoring logic with continuous Bloom & Scoreboard ────────────────────
68
- def score_questions(uploaded_file, text):
69
  # 1) gather
70
  if uploaded_file:
71
  df_in = pd.read_excel(uploaded_file)
@@ -73,19 +73,28 @@ def score_questions(uploaded_file, text):
73
  else:
74
  questions = [q.strip() for q in text.splitlines() if q.strip()]
75
 
76
- # 2) validate (same as before) …
77
- valid_qs, invalid_qs = [], []
78
- for q in questions:
79
- if len(q.split()) >= 2 and q.endswith("?"):
80
- valid_qs.append(q)
81
- else:
82
- invalid_qs.append(q)
83
- if invalid_qs:
84
- warning_html = "<div style='color:red; …'>" + "".join(f"– {iq}<br>" for iq in invalid_qs) + "</div>"
85
- # return early (table, slider, bloom, stats, coaching, download)
86
- return None, 1, "", warning_html, None
 
 
 
 
 
 
87
 
88
- questions = valid_qs
 
 
 
89
 
90
  # 3) predict & score
91
  inputs = tokenizer(questions, return_tensors="pt", truncation=True, padding=True)
@@ -186,7 +195,6 @@ body, .gradio-container {
186
 
187
  # ─── 4) Blocks layout ───────────────────────────────────────────────────────────
188
  with gr.Blocks(css=custom_css) as demo:
189
-
190
  # ── Theme toggles (optional) ────────────────────────────────────────
191
  gr.HTML(
192
  """
@@ -235,6 +243,7 @@ with gr.Blocks(css=custom_css) as demo:
235
  type="filepath"
236
  )
237
  text_in = gr.Textbox(label="Or paste one question per line…", lines=6)
 
238
  score_btn = gr.Button("Score my data")
239
 
240
  with gr.Column():
@@ -249,7 +258,7 @@ with gr.Blocks(css=custom_css) as demo:
249
  # Hook up the scoring button (must return exactly 5 outputs)
250
  score_btn.click(
251
  fn=score_questions,
252
- inputs=[excel, text_in],
253
  outputs=[df_out, avg_slider, bloom_html, stats_box, coaching_box]
254
  )
255
 
 
65
  return html
66
 
67
  # ─── 2) Scoring logic with continuous Bloom & Scoreboard ────────────────────
68
+ def score_questions(uploaded_file, text, ignore_validation=False):
69
  # 1) gather
70
  if uploaded_file:
71
  df_in = pd.read_excel(uploaded_file)
 
73
  else:
74
  questions = [q.strip() for q in text.splitlines() if q.strip()]
75
 
76
+ if not ignore_validation:
77
+ valid_qs, invalid_qs = [], []
78
+ for q in questions:
79
+ if len(q.split()) >= 2 and q.endswith(("?", "?")):
80
+ valid_qs.append(q)
81
+ else:
82
+ invalid_qs.append(q)
83
+ if invalid_qs:
84
+ warning_html = (
85
+ "<div style='color:red; padding:1rem; border:1px solid #F00;'>"
86
+ "<strong>The entries below weren’t scored because they didn’t look like full questions "
87
+ "(≥2 words + trailing '?'):</strong><br>"
88
+ + "".join(f"– {iq}<br>" for iq in invalid_qs)
89
+ + "</div>"
90
+ )
91
+ # return early (table, slider, bloom, stats, coaching)
92
+ return None, 1, "", warning_html, ""
93
 
94
+ questions = valid_qs
95
+ else:
96
+ # skip validation, proceed with all questions
97
+ questions = [q for q in questions if q.strip()]
98
 
99
  # 3) predict & score
100
  inputs = tokenizer(questions, return_tensors="pt", truncation=True, padding=True)
 
195
 
196
  # ─── 4) Blocks layout ───────────────────────────────────────────────────────────
197
  with gr.Blocks(css=custom_css) as demo:
 
198
  # ── Theme toggles (optional) ────────────────────────────────────────
199
  gr.HTML(
200
  """
 
243
  type="filepath"
244
  )
245
  text_in = gr.Textbox(label="Or paste one question per line…", lines=6)
246
+ ignore_validation = gr.Checkbox(label="Ignore validation (allow any text)", value=False)
247
  score_btn = gr.Button("Score my data")
248
 
249
  with gr.Column():
 
258
  # Hook up the scoring button (must return exactly 5 outputs)
259
  score_btn.click(
260
  fn=score_questions,
261
+ inputs=[excel, text_in, ignore_validation],
262
  outputs=[df_out, avg_slider, bloom_html, stats_box, coaching_box]
263
  )
264