File size: 817 Bytes
6bc5f93 d3e70b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
func = None
def gradify_closure(ldict, argmaps, func_kwargs={}):
globals().update(ldict)
func_kwargs = dict(func_kwargs)
def gradify_func(*args):
try:
for (arg, argmap) in zip(args, argmaps):
postprocessing = argmap.get("postprocessing", None)
if postprocessing:
arg = eval(postprocessing)(arg)
kw_label = argmap["label"]
func_kwargs[kw_label] = arg
return func(**func_kwargs)
except Exception as e:
import gradio as gr
raise gr.Error(f"Error: {e}")
return gradify_func
def exec_to_dict(source, target=None):
ldict = {}
exec(source, globals(), ldict)
return ldict.get(target, None) if target else ldict |