QuAcc/qcpanel/run.py

99 lines
2.2 KiB
Python
Raw Normal View History

2023-11-11 16:44:12 +01:00
import argparse
import panel as pn
2023-11-16 17:10:19 +01:00
from qcpanel.viewer import QuaccTestViewer
2023-11-11 16:44:12 +01:00
2023-11-16 17:10:19 +01:00
# pn.config.design = pn.theme.Bootstrap
# pn.config.theme = "dark"
2023-11-16 01:34:01 +01:00
pn.config.notifications = True
def app_instance():
param_init = {
k: v
for k, v in pn.state.location.query_params.items()
if k in ["dataset", "metric", "plot_view", "mode", "estimators"]
}
qtv = QuaccTestViewer(param_init=param_init)
pn.state.location.sync(
qtv,
{
"dataset": "dataset",
"metric": "metric",
"plot_view": "plot_view",
"mode": "mode",
"estimators": "estimators",
},
)
2023-11-16 01:34:01 +01:00
def save_callback(event):
app.open_modal()
2023-11-16 17:10:19 +01:00
def refresh_callback(event):
qtv.update_datasets()
2023-11-16 01:34:01 +01:00
save_button = pn.widgets.Button(
2023-11-16 17:10:19 +01:00
# name="Save",
icon="device-floppy",
icon_size="16px",
# sizing_mode="scale_width",
2023-11-16 01:34:01 +01:00
button_style="solid",
button_type="success",
2023-11-11 16:44:12 +01:00
)
2023-11-16 01:34:01 +01:00
save_button.on_click(save_callback)
2023-11-11 16:44:12 +01:00
2023-11-16 17:10:19 +01:00
refresh_button = pn.widgets.Button(
icon="refresh",
icon_size="16px",
button_style="solid",
)
refresh_button.on_click(refresh_callback)
app = pn.template.FastListTemplate(
2023-11-16 01:34:01 +01:00
title="quacc tests",
2023-11-16 17:10:19 +01:00
sidebar=[
pn.FlexBox(save_button, refresh_button, flex_direction="row-reverse"),
qtv.get_param_pane,
],
main=[pn.Column(qtv.get_plot, sizing_mode="stretch_both")],
2023-11-16 01:34:01 +01:00
modal=[qtv.modal_pane],
2023-11-16 17:10:19 +01:00
theme=pn.theme.DarkTheme,
theme_toggle=False,
2023-11-16 01:34:01 +01:00
)
app.servable()
return app
def serve(address="localhost"):
2023-11-11 16:44:12 +01:00
__port = 33420
2023-11-16 01:34:01 +01:00
__allowed = [address]
if address == "localhost":
__allowed.append("127.0.0.1")
2023-11-11 16:44:12 +01:00
pn.serve(
app_instance,
2023-11-11 16:44:12 +01:00
autoreload=True,
port=__port,
show=False,
address=address,
2023-11-16 01:34:01 +01:00
websocket_origin=[f"{_a}:{__port}" for _a in __allowed],
2023-11-11 16:44:12 +01:00
)
def run():
parser = argparse.ArgumentParser()
parser.add_argument(
"--address",
action="store",
dest="address",
default="localhost",
)
args = parser.parse_args()
serve(address=args.address)
2023-11-16 01:34:01 +01:00
if __name__ == "__main__":
run()