neuralworm commited on
Commit
b652405
·
verified ·
1 Parent(s): 83e5da9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -30
app.py CHANGED
@@ -24,40 +24,45 @@ def run_single_analysis_display(*args, progress=gr.Progress(track_tqdm=True)):
24
  cleanup_memory()
25
 
26
  def run_auto_suite_display(model_id, num_steps, seed, experiment_name, progress=gr.Progress(track_tqdm=True)):
27
- """Wrapper, der die speziellen Plots für die verschiedenen Experimente handhaben kann."""
28
  try:
29
  summary_df, plot_df, all_results = run_auto_suite(model_id, int(num_steps), int(seed), experiment_name, progress)
30
 
31
- dataframe_component = gr.DataFrame(label="Comparative Statistical Signature", value=summary_df, wrap=True, row_count=(len(summary_df), "dynamic"))
32
 
33
- # FINALE KORREKTUR: Robuste Plot-Parameter-Logik
34
  plot_params = {
35
- "title": "Comparative Cognitive Dynamics",
36
- "color_legend_position": "bottom", "show_label": True, "height": 400, "interactive": True
37
  }
 
 
 
 
38
 
39
- if experiment_name == "ACT Titration (Point of No Return)":
40
- plot_params.update({
41
- "x": "Patch Step", "y": "Post-Patch Mean Delta", "color": None,
42
- "title": "Attractor Capture Time (ACT) - Phase Transition", "mark": "line",
43
- "color_legend_title": None,
44
- })
45
- elif experiment_name == "Mechanistic Probe (Attention Entropies)":
46
- plot_params.update({
47
- "x": "Step", "y": "Value", "color": "Metric",
48
- "title": "Mechanistic Analysis: State Delta vs. Attention Entropy",
49
- "color_legend_title": "Metric",
50
- })
51
- else: # Default für alle anderen Multi-Lauf-Experimente
52
- plot_params.update({
53
- "x": "Step", "y": "Delta", "color": "Experiment",
54
- "color_legend_title": "Experiment Runs",
55
- })
56
 
57
- new_plot = gr.LinePlot(value=plot_df, **plot_params)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  serializable_results = json.dumps(all_results, indent=2, default=str)
60
- return dataframe_component, new_plot, serializable_results
61
  finally:
62
  cleanup_memory()
63
 
@@ -98,7 +103,7 @@ with gr.Blocks(theme=theme, title="Cognitive Seismograph 2.3") as demo:
98
  with gr.Row(variant='panel'):
99
  with gr.Column(scale=1):
100
  gr.Markdown("### Auto-Experiment Parameters")
101
- auto_model_id = gr.Textbox(value="google/gemma-3-1b-it", label="Model ID")
102
  auto_num_steps = gr.Slider(50, 1000, 300, step=10, label="Steps per Run")
103
  auto_seed = gr.Slider(1, 1000, 42, step=1, label="Seed")
104
  auto_experiment_name = gr.Dropdown(
@@ -110,17 +115,19 @@ with gr.Blocks(theme=theme, title="Cognitive Seismograph 2.3") as demo:
110
 
111
  with gr.Column(scale=2):
112
  gr.Markdown("### Suite Results Summary")
113
- # Initialisiere den Plot mit den Default-Parametern
114
- auto_plot_output = gr.LinePlot(x="Step", y="Delta", color="Experiment", title="Comparative Cognitive Dynamics")
115
- auto_summary_df = gr.DataFrame(label="Comparative Statistical Signature", wrap=True)
 
 
116
  with gr.Accordion("Raw JSON for all runs", open=False):
117
  auto_raw_json = gr.JSON()
118
 
119
  auto_run_btn.click(
120
  fn=run_auto_suite_display,
121
  inputs=[auto_model_id, auto_num_steps, auto_seed, auto_experiment_name],
122
- outputs=[auto_summary_df, auto_plot_output, auto_raw_json]
123
  )
124
 
125
  if __name__ == "__main__":
126
- demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)
 
24
  cleanup_memory()
