Spaces:
Runtime error
Runtime error
frankaging
commited on
Commit
·
ace5a59
1
Parent(s):
e5ed67b
hande made
Browse files
app.py
CHANGED
|
@@ -155,31 +155,23 @@ def add_concept_to_list(selected_concept, user_slider_val, current_list):
|
|
| 155 |
"internal_mag": internal_mag,
|
| 156 |
}
|
| 157 |
# Add to the beginning of the list
|
| 158 |
-
|
| 159 |
-
return
|
| 160 |
-
|
| 161 |
-
def remove_concept_from_list(selected_text, current_list):
|
| 162 |
-
if not selected_text:
|
| 163 |
-
return current_list, gr.update(choices=_build_remove_choices(current_list))
|
| 164 |
-
|
| 165 |
-
# Remove based on the full formatted text
|
| 166 |
-
updated_list = [x for x in current_list if f"(+{x['display_mag']:.1f}*) {x['text']}" != selected_text]
|
| 167 |
-
return updated_list, gr.update(choices=_build_remove_choices(updated_list))
|
| 168 |
|
| 169 |
def update_dropdown_choices(search_text):
|
| 170 |
filtered = filter_concepts(search_text)
|
| 171 |
return gr.update(choices=filtered)
|
| 172 |
|
| 173 |
-
with gr.Blocks(
|
| 174 |
# Remove default subspaces
|
| 175 |
selected_subspaces = gr.State([])
|
| 176 |
|
| 177 |
-
with gr.Row():
|
| 178 |
# Left side: bigger chat area
|
| 179 |
with gr.Column(scale=7):
|
| 180 |
chat_interface = gr.ChatInterface(
|
| 181 |
fn=generate,
|
| 182 |
-
title="
|
| 183 |
description="Steer responses by selecting concepts on the right →",
|
| 184 |
type="messages",
|
| 185 |
additional_inputs=[selected_subspaces],
|
|
@@ -189,7 +181,7 @@ with gr.Blocks(theme='allenai/gradio-theme') as demo:
|
|
| 189 |
# Right side: concept management
|
| 190 |
with gr.Column(scale=3):
|
| 191 |
gr.Markdown("## Steer Model Responses")
|
| 192 |
-
gr.Markdown("Search and then
|
| 193 |
# Concept Search and Selection
|
| 194 |
with gr.Group():
|
| 195 |
search_box = gr.Textbox(
|
|
@@ -198,7 +190,7 @@ with gr.Blocks(theme='allenai/gradio-theme') as demo:
|
|
| 198 |
lines=2,
|
| 199 |
)
|
| 200 |
concept_dropdown = gr.Dropdown(
|
| 201 |
-
label="Select a
|
| 202 |
interactive=True,
|
| 203 |
)
|
| 204 |
concept_magnitude = gr.Slider(
|
|
@@ -208,17 +200,6 @@ with gr.Blocks(theme='allenai/gradio-theme') as demo:
|
|
| 208 |
step=0.1, # Allow 1 decimal point
|
| 209 |
value=3,
|
| 210 |
)
|
| 211 |
-
add_button = gr.Button("Add Concept to Steering")
|
| 212 |
-
|
| 213 |
-
# Current Steering Concepts
|
| 214 |
-
gr.Markdown("## Current Steering Concepts")
|
| 215 |
-
with gr.Group():
|
| 216 |
-
remove_dropdown = gr.Dropdown(
|
| 217 |
-
label="Select a Current Steering Concept to Stop Steering",
|
| 218 |
-
choices=[],
|
| 219 |
-
multiselect=False,
|
| 220 |
-
)
|
| 221 |
-
remove_button = gr.Button("Remove Current Steering Concept", variant="secondary")
|
| 222 |
|
| 223 |
# Wire up events
|
| 224 |
# When the search box changes, update the concept dropdown choices:
|
|
@@ -228,20 +209,16 @@ with gr.Blocks(theme='allenai/gradio-theme') as demo:
|
|
| 228 |
[concept_dropdown]
|
| 229 |
)
|
| 230 |
|
| 231 |
-
|
| 232 |
-
# and update the "Remove" dropdown choices.
|
| 233 |
-
add_button.click(
|
| 234 |
add_concept_to_list,
|
| 235 |
[concept_dropdown, concept_magnitude, selected_subspaces],
|
| 236 |
-
[selected_subspaces
|
| 237 |
)
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
[remove_dropdown, selected_subspaces],
|
| 244 |
-
[selected_subspaces, remove_dropdown]
|
| 245 |
)
|
| 246 |
|
| 247 |
demo.launch(share=True)
|
|
|
|
| 155 |
"internal_mag": internal_mag,
|
| 156 |
}
|
| 157 |
# Add to the beginning of the list
|
| 158 |
+
current_list = [new_entry]
|
| 159 |
+
return current_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
def update_dropdown_choices(search_text):
|
| 162 |
filtered = filter_concepts(search_text)
|
| 163 |
return gr.update(choices=filtered)
|
| 164 |
|
| 165 |
+
with gr.Blocks(fill_height=True) as demo:
|
| 166 |
# Remove default subspaces
|
| 167 |
selected_subspaces = gr.State([])
|
| 168 |
|
| 169 |
+
with gr.Row(min_height=700):
|
| 170 |
# Left side: bigger chat area
|
| 171 |
with gr.Column(scale=7):
|
| 172 |
chat_interface = gr.ChatInterface(
|
| 173 |
fn=generate,
|
| 174 |
+
title="Chat with a Concept Steering Model",
|
| 175 |
description="Steer responses by selecting concepts on the right →",
|
| 176 |
type="messages",
|
| 177 |
additional_inputs=[selected_subspaces],
|
|
|
|
| 181 |
# Right side: concept management
|
| 182 |
with gr.Column(scale=3):
|
| 183 |
gr.Markdown("## Steer Model Responses")
|
| 184 |
+
gr.Markdown("Search and then select a concept to steer the model.")
|
| 185 |
# Concept Search and Selection
|
| 186 |
with gr.Group():
|
| 187 |
search_box = gr.Textbox(
|
|
|
|
| 190 |
lines=2,
|
| 191 |
)
|
| 192 |
concept_dropdown = gr.Dropdown(
|
| 193 |
+
label="Select a concept to steer the model",
|
| 194 |
interactive=True,
|
| 195 |
)
|
| 196 |
concept_magnitude = gr.Slider(
|
|
|
|
| 200 |
step=0.1, # Allow 1 decimal point
|
| 201 |
value=3,
|
| 202 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
# Wire up events
|
| 205 |
# When the search box changes, update the concept dropdown choices:
|
|
|
|
| 209 |
[concept_dropdown]
|
| 210 |
)
|
| 211 |
|
| 212 |
+
concept_dropdown.select(
|
|
|
|
|
|
|
| 213 |
add_concept_to_list,
|
| 214 |
[concept_dropdown, concept_magnitude, selected_subspaces],
|
| 215 |
+
[selected_subspaces]
|
| 216 |
)
|
| 217 |
|
| 218 |
+
concept_magnitude.input(
|
| 219 |
+
add_concept_to_list,
|
| 220 |
+
[concept_dropdown, concept_magnitude, selected_subspaces],
|
| 221 |
+
[selected_subspaces]
|
|
|
|
|
|
|
| 222 |
)
|
| 223 |
|
| 224 |
demo.launch(share=True)
|