gitio-max-substring / gradify.py
lint's picture
Upload folder using huggingface_hub
51d7aa9
raw
history blame contribute delete
871 Bytes
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