@@ -487,6 +487,53 @@ def call_snpe(n_clicks: int | list[int], statistics_inputs: list[float]) -> Call
487487 return dcc .send_file (outfile ), True , f"Calling { task } calibrator"
488488
489489
490+ @callback (
491+ Output (f"{ PAGE_ID } -download-results" , "data" , allow_duplicate = True ),
492+ Output (f"{ PAGE_ID } -load-toast" , "is_open" , allow_duplicate = True ),
493+ Output (f"{ PAGE_ID } -load-toast" , "children" , allow_duplicate = True ),
494+ Input ({"index" : f"{ PAGE_ID } -call-surrogate-button" , "type" : ALL }, "n_clicks" ),
495+ State ({"type" : f"{ PAGE_ID } -parameters" , "index" : ALL }, "value" ),
496+ prevent_initial_call = True ,
497+ )
498+ def call_surrogate (
499+ n_clicks : int | list [int ], statistics_inputs : list [float ]
500+ ) -> Callable :
501+ """Call the surrogate model endpoint.
502+
503+ Args:
504+ n_clicks (int | list[int]):
505+ The number of form clicks.
506+ statistics_inputs (list[float]):
507+ The list of summary statistic values.
508+
509+ Returns:
510+ Callable:
511+ The form data.
512+ """
513+ if n_clicks is None or len (n_clicks ) == 0 : # type: ignore
514+ return no_update
515+
516+ if n_clicks [0 ] is None or n_clicks [0 ] == 0 : # type: ignore
517+ return no_update
518+
519+ endpoint = os .environ .get (
520+ "DEPLOYMENT_SURROGATE_INTERNAL_LINK" , "http://surrogate:3000"
521+ )
522+
523+ app = get_app ()
524+ statistics_form = app .settings [FORM_NAME ]
525+ summary_statistics = {}
526+ for i , child in enumerate (statistics_form .components ["parameters" ]["children" ]):
527+ statistic_name = child ["param" ]
528+ statistic_value = statistics_inputs [i ]
529+ summary_statistics [statistic_name ] = statistic_value
530+
531+ json = {"data" : [summary_statistics ]}
532+ task = "surrogate"
533+ outfile = endpoint_predict (task , endpoint , json )
534+ return dcc .send_file (outfile ), True , f"Calling { task } calibrator"
535+
536+
490537######################################
491538# Layout
492539######################################
0 commit comments