|
|
import gradio as gr |
|
|
import pandas as pd |
|
|
import traceback |
|
|
import sys |
|
|
|
|
|
from cognitive_mapping_probe.orchestrator_seismograph import run_seismic_analysis |
|
|
from cognitive_mapping_probe.prompts import RESONANCE_PROMPTS |
|
|
from cognitive_mapping_probe.utils import dbg |
|
|
|
|
|
|
|
|
theme = gr.themes.Soft(primary_hue="indigo", secondary_hue="blue").set( |
|
|
body_background_fill="#f0f4f9", |
|
|
block_background_fill="white", |
|
|
) |
|
|
|
|
|
def run_and_display( |
|
|
model_id: str, |
|
|
prompt_type: str, |
|
|
seed: int, |
|
|
num_steps: int, |
|
|
progress=gr.Progress(track_tqdm=True) |
|
|
): |
|
|
""" |
|
|
Führt die neue seismische Analyse durch und visualisiert die internen Dynamiken. |
|
|
""" |
|
|
try: |
|
|
results = run_seismic_analysis( |
|
|
model_id, prompt_type, int(seed), int(num_steps), progress |
|
|
) |
|
|
|
|
|
verdict = results.get("verdict", "Analysis complete.") |
|
|
stats = results.get("stats", {}) |
|
|
deltas = results.get("state_deltas", []) |
|
|
|
|
|
|
|
|
df = pd.DataFrame({ |
|
|
"Internal Step": range(len(deltas)), |
|
|
"State Change (Delta)": deltas |
|
|
}) |
|
|
|
|
|
|
|
|
stats_md = f"### Statistical Signature\n" |
|
|
stats_md += f"- **Mean Delta:** {stats.get('mean_delta', 0):.4f} (Avg. cognitive activity)\n" |
|
|
stats_md += f"- **Std Dev Delta:** {stats.get('std_delta', 0):.4f} (Volatility of thought)\n" |
|
|
stats_md += f"- **Max Delta:** {stats.get('max_delta', 0):.4f} (Peak cognitive shift)\n" |
|
|
|
|
|
return f"{verdict}\n\n{stats_md}", df, results |
|
|
|
|
|
except Exception: |
|
|
error_str = traceback.format_exc() |
|
|
return f"### ❌ Analysis Failed\nAn unexpected error occurred:\n\n```\n{error_str}\n```", pd.DataFrame(), {} |
|
|
|
|
|
|
|
|
with gr.Blocks(theme=theme, title="Cognitive Seismograph") as demo: |
|
|
gr.Markdown("# 🧠 Cognitive Seismograph: Visualizing Internal Dynamics") |
|
|
gr.Markdown( |
|
|
"**Neues Paradigma:** Wir akzeptieren, dass der 'stille Denkprozess' nicht konvergiert. Stattdessen messen und visualisieren wir die **Signatur der internen Dynamik** – ein EKG für den Denkprozess des Modells." |
|
|
) |
|
|
with gr.Row(variant='panel'): |
|
|
with gr.Column(scale=1): |
|
|
gr.Markdown("### Parameters") |
|
|
model_id_input = gr.Textbox(value="google/gemma-3-1b-it", label="Model ID") |
|
|
prompt_type_input = gr.Radio( |
|
|
choices=list(RESONANCE_PROMPTS.keys()), |
|
|
value="control_long_prose", |
|
|
label="Prompt Type (Cognitive Load)" |
|
|
) |
|
|
seed_input = gr.Slider(1, 1000, 42, step=1, label="Seed") |
|
|
num_steps_input = gr.Slider(50, 1000, 300, step=10, label="Number of Internal Steps") |
|
|
run_btn = gr.Button("Run Seismic Analysis", variant="primary") |
|
|
|
|
|
with gr.Column(scale=2): |
|
|
gr.Markdown("### Results") |
|
|
verdict_output = gr.Markdown("Die Analyse der Dynamik erscheint hier.") |
|
|
plot_output = gr.LinePlot( |
|
|
x="Internal Step", |
|
|
y="State Change (Delta)", |
|
|
title="Internal State Dynamics (Cognitive EKG)", |
|
|
show_label=True, |
|
|
height=400, |
|
|
) |
|
|
with gr.Accordion("Raw JSON Output", open=False): |
|
|
raw_json_output = gr.JSON() |
|
|
|
|
|
run_btn.click( |
|
|
fn=run_and_display, |
|
|
inputs=[model_id_input, prompt_type_input, seed_input, num_steps_input], |
|
|
outputs=[verdict_output, plot_output, raw_json_output] |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
print("="*80) |
|
|
print("🔬 COGNITIVE SEISMOGRAPH INITIALIZED") |
|
|
print("="*80) |
|
|
print("Das experimentelle Paradigma wurde aufgrund der Falsifikation der Konvergenz-Hypothese geändert.") |
|
|
print("Wir messen nun die Dynamik des nicht-konvergenten Zustands.") |
|
|
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True) |
|
|
|