DocUA commited on
Commit
86dfd2e
·
1 Parent(s): 08ac559

Improve conversation verification UX

Browse files
src/interface/simplified_gradio_app.py CHANGED
@@ -2071,12 +2071,56 @@ To revert, use "Reset to Default" button.
2071
  else:
2072
  rec = r
2073
  html = vi._render_exchange_review(rec)
2074
- pos = f"### Exchange {index + 1} of {len(records)}"
2075
- # very small stats
2076
- checked = sum(1 for x in records if (x.get("is_correct") if isinstance(x, dict) else getattr(x, "is_correct", None)) is not None)
2077
- stats = f"<div><strong>Reviewed:</strong> {checked}/{len(records)}</div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2078
  return html, pos, stats
2079
 
 
 
 
 
 
 
 
 
 
 
 
 
2080
  def _export_conv_records_to_json(meta: dict, records: list):
2081
  """Write reviewed conversation verification results to a JSON file and return its path."""
2082
  import json
@@ -2189,38 +2233,41 @@ To revert, use "Reset to Default" button.
2189
 
2190
  def _mark_conv_correct(records: list, idx: int):
2191
  if not records:
2192
- return records, idx, "", "", ""
2193
  idx = max(0, min(idx, len(records) - 1))
2194
  if isinstance(records[idx], dict):
2195
  records[idx]["is_correct"] = True
 
 
2196
  html, pos, stats = _render_conv_exchange(records, idx)
2197
- return records, idx, "✅ Marked correct", html, pos, stats
 
2198
 
2199
  def _mark_conv_incorrect(records: list, idx: int):
2200
  if not records:
2201
- return records, idx, "", "", ""
2202
  idx = max(0, min(idx, len(records) - 1))
2203
  if isinstance(records[idx], dict):
2204
  records[idx]["is_correct"] = False
2205
  html, pos, stats = _render_conv_exchange(records, idx)
2206
- return records, idx, "❌ Marked incorrect", html, pos, stats
 
2207
 
2208
  def _show_incorrect_comment_ui(records: list, idx: int):
2209
  """Mark incorrect and open the comment row, pre-filling any existing note."""
2210
- records, idx, status, html, pos, stats = _mark_conv_incorrect(records, idx)
2211
- note = ""
2212
- if records and isinstance(records[idx], dict):
2213
- note = records[idx].get("verifier_notes") or ""
2214
  return records, idx, status, html, pos, stats, gr.update(visible=True), note
2215
 
2216
  def _save_incorrect_comment(records: list, idx: int, note: str):
2217
  if not records:
2218
- return records, idx, "", "", "", gr.update(visible=False), ""
2219
  idx = max(0, min(idx, len(records) - 1))
2220
  if isinstance(records[idx], dict):
2221
  records[idx]["verifier_notes"] = (note or "").strip()
2222
  html, pos, stats = _render_conv_exchange(records, idx)
2223
- return records, idx, "💾 Comment saved", html, pos, stats, gr.update(visible=False)
 
 
2224
 
2225
  def _download_reviewed_json(meta: dict, records: list):
2226
  return _export_conv_records_to_json(meta, records)
@@ -2230,10 +2277,11 @@ To revert, use "Reset to Default" button.
2230
 
2231
  def _nav_conv(records: list, idx: int, delta: int):
2232
  if not records:
2233
- return idx, "", "", ""
2234
  idx = max(0, min(idx + delta, len(records) - 1))
2235
  html, pos, stats = _render_conv_exchange(records, idx)
2236
- return idx, html, pos, stats
 
2237
 
2238
  generate_conv_verification_btn.click(
2239
  _generate_conv_verification,
@@ -2256,7 +2304,16 @@ To revert, use "Reset to Default" button.
2256
  conv_correct_btn.click(
2257
  _mark_conv_correct,
2258
  inputs=[conv_verify_records, conv_verify_index],
2259
- outputs=[conv_verify_records, conv_verify_index, conv_verify_status, conv_verify_exchange, conv_position, conv_stats]
 
 
 
 
 
 
 
 
 
2260
  )
2261
 
2262
  conv_incorrect_btn.click(
@@ -2285,19 +2342,20 @@ To revert, use "Reset to Default" button.
2285
  conv_position,
2286
  conv_stats,
2287
  conv_incorrect_comment_row,
 
2288
  ]
2289
  )