25
 
26
  def run_auto_suite_display(model_id, num_steps, seed, experiment_name, progress=gr.Progress(track_tqdm=True)):
27
+ """Wrapper, der nun auch die Frequenz-Spektrum-Plots anzeigen kann."""
28
  try:
29
  summary_df, plot_df, all_results = run_auto_suite(model_id, int(num_steps), int(seed), experiment_name, progress)
30
 
31
+ dataframe_component = gr.DataFrame(label="Comparative Signature (incl. Signal Metrics)", value=summary_df, wrap=True, row_count=(len(summary_df), "dynamic"))
32
 
33
+ # Erzeuge den primären Zeitreihen-Plot
34
  plot_params = {
35
+ "title": "Comparative Cognitive Dynamics (Time Domain)",
36
+ "color_legend_position": "bottom", "show_label": True, "height": 300, "interactive": True
37
  }
38
+ if experiment_name == "Mechanistic Probe (Attention Entropies)":
39
+ plot_params.update({"x": "Step", "y": "Value", "color": "Metric", "color_legend_title": "Metric"})
40
+ else:
41
+ plot_params.update({"x": "Step", "y": "Delta", "color": "Experiment", "color_legend_title": "Experiment Runs"})
42
 
43
+ time_domain_plot = gr.LinePlot(value=plot_df, **plot_params)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ # Erzeuge den Frequenz-Spektrum-Plot
46
+ spectrum_data = []
47
+ for label, result in all_results.items():
48
+ if "power_spectrum" in result:
49
+ spectrum = result["power_spectrum"]
50
+ for freq, power in zip(spectrum["frequencies"], spectrum["power"]):
51
+ if freq > 0.001:
52
+ spectrum_data.append({"Frequency": freq, "Power": power, "Experiment": label})
53
+
54
+ spectrum_df = pd.DataFrame(spectrum_data)
55
+
56
+ spectrum_plot_params = {
57
+ "x": "Frequency", "y": "Power", "color": "Experiment",
58
+ "title": "Cognitive Frequency Fingerprint (Frequency Domain)", "height": 300,
59
+ "color_legend_position": "bottom", "show_label": True, "interactive": True,
60
+ "color_legend_title": "Experiment Runs",
61
+ }
62
+ frequency_domain_plot = gr.LinePlot(value=spectrum_df, **spectrum_plot_params)
63
 
64
  serializable_results = json.dumps(all_results, indent=2, default=str)
65
+ return dataframe_component, time_domain_plot, frequency_domain_plot, serializable_results
66
  finally:
67
  cleanup_memory()
68
 
 
103
  with gr.Row(variant='panel'):
104
  with gr.Column(scale=1):
105
  gr.Markdown("### Auto-Experiment Parameters")
106
+ auto_model_id = gr.Textbox(value="google/gemma-3-12b-it", label="Model ID")
107
  auto_num_steps = gr.Slider(50, 1000, 300, step=10, label="Steps per Run")
108
  auto_seed = gr.Slider(1, 1000, 42, step=1, label="Seed")
109
  auto_experiment_name = gr.Dropdown(
 
115
 
116
  with gr.Column(scale=2):
117
  gr.Markdown("### Suite Results Summary")
118
+ auto_summary_df = gr.DataFrame(label="Comparative Signature (incl. Signal Metrics)", wrap=True)
119
+ with gr.Row():
120
+ auto_time_plot_output = gr.LinePlot()
121
+ auto_freq_plot_output = gr.LinePlot()
122
+
123
  with gr.Accordion("Raw JSON for all runs", open=False):
124
  auto_raw_json = gr.JSON()
125
 
126
  auto_run_btn.click(
127
  fn=run_auto_suite_display,
128
  inputs=[auto_model_id, auto_num_steps, auto_seed, auto_experiment_name],
129
+ outputs=[auto_summary_df, auto_time_plot_output, auto_freq_plot_output, auto_raw_json]
130
  )
131
 
132
  if __name__ == "__main__":
133
+ demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)