cyberandy commited on
Commit
32ab5e4
·
verified ·
1 Parent(s): bc664e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -42,8 +42,9 @@ def create_dashboard(feature_id: int, model: Model) -> str:
42
  </div>
43
  """
44
 
45
- def handle_feature_click(feature_id: int, model: Model):
46
- return create_dashboard(feature_id, model)
 
47
 
48
  def analyze_text(text: str, selected_model: str):
49
  model = Model.GEMMA if selected_model == "Gemini" else Model.GPT2
@@ -151,7 +152,24 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
151
  )
152
 
153
  with gr.Column(scale=2):
154
- features_list = gr.JSON(label="Features", visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  dashboard = gr.HTML()
156
 
157
  def update_and_analyze(text, model):
 
42
  </div>
43
  """
44
 
45
+ def handle_feature_click(feature_id: int, model: str):
46
+ selected_model = Model.GEMMA if model == "Gemini" else Model.GPT2
47
+ return create_dashboard(feature_id, selected_model)
48
 
49
  def analyze_text(text: str, selected_model: str):
50
  model = Model.GEMMA if selected_model == "Gemini" else Model.GPT2
 
152
  )
153
 
154
  with gr.Column(scale=2):
155
+ @gr.render(inputs=[features_state, current_model])
156
+ def render_features(features, model):
157
+ if not features:
158
+ return
159
+
160
+ for token_group in features:
161
+ gr.Markdown(f"### {token_group['token']}")
162
+ with gr.Row():
163
+ for feature in token_group['features']:
164
+ btn = gr.Button(
165
+ f"Feature {feature['id']} (Activation: {feature['activation']:.2f})",
166
+ elem_classes=["feature-button"]
167
+ )
168
+ btn.click(
169
+ fn=lambda fid=feature['id']: handle_feature_click(fid, model),
170
+ outputs=dashboard
171
+ )
172
+
173
  dashboard = gr.HTML()
174
 
175
  def update_and_analyze(text, model):