Spaces:
Build error
Build error
update
Browse files
app.py
CHANGED
|
@@ -539,7 +539,38 @@ class ExplainerCheckbox(Component):
|
|
| 539 |
self.opt_check.select(self.optimal_on_select)
|
| 540 |
|
| 541 |
self.bttn = gr.Button(value="Optimize", size="sm", variant="primary")
|
| 542 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
|
| 545 |
class ExpRes(Component):
|
|
|
|
| 539 |
self.opt_check.select(self.optimal_on_select)
|
| 540 |
|
| 541 |
self.bttn = gr.Button(value="Optimize", size="sm", variant="primary")
|
| 542 |
+
|
| 543 |
+
@spaces.GPU
|
| 544 |
+
def optimize():
|
| 545 |
+
data_id = self.gallery.selected_index
|
| 546 |
+
|
| 547 |
+
opt_output = self.experiment.optimize(
|
| 548 |
+
data_ids=data_id.value,
|
| 549 |
+
explainer_id=self.default_exp_id,
|
| 550 |
+
metric_id=self.obj_metric,
|
| 551 |
+
direction='maximize',
|
| 552 |
+
sampler=SAMPLE_METHOD,
|
| 553 |
+
n_trials=OPT_N_TRIALS,
|
| 554 |
+
)
|
| 555 |
+
|
| 556 |
+
str_id = self.get_str_ppid(opt_output.postprocessor)
|
| 557 |
+
for pp_obj, pp_id in zip(*self.experiment.manager.get_postprocessors()):
|
| 558 |
+
if self.get_str_ppid(pp_obj) == str_id:
|
| 559 |
+
opt_postprocessor_id = pp_id
|
| 560 |
+
break
|
| 561 |
+
|
| 562 |
+
opt_explainer_id = max([x['id'] for x in self.groups.info]) + 1
|
| 563 |
+
opt_output.explainer.model = self.experiment.model
|
| 564 |
+
self.experiment.manager._explainers.append(opt_output.explainer)
|
| 565 |
+
self.experiment.manager._explainer_ids.append(opt_explainer_id)
|
| 566 |
+
self.groups.insert_check(self.explainer_name, opt_explainer_id, opt_postprocessor_id)
|
| 567 |
+
self.optimal_exp_id = opt_explainer_id
|
| 568 |
+
checkbox = gr.update(label="Optimized Parameter (Optimal)", interactive=True)
|
| 569 |
+
bttn = gr.update(value="Optimized", variant="secondary")
|
| 570 |
+
|
| 571 |
+
return [checkbox, bttn]
|
| 572 |
+
|
| 573 |
+
self.bttn.click(optimize, outputs=[self.opt_check, self.bttn], queue=True, concurrency_limit=1)
|
| 574 |
|
| 575 |
|
| 576 |
class ExpRes(Component):
|