beanapologist commited on
Commit
076d418
·
verified ·
1 Parent(s): 55a1dab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -18
app.py CHANGED
@@ -674,8 +674,11 @@ class TinyAgent:
674
  meta['source']='analytic'
675
  else:
676
  chosen_id=cnn_action_idx+1
677
- meta={'source':'cnn','probs':probs.tolist(),
678
- 'candidates':candidates[:4] if candidates else []}
 
 
 
679
 
680
  self.prev_feat=feat; self.prev_action=cnn_action_idx
681
  self.step_count+=1
@@ -787,22 +790,29 @@ def pull_frame():
787
 
788
  grid=data['grid']; meta=data['meta']; step=data['step']
789
  levels=data['levels']; state=data['state']; action=data['action']
790
- candidates=meta.get('candidates',[])
791
  source=meta.get('source','cnn')
 
 
 
 
 
 
 
 
 
 
 
 
 
792
 
793
  # Determine what to highlight
794
  mark_cell=None; highlight=None
795
- if source=='analytic' and 'cell' in meta:
796
- r,c,v=meta['cell']
797
- best_cand_name=meta.get('hypothesis','?')
798
- best_conf=meta.get('conf',0)
799
- # Compute Re-side diff for candidate
800
- cand_name,cand_grid,cand_conf=(candidates[0] if candidates
801
- else (best_cand_name,grid,best_conf))
802
  if cand_grid.shape==grid.shape:
803
  all_diffs=pixel_diff(grid,cand_grid)
804
- highlight=all_diffs[:20] # show up to 20 wrong cells in red
805
- mark_cell=meta['cell'] # cyan star on the cell we're clicking
806
 
807
  source_emoji='🧠' if source=='analytic' else '🎲'
808
  _latest['grid_img']=render_grid(
@@ -811,16 +821,20 @@ def pull_frame():
811
  highlight=highlight,
812
  mark_cell=mark_cell)
813
 
814
- # Im side: hypothesis ranking
815
- _latest['hyp_img']=render_hypothesis_panel(candidates)
 
 
 
 
816
 
817
- # Re side: candidate grid (what Im thinks the answer looks like)
818
- if candidates and candidates[0][1].shape==grid.shape:
819
- cname,cgrid,cconf=candidates[0]
820
  diffs=pixel_diff(grid,cgrid)
821
  _latest['cand_img']=render_grid(
822
  cgrid,
823
- title=f"Im candidate: {cname} (conf={cconf:.2f}) — {len(diffs)} cells differ",
824
  highlight=diffs[:20])
825
  else:
826
  _latest['cand_img']=None
 
674
  meta['source']='analytic'
675
  else:
676
  chosen_id=cnn_action_idx+1
677
+ # Package read_board result for display even in CNN fallback
678
+ cnn_cands=[(r, cand_answer, cand_conf)] if cand_answer is not None else []
679
+ meta={'source':'cnn','probs':probs.tolist(),'candidates':cnn_cands,
680
+ 'hypothesis':cand_reasoning[0][:60] if cand_reasoning else 'none',
681
+ 'conf':cand_conf,'n_diffs':len(pixel_diff(grid,cand_answer)) if cand_answer is not None else 0}
682
 
683
  self.prev_feat=feat; self.prev_action=cnn_action_idx
684
  self.step_count+=1
 
790
 
791
  grid=data['grid']; meta=data['meta']; step=data['step']
792
  levels=data['levels']; state=data['state']; action=data['action']
 
793
  source=meta.get('source','cnn')
794
+ hyp_str=meta.get('hypothesis','none')
795
+ cand_conf=meta.get('conf',0.0)
796
+ n_diffs=meta.get('n_diffs',0)
797
+
798
+ # Build display candidates list: [(label, grid, conf)]
799
+ raw_cands=meta.get('candidates',[])
800
+ # raw_cands entries are (reasoning_str, grid, conf)
801
+ # Normalise to (short_label, grid, conf)
802
+ disp_cands=[]
803
+ for entry in raw_cands:
804
+ if len(entry)==3:
805
+ label=str(entry[0])[:40]; cgrid=entry[1]; cconf=entry[2]
806
+ if isinstance(cgrid, np.ndarray): disp_cands.append((label,cgrid,cconf))
807
 
808
  # Determine what to highlight
809
  mark_cell=None; highlight=None
810
+ if source=='analytic' and 'cell' in meta and disp_cands:
811
+ _,cand_grid,_=disp_cands[0]
 
 
 
 
 
812
  if cand_grid.shape==grid.shape:
813
  all_diffs=pixel_diff(grid,cand_grid)
814
+ highlight=all_diffs[:20]
815
+ mark_cell=meta['cell']
816
 
817
  source_emoji='🧠' if source=='analytic' else '🎲'
818
  _latest['grid_img']=render_grid(
 
821
  highlight=highlight,
822
  mark_cell=mark_cell)
823
 
824
+ # Im side: hypothesis panel — show read_board reasoning as bar
825
+ if disp_cands:
826
+ # Convert to format render_hypothesis_panel expects: [(name,grid,conf)]
827
+ _latest['hyp_img']=render_hypothesis_panel(disp_cands)
828
+ else:
829
+ _latest['hyp_img']=None
830
 
831
+ # Re side: candidate grid
832
+ if disp_cands and disp_cands[0][1].shape==grid.shape:
833
+ cname,cgrid,cconf2=disp_cands[0]
834
  diffs=pixel_diff(grid,cgrid)
835
  _latest['cand_img']=render_grid(
836
  cgrid,
837
+ title=f"Im answer: {cname[:35]} (conf={cconf2:.2f}) — {len(diffs)} cells differ",
838
  highlight=diffs[:20])
839
  else:
840
  _latest['cand_img']=None