# 需要导入模块: from bokeh.models import widgets [as 别名]
# 或者: from bokeh.models.widgets import Slider [as 别名]
def update_effect(attrname, old, new):
global effect, model, knob_names, knob_ranges, num_knobs, knob_sliders
# match the menu option with the right entry in effects_dict
long_name = effect_select.value
plot.title.text = f"Trying to setup effect '{long_name}'..."
shortname = ''
for key, val in effects_dict.items():
if val['name'] == long_name:
shortname = key
break
if '' == shortname:
plot.title.text = f"**ERROR: Effect '{long_name}' not defined**"
return
effect = effects_dict[shortname]['effect']
num_knobs = 0
if effect is not None:
knob_names, knob_ranges = effect.knob_names, np.array(effect.knob_ranges)
num_knobs = len(knob_names)
# try to read the checkpoint file
checkpoint_file = effects_dict[shortname]['checkpoint']
model = setup_model(checkpoint_file, fatal=False)
if model is None:
msg = f"**ERROR: checkpoint file '{checkpoint_file}' not found**"
print("\n",msg)
plot.title.text = msg
# rebuild the entire display (because knobs have changed)
knob_sliders = []
if num_knobs > 0:
knobs_wc = knob_ranges.mean(axis=1)
for k in range(num_knobs):
start, end = knob_ranges[k][0], knob_ranges[k][1]
mid = knobs_wc[k]
step = (end-start)/25
tmp = Slider(title=knob_names[k], value=mid, start=start, end=end, step=step)
knob_sliders.append(tmp)
for w in knob_sliders: # since we now defined new widgets, we need triggers for them
w.on_change('value', update_data)
inputs = column([effect_select, input_select]+knob_sliders )
curdoc().clear()
curdoc().add_root(row(inputs, plot, width=800))
curdoc().title = "SignalTrain Demo"
update_data(attrname, old, new)