2290
 
2291
  conv_prev_btn.click(
2292
  lambda records, idx: _nav_conv(records, idx, -1),
2293
  inputs=[conv_verify_records, conv_verify_index],
2294
- outputs=[conv_verify_index, conv_verify_exchange, conv_position, conv_stats]
2295
  )
2296
 
2297
  conv_next_btn.click(
2298
  lambda records, idx: _nav_conv(records, idx, 1),
2299
  inputs=[conv_verify_records, conv_verify_index],
2300
- outputs=[conv_verify_index, conv_verify_exchange, conv_position, conv_stats]
2301
  )
2302
 
2303
  # Refresh conversation stats
 
2071
  else:
2072
  rec = r
2073
  html = vi._render_exchange_review(rec)
2074
+ # status badge
2075
+ cur_is_correct = (r.get("is_correct") if isinstance(r, dict) else getattr(r, "is_correct", None))
2076
+ if cur_is_correct is True:
2077
+ badge = ""
2078
+ elif cur_is_correct is False:
2079
+ badge = "❌"
2080
+ else:
2081
+ badge = "⏳"
2082
+ pos = f"### {badge} Exchange {index + 1} of {len(records)}"
2083
+
2084
+ # richer stats
2085
+ reviewed = 0
2086
+ correct = 0
2087
+ incorrect = 0
2088
+ incorrect_with_comment = 0
2089
+ for x in records:
2090
+ v = (x.get("is_correct") if isinstance(x, dict) else getattr(x, "is_correct", None))
2091
+ if v is None:
2092
+ continue
2093
+ reviewed += 1
2094
+ if v is True:
2095
+ correct += 1
2096
+ else:
2097
+ incorrect += 1
2098
+ note = (x.get("verifier_notes") if isinstance(x, dict) else getattr(x, "verifier_notes", None))
2099
+ if note and str(note).strip():
2100
+ incorrect_with_comment += 1
2101
+
2102
+ stats = (
2103
+ "<div style='display:flex; gap:12px; flex-wrap:wrap;'>"
2104
+ f"<div><strong>Reviewed:</strong> {reviewed}/{len(records)}</div>"
2105
+ f"<div><strong>✅ Correct:</strong> {correct}</div>"
2106
+ f"<div><strong>❌ Incorrect:</strong> {incorrect}</div>"
2107
+ f"<div><strong>📝 Incorrect w/ comment:</strong> {incorrect_with_comment}</div>"
2108
+ "</div>"
2109
+ )
2110
  return html, pos, stats
2111
 
2112
+ def _comment_ui_state(records: list, idx: int):
2113
+ """Return (row_update, note_value) based on current record state."""
2114
+ if not records:
2115
+ return gr.update(visible=False), ""
2116
+ idx = max(0, min(idx, len(records) - 1))
2117
+ r = records[idx]
2118
+ is_incorrect = (r.get("is_correct") is False) if isinstance(r, dict) else (getattr(r, "is_correct", None) is False)
2119
+ if not is_incorrect:
2120
+ return gr.update(visible=False), ""
2121
+ note = (r.get("verifier_notes") or "") if isinstance(r, dict) else (getattr(r, "verifier_notes", "") or "")
2122
+ return gr.update(visible=True), str(note)
2123
+
2124
  def _export_conv_records_to_json(meta: dict, records: list):
2125
  """Write reviewed conversation verification results to a JSON file and return its path."""
2126
  import json
 
2233
 
2234
  def _mark_conv_correct(records: list, idx: int):
2235
  if not records:
2236
+ return records, idx, "", "", "", gr.update(visible=False), ""
2237
  idx = max(0, min(idx, len(records) - 1))
2238
  if isinstance(records[idx], dict):
2239
  records[idx]["is_correct"] = True
