Spaces:
Sleeping
Sleeping
File size: 871 Bytes
be0e66f b2848c4 be0e66f b2848c4 be0e66f 44639bf |
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 33 34 |
def gradify_closure(source, argmaps, func_kwargs={}):
ldict = {}
exec(source, globals(), ldict)
from types import FunctionType
for k, v in ldict.items():
if isinstance(v, FunctionType):
func = ldict.pop(k)
break
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 |