Anisha Bhatnagar commited on
Commit
9a097e7
Β·
1 Parent(s): 6aef776

triggering feature span caching on precomputed regions

Browse files
Files changed (2) hide show
  1. app.py +0 -2
  2. precompute_caches.py +36 -3
app.py CHANGED
@@ -428,8 +428,6 @@ def app(share=False):
428
  label="Precomputed Regions",
429
  info="Select a region to automatically zoom and analyze"
430
  )
431
- # Add a hidden HTML component for JavaScript execution
432
- js_trigger = gr.HTML(visible=False, elem_id="js-trigger")
433
 
434
 
435
  with gr.Row():
 
428
  label="Precomputed Regions",
429
  info="Select a region to automatically zoom and analyze"
430
  )
 
 
431
 
432
 
433
  with gr.Row():
precompute_caches.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import json
3
  import pickle
@@ -8,9 +9,8 @@ from datetime import datetime
8
  import yaml
9
 
10
  # Import your actual modules exactly as app.py does
11
- from utils.visualizations import get_instances, load_interp_space, compute_tsne_with_cache, compute_precomputed_regions
12
- from utils.ui import update_task_display, instance_to_df
13
- from utils.interp_space_utils import cached_generate_style_embedding, compute_g2v_features, compute_predicted_author
14
 
15
  def load_config(path="config/config.yaml"):
16
  with open(path, "r") as f:
@@ -132,6 +132,39 @@ def precompute_all_caches(
132
 
133
  print(f" βœ“ Instance {instance_id} with model {model_name} completed successfully")
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  except Exception as e:
136
  error_msg = f"Error processing instance {instance_id} with model {model_name}: {str(e)}"
137
  print(f" βœ— {error_msg}")
 
1
+ import ast
2
  import os
3
  import json
4
  import pickle
 
9
  import yaml
10
 
11
  # Import your actual modules exactly as app.py does
12
+ from utils.visualizations import get_instances, load_interp_space, trigger_precomputed_region, handle_zoom_with_retries
13
+ from utils.ui import update_task_display
 
14
 
15
  def load_config(path="config/config.yaml"):
16
  with open(path, "r") as f:
 
132
 
133
  print(f" βœ“ Instance {instance_id} with model {model_name} completed successfully")
134
 
135
+
136
+ print(" β†’ Testing region zoom simulation...")
137
+ if precomputed_regions_state:
138
+ regions_dict = ast.literal_eval(precomputed_regions_state)
139
+ test_regions = list(regions_dict.keys())
140
+
141
+ for region_name in test_regions:
142
+ try:
143
+ print(f" β†’ Testing region: {region_name}")
144
+
145
+ # Step 3a: Simulate region selection (trigger_precomputed_region)
146
+ zoom_payload = trigger_precomputed_region(region_name, regions_dict)
147
+
148
+ if zoom_payload: # Only proceed if we got a valid zoom payload
149
+ # Step 3b: Simulate axis_ranges.change() (handle_zoom_with_retries)
150
+ zoom_results = handle_zoom_with_retries(
151
+ event_json=zoom_payload,
152
+ bg_proj=bg_proj,
153
+ bg_lbls=bg_ids,
154
+ clustered_authors_df=background_authors_embeddings_df,
155
+ task_authors_df=task_authors_embeddings_df
156
+ )
157
+
158
+ # Extract results like app.py does
159
+ (features_rb_update, gram2vec_rb_update, llm_style_feats_analysis,
160
+ feature_list_state, visible_zoomed_authors) = zoom_results
161
+
162
+ print(f" βœ“ LLM features cached for region: {region_name}")
163
+
164
+ except Exception as e:
165
+ print(f" βœ— Failed to cache features for region {region_name}: {e}")
166
+ # Continue with other regions even if one fails
167
+ continue
168
  except Exception as e:
169
  error_msg = f"Error processing instance {instance_id} with model {model_name}: {str(e)}"
170
  print(f" βœ— {error_msg}")