adarshcod30 commited on
Commit
12f38c5
·
verified ·
1 Parent(s): 1b84e30

Fix forced-grade display bug found by manually driving the demo

Browse files
Files changed (1) hide show
  1. src/drdetect/serve/demo.py +14 -1
src/drdetect/serve/demo.py CHANGED
@@ -18,15 +18,28 @@ __all__ = ["build_interface"]
18
 
19
 
20
  def _format_summary(result: PredictionResult) -> str:
 
 
 
 
 
 
 
 
 
21
  q = result.quality
22
  lines = [
23
  f"**Quality:** sharpness {q.sharpness:.0f} | brightness {q.mean_brightness:.0f} | "
24
  f"field-of-view {q.fov_fraction:.0%}"
25
  ]
26
  if not q.usable:
27
- lines.append("\n**REJECTED -- recapture requested.** Reasons:")
28
  lines.extend(f"- {r}" for r in q.reasons)
 
 
29
  return "\n".join(lines)
 
 
30
 
31
  calib_label = "temperature-scaled" if result.calibrated else "uncalibrated"
32
  lines.append(f"\n### Grade {result.grade}: {result.grade_name}")
 
18
 
19
 
20
  def _format_summary(result: PredictionResult) -> str:
21
+ """Real bug found manually driving the live Space (2026-09-07): this used
22
+ to branch on `not q.usable` alone, so checking "Grade anyway if quality
23
+ gate rejects" and forcing a real grade through (`result.grade` is not
24
+ None) still displayed only the rejection reasons and never the grade --
25
+ `run_pipeline` had computed it correctly, this function just never showed
26
+ it. Branching on `result.grade is None` instead handles both real cases:
27
+ genuinely no grade (rejected, not forced) and a forced grade on
28
+ known-poor-quality input (still shown, with the quality warning kept
29
+ visible above it rather than silently dropped)."""
30
  q = result.quality
31
  lines = [
32
  f"**Quality:** sharpness {q.sharpness:.0f} | brightness {q.mean_brightness:.0f} | "
33
  f"field-of-view {q.fov_fraction:.0%}"
34
  ]
35
  if not q.usable:
36
+ lines.append("\n**Quality gate flagged this image.** Reasons:")
37
  lines.extend(f"- {r}" for r in q.reasons)
38
+ if result.grade is None:
39
+ lines.insert(1, "\n**REJECTED -- recapture requested.**")
40
  return "\n".join(lines)
41
+ if not q.usable:
42
+ lines.append("\n**Graded anyway -- interpret with extra caution.**")
43
 
44
  calib_label = "temperature-scaled" if result.calibrated else "uncalibrated"
45
  lines.append(f"\n### Grade {result.grade}: {result.grade_name}")