frankaging commited on
Commit
7de2513
·
1 Parent(s): ace5a59

hande made

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -160,7 +160,14 @@ def add_concept_to_list(selected_concept, user_slider_val, 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
@@ -181,7 +188,7 @@ with gr.Blocks(fill_height=True) as demo:
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(
@@ -192,21 +199,26 @@ with gr.Blocks(fill_height=True) as demo:
192
  concept_dropdown = gr.Dropdown(
193
  label="Select a concept to steer the model",
194
  interactive=True,
 
195
  )
196
  concept_magnitude = gr.Slider(
197
  label="Steering Intensity",
198
  minimum=-5,
199
  maximum=5,
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:
206
  search_box.change(
207
  update_dropdown_choices,
208
  [search_box],
209
  [concept_dropdown]
 
 
 
 
210
  )
211
 
212
  concept_dropdown.select(
@@ -222,4 +234,3 @@ with gr.Blocks(fill_height=True) as demo:
222
  )
223
 
224
  demo.launch(share=True)
225
-
 
160
 
161
  def update_dropdown_choices(search_text):
162
  filtered = filter_concepts(search_text)
163
+ if not filtered:
164
+ return gr.update(choices=[], value=None, interactive=True)
165
+ # Automatically select the first matching concept
166
+ return gr.update(
167
+ choices=filtered,
168
+ value=filtered[0], # Select the first match
169
+ interactive=True
170
+ )
171
 
172
  with gr.Blocks(fill_height=True) as demo:
173
  # Remove default subspaces
 
188
  # Right side: concept management
189
  with gr.Column(scale=3):
190
  gr.Markdown("## Steer Model Responses")
191
+ gr.Markdown("Search and then select a concept to steer. The closest match will be automatically selected.")
192
  # Concept Search and Selection
193
  with gr.Group():
194
  search_box = gr.Textbox(
 
199
  concept_dropdown = gr.Dropdown(
200
  label="Select a concept to steer the model",
201
  interactive=True,
202
+ allow_custom_value=False
203
  )
204
  concept_magnitude = gr.Slider(
205
  label="Steering Intensity",
206
  minimum=-5,
207
  maximum=5,
208
+ step=0.1,
209
  value=3,
210
  )
211
 
212
  # Wire up events
213
+ # When search box changes, update dropdown AND trigger concept selection
214
  search_box.change(
215
  update_dropdown_choices,
216
  [search_box],
217
  [concept_dropdown]
218
+ ).then( # Chain the events to automatically add the concept
219
+ add_concept_to_list,
220
+ [concept_dropdown, concept_magnitude, selected_subspaces],
221
+ [selected_subspaces]
222
  )
223
 
224
  concept_dropdown.select(
 
234
  )
235
 
236
  demo.launch(share=True)