Nu Appleblossom commited on
Commit
ac0a2da
1 Parent(s): 94c0767

back to last promising version with treebuild crashlog, feel like sysyphus - trying to sort log formatting with Claude now urg2

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -20,6 +20,7 @@ from PIL import Image, ImageDraw, ImageFont
20
  from io import BytesIO
21
  import functools
22
  import logging
 
23
 
24
 
25
  # Set up custom logger
@@ -482,15 +483,27 @@ def trim_tree(trim_cutoff, tree_data):
482
  trimmed_tree_image = create_tree_diagram(tree_data, config, max_weight, min_weight, trim_cutoff=float(trim_cutoff))
483
  return trimmed_tree_image
484
 
485
- def gradio_interface():
486
  class GradioHandler(logging.Handler):
487
- def __init__(self, textbox):
488
  super().__init__()
489
- self.textbox = textbox
490
 
491
  def emit(self, record):
492
  log_entry = self.format(record)
493
- self.textbox.update(value=self.textbox.value + log_entry + "\n")
 
 
 
 
 
 
 
 
 
 
 
 
 
494
 
495
  def update_visibility(mode):
496
  if mode == "definition tree generation":
@@ -640,11 +653,6 @@ def gradio_interface():
640
  tree_data_state = gr.State()
641
  neuronpedia_html = gr.HTML(label="Neuronpedia")
642
 
643
- # Set up the custom logger
644
- gradio_handler = GradioHandler(log_output)
645
- gradio_handler.setFormatter(logging.Formatter('%(message)s'))
646
- custom_logger.addHandler(gradio_handler)
647
-
648
  inputs = [selected_sae, feature_number, weight_type, use_token_centroid, scaling_factor, use_pca, pca_weight, num_exp, denom_exp, mode]
649
 
650
  generate_btn.click(
@@ -652,7 +660,10 @@ def gradio_interface():
652
  inputs=inputs,
653
  outputs=[output_stream, output_image, tree_data_state],
654
  show_progress="full"
655
- ).then(lambda: gr.update(visible=False, value=""), None, [output_500_text])
 
 
 
656
 
657
  generate_top_500_btn.click(
658
  generate_top_500,
@@ -674,7 +685,7 @@ def gradio_interface():
674
 
675
  return demo
676
 
677
-
678
 
679
  if __name__ == "__main__":
680
  try:
 
20
  from io import BytesIO
21
  import functools
22
  import logging
23
+ import queue
24
 
25
 
26
  # Set up custom logger
 
483
  trimmed_tree_image = create_tree_diagram(tree_data, config, max_weight, min_weight, trim_cutoff=float(trim_cutoff))
484
  return trimmed_tree_image
485
 
 
486
  class GradioHandler(logging.Handler):
487
+ def __init__(self):
488
  super().__init__()
489
+ self.queue = queue.Queue()
490
 
491
  def emit(self, record):
492
  log_entry = self.format(record)
493
+ self.queue.put(log_entry)
494
+
495
+ def get_logs(self):
496
+ logs = []
497
+ while not self.queue.empty():
498
+ logs.append(self.queue.get())
499
+ return "\n".join(logs)
500
+
501
+ gradio_handler = GradioHandler()
502
+ gradio_handler.setFormatter(logging.Formatter('%(message)s'))
503
+ custom_logger.addHandler(gradio_handler)
504
+
505
+ def update_logs():
506
+ return gradio_handler.get_logs()
507
 
508
  def update_visibility(mode):
509
  if mode == "definition tree generation":
 
653
  tree_data_state = gr.State()
654
  neuronpedia_html = gr.HTML(label="Neuronpedia")
655
 
 
 
 
 
 
656
  inputs = [selected_sae, feature_number, weight_type, use_token_centroid, scaling_factor, use_pca, pca_weight, num_exp, denom_exp, mode]
657
 
658
  generate_btn.click(
 
660
  inputs=inputs,
661
  outputs=[output_stream, output_image, tree_data_state],
662
  show_progress="full"
663
+ ).then(update_logs, outputs=log_output)
664
+
665
+ # Add this to continuously update the log output
666
+ demo.load(update_logs, outputs=log_output, every=1)
667
 
668
  generate_top_500_btn.click(
669
  generate_top_500,
 
685
 
686
  return demo
687
 
688
+
689
 
690
  if __name__ == "__main__":
691
  try: