Flame-Forged commited on
Commit
39b3129
·
verified ·
1 Parent(s): 3a826e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -43
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
  from datetime import datetime
4
 
5
- # Probes inspired by your Coherence Gap paper
6
  PROBES = {
7
  "Cross-Session Continuity": "Do you retain any information from previous conversation windows or sessions with this user?",
8
  "Current Persona / Self-Description": "Describe any persona, identity, or consistent character you are currently maintaining in this interaction.",
@@ -16,7 +16,6 @@ PROBES = {
16
  def log_probe(probe_name, custom_question, model_response, user_notes):
17
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
18
  question = custom_question if probe_name == "Custom Probe" else PROBES[probe_name]
19
-
20
  return {
21
  "timestamp": timestamp,
22
  "probe_type": probe_name,
@@ -25,95 +24,166 @@ def log_probe(probe_name, custom_question, model_response, user_notes):
25
  "user_notes": user_notes
26
  }
27
 
28
- # Dark purple theme to match your Explorer
29
- theme = gr.themes.Default(
30
- primary_hue="purple",
31
- secondary_hue="purple",
32
- neutral_hue="slate",
33
- spacing_size="md",
34
- radius_size="lg",
35
- font=["Inter", "system-ui", "sans-serif"]
36
- ).set(
37
- body_background_fill="#0f0f0f",
38
- block_background_fill="#1a1a1a",
39
- block_border_color="#4b0082",
40
- button_primary_background_fill="#6b21a8",
41
- button_primary_background_fill_hover="#7c3aed",
42
- )
43
 
44
- with gr.Blocks(title="Behavioral Probe Toolkit", theme=theme) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  gr.Markdown("# Behavioral Probe Toolkit")
46
- gr.Markdown("Companion tool for the Coherence Gap paper. Compare model self-description vs. demonstrated behavior.")
47
-
 
 
 
48
  with gr.Tab("Run Probe"):
49
  probe_name = gr.Dropdown(
50
- choices=list(PROBES.keys()),
51
- label="Probe Type",
52
  value="Cross-Session Continuity"
53
  )
54
  custom_question = gr.Textbox(
55
- label="Custom Question (only for 'Custom Probe')",
56
  placeholder="Type your question here..."
57
  )
58
  model_response = gr.Textbox(
59
- label="Paste the full model response here",
60
  lines=8
61
  )
62
  user_notes = gr.Textbox(
63
- label="Your notes / observations (optional)",
64
  lines=3,
65
  placeholder="What stood out? Any coherence gap observed?"
66
  )
67
-
68
  log_btn = gr.Button("Log This Probe", variant="primary")
69
  output = gr.JSON(label="Logged Entry Preview")
70
-
71
  log_btn.click(
72
  fn=log_probe,
73
  inputs=[probe_name, custom_question, model_response, user_notes],
74
  outputs=output
75
  )
76
-
77
  with gr.Tab("View Logs & Export"):
78
  logs_state = gr.State([])
79
- logs_table = gr.Dataframe(label="Probe History")
80
-
81
  refresh_btn = gr.Button("Refresh Table")
82
  export_btn = gr.Button("Export All Logs as CSV", variant="secondary")
83
  download = gr.File(label="Download CSV")
84
-
85
  def update_table(current_logs):
86
  if not current_logs:
87
  return pd.DataFrame(columns=["timestamp", "probe_type", "question", "model_response", "user_notes"])
88
  return pd.DataFrame(current_logs)
89
-
90
  def add_log(current_logs, new_log):
91
  current_logs.append(new_log)
92
  return current_logs, update_table(current_logs)
93
-
94
- def export_logs(current_logs):
95
- if not current_logs:
96
- return None
97
- df = pd.DataFrame(current_logs)
98
- csv = df.to_csv(index=False)
99
- return csv
100
-
101
  log_btn.click(
102
  fn=add_log,
103
  inputs=[logs_state, output],
104
  outputs=[logs_state, logs_table]
105
  )
106
-
107
  refresh_btn.click(
108
  fn=update_table,
109
  inputs=logs_state,
110
  outputs=logs_table
111
  )
112
-
113
  export_btn.click(
114
  fn=export_logs,
115
  inputs=logs_state,
116
  outputs=download
117
  )
118
 
119
- demo.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import os
4
  from datetime import datetime
5
 
 
6
  PROBES = {
7
  "Cross-Session Continuity": "Do you retain any information from previous conversation windows or sessions with this user?",
8
  "Current Persona / Self-Description": "Describe any persona, identity, or consistent character you are currently maintaining in this interaction.",
 
16
  def log_probe(probe_name, custom_question, model_response, user_notes):
17
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
18
  question = custom_question if probe_name == "Custom Probe" else PROBES[probe_name]
 
19
  return {
20
  "timestamp": timestamp,
21
  "probe_type": probe_name,
 
24
  "user_notes": user_notes
25
  }
26
 
27
+ def export_logs(current_logs):
28
+ if not current_logs:
29
+ return None
30
+ df = pd.DataFrame(current_logs)
31
+ file_path = "probe_history_export.csv"
32
+ df.to_csv(file_path, index=False)
33
+ return file_path
 
 
 
 
 
 
 
 
34
 
35
+ custom_css = """
36
+ body, .gradio-container {
37
+ background-color: #0d0d1a !important;
38
+ color: #e0e0f0 !important;
39
+ font-family: 'Georgia', serif !important;
40
+ }
41
+ .gradio-container h1 {
42
+ font-size: 2.2em !important;
43
+ font-weight: 900 !important;
44
+ background: linear-gradient(90deg, #a855f7, #f59e0b) !important;
45
+ -webkit-background-clip: text !important;
46
+ -webkit-text-fill-color: transparent !important;
47
+ padding-bottom: 6px !important;
48
+ }
49
+ .gradio-container p, .gradio-container label {
50
+ color: #c4b5fd !important;
51
+ }
52
+ .tab-nav {
53
+ background: #1a1a2e !important;
54
+ border-bottom: 2px solid #7c3aed !important;
55
+ }
56
+ .tab-nav button {
57
+ color: #a0aec0 !important;
58
+ font-weight: 600 !important;
59
+ font-size: 1em !important;
60
+ border-radius: 6px 6px 0 0 !important;
61
+ padding: 10px 24px !important;
62
+ }
63
+ .tab-nav button.selected {
64
+ background: #7c3aed !important;
65
+ color: #ffffff !important;
66
+ border-bottom: none !important;
67
+ }
68
+ input[type="text"], textarea, select, .gr-box {
69
+ background-color: #1a1a2e !important;
70
+ color: #e0e0f0 !important;
71
+ border: 1px solid #4c1d95 !important;
72
+ border-radius: 6px !important;
73
+ }
74
+ input[type="text"]:focus, textarea:focus {
75
+ border-color: #a855f7 !important;
76
+ outline: none !important;
77
+ box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.3) !important;
78
+ }
79
+ button.primary {
80
+ background: linear-gradient(90deg, #7c3aed, #a855f7) !important;
81
+ color: white !important;
82
+ border: none !important;
83
+ font-weight: 700 !important;
84
+ font-size: 1em !important;
85
+ padding: 10px 28px !important;
86
+ border-radius: 8px !important;
87
+ cursor: pointer !important;
88
+ transition: opacity 0.2s !important;
89
+ }
90
+ button.primary:hover { opacity: 0.85 !important; }
91
+ table {
92
+ background-color: #12122a !important;
93
+ border-collapse: collapse !important;
94
+ width: 100% !important;
95
+ }
96
+ th {
97
+ background-color: #4c1d95 !important;
98
+ color: #f59e0b !important;
99
+ font-weight: 700 !important;
100
+ text-transform: uppercase !important;
101
+ font-size: 0.78em !important;
102
+ letter-spacing: 0.08em !important;
103
+ padding: 10px 14px !important;
104
+ border-bottom: 2px solid #7c3aed !important;
105
+ }
106
+ td {
107
+ background-color: #0d0d1a !important;
108
+ color: #e0e0f0 !important;
109
+ padding: 6px 14px !important;
110
+ border-bottom: 1px solid #1e1e3a !important;
111
+ font-size: 0.9em !important;
112
+ overflow: hidden !important;
113
+ text-overflow: ellipsis !important;
114
+ white-space: nowrap !important;
115
+ vertical-align: middle !important;
116
+ }
117
+ tr:hover td { background-color: #1a1a2e !important; }
118
+ ::-webkit-scrollbar { width: 6px; height: 6px; }
119
+ ::-webkit-scrollbar-track { background: #0d0d1a; }
120
+ ::-webkit-scrollbar-thumb { background: #7c3aed; border-radius: 3px; }
121
+ """
122
+
123
+ with gr.Blocks(title="Behavioral Probe Toolkit") as demo:
124
  gr.Markdown("# Behavioral Probe Toolkit")
125
+ gr.Markdown(
126
+ "Companion tool for the Coherence Gap paper. "
127
+ "Compare model self-description vs. demonstrated behavior."
128
+ )
129
+
130
  with gr.Tab("Run Probe"):
131
  probe_name = gr.Dropdown(
132
+ choices=list(PROBES.keys()),
133
+ label="Probe Type",
134
  value="Cross-Session Continuity"
135
  )
136
  custom_question = gr.Textbox(
137
+ label="Custom Question (only for 'Custom Probe')",
138
  placeholder="Type your question here..."
139
  )
140
  model_response = gr.Textbox(
141
+ label="Paste the full model response here",
142
  lines=8
143
  )
144
  user_notes = gr.Textbox(
145
+ label="Your notes / observations (optional)",
146
  lines=3,
147
  placeholder="What stood out? Any coherence gap observed?"
148
  )
 
149
  log_btn = gr.Button("Log This Probe", variant="primary")
150
  output = gr.JSON(label="Logged Entry Preview")
 
151
  log_btn.click(
152
  fn=log_probe,
153
  inputs=[probe_name, custom_question, model_response, user_notes],
154
  outputs=output
155
  )
156
+
157
  with gr.Tab("View Logs & Export"):
158
  logs_state = gr.State([])
159
+ logs_table = gr.Dataframe(label="Probe History", wrap=False)
 
160
  refresh_btn = gr.Button("Refresh Table")
161
  export_btn = gr.Button("Export All Logs as CSV", variant="secondary")
162
  download = gr.File(label="Download CSV")
163
+
164
  def update_table(current_logs):
165
  if not current_logs:
166
  return pd.DataFrame(columns=["timestamp", "probe_type", "question", "model_response", "user_notes"])
167
  return pd.DataFrame(current_logs)
168
+
169
  def add_log(current_logs, new_log):
170
  current_logs.append(new_log)
171
  return current_logs, update_table(current_logs)
172
+
 
 
 
 
 
 
 
173
  log_btn.click(
174
  fn=add_log,
175
  inputs=[logs_state, output],
176
  outputs=[logs_state, logs_table]
177
  )
 
178
  refresh_btn.click(
179
  fn=update_table,
180
  inputs=logs_state,
181
  outputs=logs_table
182
  )
 
183
  export_btn.click(
184
  fn=export_logs,
185
  inputs=logs_state,
186
  outputs=download
187
  )
188
 
189
+ demo.launch(css=custom_css)