midi_visualizer / app.py
Next
Update app.py
aa2296f verified
raw
history blame
No virus
682 Bytes
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<!-- {path} --><script>{jsfile.read()}</script>"
template_response_ori = gr.routes.templates.TemplateResponse
def template_response(*args, **kwargs):
res = template_response_ori(*args, **kwargs)
res.body = res.body.replace(
b'</head>', f'{javascript}</head>'.encode("utf8"))
res.init_headers()
return res
gr.routes.templates.TemplateResponse = template_response
load_javascript()