2240
+ # clear comment when marked correct (avoid stale notes)
2241
+ records[idx]["verifier_notes"] = ""
2242
  html, pos, stats = _render_conv_exchange(records, idx)
2243
+ row_upd, note_val = _comment_ui_state(records, idx)
2244
+ return records, idx, "✅ Marked correct", html, pos, stats, row_upd, note_val
2245
 
2246
  def _mark_conv_incorrect(records: list, idx: int):
2247
  if not records:
2248
+ return records, idx, "", "", "", gr.update(visible=False), ""
2249
  idx = max(0, min(idx, len(records) - 1))
2250
  if isinstance(records[idx], dict):
2251
  records[idx]["is_correct"] = False
2252
  html, pos, stats = _render_conv_exchange(records, idx)
2253
+ row_upd, note_val = _comment_ui_state(records, idx)
2254
+ return records, idx, "❌ Marked incorrect", html, pos, stats, row_upd, note_val
2255
 
2256
  def _show_incorrect_comment_ui(records: list, idx: int):
2257
  """Mark incorrect and open the comment row, pre-filling any existing note."""
2258
+ records, idx, status, html, pos, stats, _row, note = _mark_conv_incorrect(records, idx)
 
 
 
2259
  return records, idx, status, html, pos, stats, gr.update(visible=True), note
2260
 
2261
  def _save_incorrect_comment(records: list, idx: int, note: str):
2262
  if not records:
2263
+ return records, idx, "", "", "", "", gr.update(visible=False), ""
2264
  idx = max(0, min(idx, len(records) - 1))
2265
  if isinstance(records[idx], dict):
2266
  records[idx]["verifier_notes"] = (note or "").strip()
2267
  html, pos, stats = _render_conv_exchange(records, idx)
2268
+ row_upd, note_val = _comment_ui_state(records, idx)
2269
+ # keep row visible after save (since still incorrect)
2270
+ return records, idx, "💾 Comment saved", html, pos, stats, row_upd, note_val
2271
 
2272
  def _download_reviewed_json(meta: dict, records: list):
2273
  return _export_conv_records_to_json(meta, records)
 
2277
 
2278
  def _nav_conv(records: list, idx: int, delta: int):
2279
  if not records:
2280
+ return idx, "", "", "", gr.update(visible=False), ""
2281
  idx = max(0, min(idx + delta, len(records) - 1))
2282
  html, pos, stats = _render_conv_exchange(records, idx)
2283
+ row_upd, note_val = _comment_ui_state(records, idx)
2284
+ return idx, html, pos, stats, row_upd, note_val
2285
 
2286
  generate_conv_verification_btn.click(
2287
  _generate_conv_verification,
 
2304
  conv_correct_btn.click(
2305
  _mark_conv_correct,
2306
  inputs=[conv_verify_records, conv_verify_index],
2307
+ outputs=[
2308
+ conv_verify_records,
2309
+ conv_verify_index,
2310
+ conv_verify_status,
2311
+ conv_verify_exchange,
2312
+ conv_position,
2313
+ conv_stats,
2314
+ conv_incorrect_comment_row,
2315
+ conv_incorrect_comment,
2316
+ ]
2317
  )
2318
 
2319
  conv_incorrect_btn.click(
 
2342
  conv_position,
2343
  conv_stats,
2344
  conv_incorrect_comment_row,
2345
+ conv_incorrect_comment,
2346
  ]
2347
  )
2348
 
2349
  conv_prev_btn.click(
2350
  lambda records, idx: _nav_conv(records, idx, -1),
2351
  inputs=[conv_verify_records, conv_verify_index],
2352
+ outputs=[conv_verify_index, conv_verify_exchange, conv_position, conv_stats, conv_incorrect_comment_row, conv_incorrect_comment]
2353
  )
2354
 
2355
  conv_next_btn.click(
2356
  lambda records, idx: _nav_conv(records, idx, 1),
2357
  inputs=[conv_verify_records, conv_verify_index],
2358
+ outputs=[conv_verify_index, conv_verify_exchange, conv_position, conv_stats, conv_incorrect_comment_row, conv_incorrect_comment]
2359
  )
2360
 
2361
  # Refresh conversation stats