Recompute condition on generation click
Browse files
app.py
CHANGED
|
@@ -507,29 +507,22 @@ def ui_load_test_condition(idx: int):
|
|
| 507 |
return (*vals, f"Loaded v5 test condition `{int(idx)}`.", plot_required_curves_from_series(curves), payload)
|
| 508 |
|
| 509 |
|
| 510 |
-
def ui_after_requirement_ready(mode: str
|
| 511 |
manual = mode == "Define by Input Values"
|
| 512 |
-
return ui_set_buttons(manual, not manual,
|
| 513 |
|
| 514 |
|
| 515 |
-
def ui_inverse_design(n_generate: float,
|
| 516 |
-
if not condition_payload:
|
| 517 |
-
return (
|
| 518 |
-
None,
|
| 519 |
-
None,
|
| 520 |
-
"No generated designs are available.",
|
| 521 |
-
"Requirement curves are not ready. Generate required curves or load a test condition first.",
|
| 522 |
-
gr.update(choices=[], value=None),
|
| 523 |
-
NO_SELECTED_DESIGN,
|
| 524 |
-
"",
|
| 525 |
-
)
|
| 526 |
gt_summary = ""
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
|
|
|
|
|
|
|
|
|
| 533 |
req_plot = plot_required_curves_from_series(curves)
|
| 534 |
n_generate_int = int(max(1, min(int(n_generate), MAX_N_GENERATE)))
|
| 535 |
try:
|
|
@@ -859,7 +852,7 @@ def build_app():
|
|
| 859 |
show_progress=False,
|
| 860 |
).then(
|
| 861 |
fn=ui_after_requirement_ready,
|
| 862 |
-
inputs=[input_mode
|
| 863 |
outputs=[preview_btn, load_btn, design_btn, thermo_btn],
|
| 864 |
show_progress=False,
|
| 865 |
)
|
|
@@ -877,7 +870,7 @@ def build_app():
|
|
| 877 |
show_progress=False,
|
| 878 |
).then(
|
| 879 |
fn=ui_after_requirement_ready,
|
| 880 |
-
inputs=[input_mode
|
| 881 |
outputs=[preview_btn, load_btn, design_btn, thermo_btn],
|
| 882 |
show_progress=False,
|
| 883 |
)
|
|
@@ -887,7 +880,7 @@ def build_app():
|
|
| 887 |
show_progress=False,
|
| 888 |
).then(
|
| 889 |
fn=ui_inverse_design,
|
| 890 |
-
inputs=[n_generate,
|
| 891 |
outputs=[req_plot, design_plot, design_summary, run_log, design_choice, selected_design_md, design_payload],
|
| 892 |
).then(
|
| 893 |
fn=ui_after_design_complete,
|
|
|
|
| 507 |
return (*vals, f"Loaded v5 test condition `{int(idx)}`.", plot_required_curves_from_series(curves), payload)
|
| 508 |
|
| 509 |
|
| 510 |
+
def ui_after_requirement_ready(mode: str):
|
| 511 |
manual = mode == "Define by Input Values"
|
| 512 |
+
return ui_set_buttons(manual, not manual, True, False)
|
| 513 |
|
| 514 |
|
| 515 |
+
def ui_inverse_design(n_generate: float, mode: str, load_idx: float, *values: float):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
gt_summary = ""
|
| 517 |
+
if mode == "Load from Test Data":
|
| 518 |
+
payload = json.loads(_load_exact_test_payload(int(load_idx)))
|
| 519 |
+
cond_coeffs = np.asarray(payload["coeffs"], dtype=np.float32).reshape(7, 3)
|
| 520 |
+
curves = _curves_from_coeffs(cond_coeffs)
|
| 521 |
+
gt = payload.get("ground_truth", {})
|
| 522 |
+
if gt:
|
| 523 |
+
gt_summary = _format_ground_truth_summary(gt)
|
| 524 |
+
else:
|
| 525 |
+
curves, cond_coeffs = _build_required_curves_and_condition(list(values))
|
| 526 |
req_plot = plot_required_curves_from_series(curves)
|
| 527 |
n_generate_int = int(max(1, min(int(n_generate), MAX_N_GENERATE)))
|
| 528 |
try:
|
|
|
|
| 852 |
show_progress=False,
|
| 853 |
).then(
|
| 854 |
fn=ui_after_requirement_ready,
|
| 855 |
+
inputs=[input_mode],
|
| 856 |
outputs=[preview_btn, load_btn, design_btn, thermo_btn],
|
| 857 |
show_progress=False,
|
| 858 |
)
|
|
|
|
| 870 |
show_progress=False,
|
| 871 |
).then(
|
| 872 |
fn=ui_after_requirement_ready,
|
| 873 |
+
inputs=[input_mode],
|
| 874 |
outputs=[preview_btn, load_btn, design_btn, thermo_btn],
|
| 875 |
show_progress=False,
|
| 876 |
)
|
|
|
|
| 880 |
show_progress=False,
|
| 881 |
).then(
|
| 882 |
fn=ui_inverse_design,
|
| 883 |
+
inputs=[n_generate, input_mode, load_test_idx] + input_components,
|
| 884 |
outputs=[req_plot, design_plot, design_summary, run_log, design_choice, selected_design_md, design_payload],
|
| 885 |
).then(
|
| 886 |
fn=ui_after_design_complete,
|