fix javascript duplication bug after pressing the restart UI button
This commit is contained in:
parent
804d9fb83d
commit
c5334fc56b
1 changed files with 4 additions and 3 deletions
|
@ -1752,7 +1752,7 @@ def create_ui(wrap_gradio_gpu_call):
|
||||||
return demo
|
return demo
|
||||||
|
|
||||||
|
|
||||||
def load_javascript(raw_response):
|
def reload_javascript():
|
||||||
with open(os.path.join(script_path, "script.js"), "r", encoding="utf8") as jsfile:
|
with open(os.path.join(script_path, "script.js"), "r", encoding="utf8") as jsfile:
|
||||||
javascript = f'<script>{jsfile.read()}</script>'
|
javascript = f'<script>{jsfile.read()}</script>'
|
||||||
|
|
||||||
|
@ -1768,7 +1768,7 @@ def load_javascript(raw_response):
|
||||||
javascript += f"\n<script>{localization.localization_js(shared.opts.localization)}</script>"
|
javascript += f"\n<script>{localization.localization_js(shared.opts.localization)}</script>"
|
||||||
|
|
||||||
def template_response(*args, **kwargs):
|
def template_response(*args, **kwargs):
|
||||||
res = raw_response(*args, **kwargs)
|
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
|
||||||
res.body = res.body.replace(
|
res.body = res.body.replace(
|
||||||
b'</head>', f'{javascript}</head>'.encode("utf8"))
|
b'</head>', f'{javascript}</head>'.encode("utf8"))
|
||||||
res.init_headers()
|
res.init_headers()
|
||||||
|
@ -1777,4 +1777,5 @@ def load_javascript(raw_response):
|
||||||
gradio.routes.templates.TemplateResponse = template_response
|
gradio.routes.templates.TemplateResponse = template_response
|
||||||
|
|
||||||
|
|
||||||
reload_javascript = partial(load_javascript, gradio.routes.templates.TemplateResponse)
|
if not hasattr(shared, 'GradioTemplateResponseOriginal'):
|
||||||
|
shared.GradioTemplateResponseOriginal = gradio.routes.templates.TemplateResponse
|
||||||
|
|
Loading…
Reference in a new issue