import gradio as gr import glob def load_javascript(): scripts_list = glob.glob("javascript_app.js") javascript = "" for path in scripts_list: with open(path, "r", encoding="utf8") as jsfile: javascript += f"\n" template_response_ori = gr.routes.templates.TemplateResponse def template_response(*args, **kwargs): res = template_response_ori(*args, **kwargs) res.body = res.body.replace( b'', f'{javascript}'.encode("utf8")) res.init_headers() return res gr.routes.templates.TemplateResponse = template_response load_javascript()