Skip to content

Commit c5334fc

Browse files
committed
fix javascript duplication bug after pressing the restart UI button
1 parent 804d9fb commit c5334fc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

modules/ui.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ def apply_field(obj, field, condition=None, init_field=None):
17521752
return demo
17531753

17541754

1755-
def load_javascript(raw_response):
1755+
def reload_javascript():
17561756
with open(os.path.join(script_path, "script.js"), "r", encoding="utf8") as jsfile:
17571757
javascript = f'<script>{jsfile.read()}</script>'
17581758

@@ -1768,7 +1768,7 @@ def load_javascript(raw_response):
17681768
javascript += f"\n<script>{localization.localization_js(shared.opts.localization)}</script>"
17691769

17701770
def template_response(*args, **kwargs):
1771-
res = raw_response(*args, **kwargs)
1771+
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
17721772
res.body = res.body.replace(
17731773
b'</head>', f'{javascript}</head>'.encode("utf8"))
17741774
res.init_headers()
@@ -1777,4 +1777,5 @@ def template_response(*args, **kwargs):
17771777
gradio.routes.templates.TemplateResponse = template_response
17781778

17791779

1780-
reload_javascript = partial(load_javascript, gradio.routes.templates.TemplateResponse)
1780+
if not hasattr(shared, 'GradioTemplateResponseOriginal'):
1781+
shared.GradioTemplateResponseOriginal = gradio.routes.templates.TemplateResponse

0 commit comments

Comments
 (0)