Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
import time
|
3 |
import os
|
4 |
import gradio as gr
|
5 |
-
from pnpxai.core.experiment
|
6 |
-
from pnpxai.core.detector
|
7 |
import matplotlib.pyplot as plt
|
8 |
import plotly.graph_objects as go
|
9 |
import plotly.express as px
|
@@ -16,6 +16,7 @@ N_FEATURES_TO_SHOW = 5
|
|
16 |
OPT_N_TRIALS = 10
|
17 |
OBJECTIVE_METRIC = "AbPC"
|
18 |
SAMPLE_METHOD = "tpe"
|
|
|
19 |
|
20 |
class App:
|
21 |
def __init__(self):
|
@@ -388,7 +389,12 @@ class ExplainerCheckboxGroup(Component):
|
|
388 |
|
389 |
self.info = []
|
390 |
for exp, exp_id in zip(explainers, exp_ids):
|
391 |
-
|
|
|
|
|
|
|
|
|
|
|
392 |
|
393 |
def update_check(self, exp_id, val=None):
|
394 |
for info in self.info:
|
@@ -407,7 +413,9 @@ class ExplainerCheckboxGroup(Component):
|
|
407 |
def update_gallery_change(self):
|
408 |
checkboxes = []
|
409 |
bttns = []
|
410 |
-
|
|
|
|
|
411 |
checkboxes += [gr.Checkbox(label="Optimized Parameter (Not Optimal)", value=False, interactive=False)] * len(self.explainer_objs)
|
412 |
bttns += [gr.Button(value="Optimize", size="sm", variant="primary")] * len(self.explainer_objs)
|
413 |
|
@@ -504,7 +512,8 @@ class ExplainerCheckbox(Component):
|
|
504 |
|
505 |
def show(self):
|
506 |
with gr.Accordion(self.explainer_name, open=False):
|
507 |
-
|
|
|
508 |
self.opt_check = gr.Checkbox(label="Optimized Parameter (Not Optimal)", interactive=False)
|
509 |
|
510 |
self.default_check.select(self.default_on_select)
|
@@ -587,7 +596,9 @@ class ImageClsApp(App):
|
|
587 |
def title(self):
|
588 |
return """
|
589 |
<div style="text-align: center;">
|
|
|
590 |
<img src="/file=data/static/XAI-Top-PnP.svg" width="100" height="100">
|
|
|
591 |
<h1> Plug and Play XAI Platform for Image Classification </h1>
|
592 |
</div>
|
593 |
"""
|
|
|
2 |
import time
|
3 |
import os
|
4 |
import gradio as gr
|
5 |
+
from pnpxai.core.experiment import AutoExplanationForImageClassification
|
6 |
+
from pnpxai.core.detector import extract_graph_data, symbolic_trace
|
7 |
import matplotlib.pyplot as plt
|
8 |
import plotly.graph_objects as go
|
9 |
import plotly.express as px
|
|
|
16 |
OPT_N_TRIALS = 10
|
17 |
OBJECTIVE_METRIC = "AbPC"
|
18 |
SAMPLE_METHOD = "tpe"
|
19 |
+
DEFAULT_EXPLAINER = ["GradientXInput", "IntegratedGradients", "LRPEpsilonPlus"]
|
20 |
|
21 |
class App:
|
22 |
def __init__(self):
|
|
|
389 |
|
390 |
self.info = []
|
391 |
for exp, exp_id in zip(explainers, exp_ids):
|
392 |
+
exp_nm = exp.__class__.__name__
|
393 |
+
if exp_nm in DEFAULT_EXPLAINER:
|
394 |
+
checked = True
|
395 |
+
else:
|
396 |
+
checked = False
|
397 |
+
self.info.append({'nm': exp_nm, 'id': exp_id, 'pp_id' : 0, 'mode': 'default', 'checked': checked})
|
398 |
|
399 |
def update_check(self, exp_id, val=None):
|
400 |
for info in self.info:
|
|
|
413 |
def update_gallery_change(self):
|
414 |
checkboxes = []
|
415 |
bttns = []
|
416 |
+
for exp in self.explainer_objs:
|
417 |
+
val = exp.explainer_name in DEFAULT_EXPLAINER
|
418 |
+
checkboxes.append(gr.Checkbox(label="Default Parameter", value=val, interactive=True))
|
419 |
checkboxes += [gr.Checkbox(label="Optimized Parameter (Not Optimal)", value=False, interactive=False)] * len(self.explainer_objs)
|
420 |
bttns += [gr.Button(value="Optimize", size="sm", variant="primary")] * len(self.explainer_objs)
|
421 |
|
|
|
512 |
|
513 |
def show(self):
|
514 |
with gr.Accordion(self.explainer_name, open=False):
|
515 |
+
checked = next(filter(lambda x: x['nm'] == self.explainer_name, self.groups.info))['checked']
|
516 |
+
self.default_check = gr.Checkbox(label="Default Parameter", value=checked, interactive=True)
|
517 |
self.opt_check = gr.Checkbox(label="Optimized Parameter (Not Optimal)", interactive=False)
|
518 |
|
519 |
self.default_check.select(self.default_on_select)
|
|
|
596 |
def title(self):
|
597 |
return """
|
598 |
<div style="text-align: center;">
|
599 |
+
<a href="https://openxaiproject.github.io/pnpxai/">
|
600 |
<img src="/file=data/static/XAI-Top-PnP.svg" width="100" height="100">
|
601 |
+
</a>
|
602 |
<h1> Plug and Play XAI Platform for Image Classification </h1>
|
603 |
</div>
|
604 |
"""
|