lint/gitio-array-median
0
1 2 3def gradify_closure(source, argmaps, func_kwargs={}):4 5 ldict = {}6 exec(source, globals(), ldict)7 8 from types import FunctionType9 for k, v in ldict.items():10 if isinstance(v, FunctionType):11 func = ldict.pop(k)12 break13 14 globals().update(ldict)15 func_kwargs = dict(func_kwargs)16 17 def gradify_func(*args):18 19 try:20 for (arg, argmap) in zip(args, argmaps):21 22 postprocessing = argmap.get("postprocessing", None)23 if postprocessing:24 arg = eval(postprocessing)(arg)25 26 kw_label = argmap["label"]27 func_kwargs[kw_label] = arg28 29 return func(**func_kwargs)30 except Exception as e:31 import gradio as gr32 raise gr.Error(f"Error: {e}")33 34 return gradify_func