Spaces:
Sleeping
Sleeping
Nu Appleblossom
commited on
Commit
•
94c0767
1
Parent(s):
1adbb01
back to last promising version with treebuild crashlog, feel like sysyphus - trying to sort log formatting with Claude now urg
Browse files
app.py
CHANGED
@@ -483,11 +483,20 @@ def trim_tree(trim_cutoff, tree_data):
|
|
483 |
return trimmed_tree_image
|
484 |
|
485 |
def gradio_interface():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
def update_visibility(mode):
|
487 |
if mode == "definition tree generation":
|
488 |
-
return gr.update(visible=True), gr.update(visible=
|
489 |
else:
|
490 |
-
return gr.update(visible=True), gr.update(visible=
|
491 |
|
492 |
def update_neuronpedia(selected_sae, feature_number):
|
493 |
layer_number = int(selected_sae.split()[-1])
|
@@ -626,9 +635,16 @@ def gradio_interface():
|
|
626 |
trim_slider = gr.Slider(minimum=0.00001, maximum=0.1, value=0.00001, label="Trim cutoff for cumulative probability", visible=False)
|
627 |
trim_btn = gr.Button("Trim Tree", visible=False)
|
628 |
|
|
|
|
|
629 |
tree_data_state = gr.State()
|
630 |
neuronpedia_html = gr.HTML(label="Neuronpedia")
|
631 |
|
|
|
|
|
|
|
|
|
|
|
632 |
inputs = [selected_sae, feature_number, weight_type, use_token_centroid, scaling_factor, use_pca, pca_weight, num_exp, denom_exp, mode]
|
633 |
|
634 |
generate_btn.click(
|
@@ -647,17 +663,15 @@ def gradio_interface():
|
|
647 |
|
648 |
trim_btn.click(trim_tree, inputs=[trim_slider, tree_data_state], outputs=[output_image])
|
649 |
|
650 |
-
mode.change(
|
|
|
|
|
|
|
|
|
651 |
|
652 |
selected_sae.change(update_neuronpedia, inputs=[selected_sae, feature_number], outputs=[neuronpedia_html])
|
653 |
feature_number.change(update_neuronpedia, inputs=[selected_sae, feature_number], outputs=[neuronpedia_html])
|
654 |
|
655 |
-
output_stream.change(
|
656 |
-
lambda text: (gr.update(visible=True), gr.update(visible=True)) if "100 tokens" in text else (gr.update(visible=False), gr.update(visible=False)),
|
657 |
-
inputs=[output_stream],
|
658 |
-
outputs=[generate_top_500_btn, output_500_text]
|
659 |
-
)
|
660 |
-
|
661 |
return demo
|
662 |
|
663 |
|
|
|
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":
|
497 |
+
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
498 |
else:
|
499 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)
|
500 |
|
501 |
def update_neuronpedia(selected_sae, feature_number):
|
502 |
layer_number = int(selected_sae.split()[-1])
|
|
|
635 |
trim_slider = gr.Slider(minimum=0.00001, maximum=0.1, value=0.00001, label="Trim cutoff for cumulative probability", visible=False)
|
636 |
trim_btn = gr.Button("Trim Tree", visible=False)
|
637 |
|
638 |
+
log_output = gr.Textbox(label="Log Output", lines=20, visible=False)
|
639 |
+
|
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(
|
|
|
663 |
|
664 |
trim_btn.click(trim_tree, inputs=[trim_slider, tree_data_state], outputs=[output_image])
|
665 |
|
666 |
+
mode.change(
|
667 |
+
update_visibility,
|
668 |
+
inputs=[mode],
|
669 |
+
outputs=[output_stream, output_image, trim_slider, trim_btn, generate_top_500_btn, log_output]
|
670 |
+
)
|
671 |
|
672 |
selected_sae.change(update_neuronpedia, inputs=[selected_sae, feature_number], outputs=[neuronpedia_html])
|
673 |
feature_number.change(update_neuronpedia, inputs=[selected_sae, feature_number], outputs=[neuronpedia_html])
|
674 |
|
|
|
|
|
|
|
|
|
|
|
|
|
675 |
return demo
|
676 |
|
677 |
|