Skip to content

Commit

Permalink
add redefinition guard to gradio_routes_templates_response
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaker authored Oct 1, 2022
1 parent a904447 commit afaa03c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,12 +1219,13 @@ def apply_field(obj, field, condition=None):
javascript += f"\n<script>{jsfile.read()}</script>"


def template_response(*args, **kwargs):
res = gradio_routes_templates_response(*args, **kwargs)
res.body = res.body.replace(b'</head>', f'{javascript}</head>'.encode("utf8"))
res.init_headers()
return res
if 'gradio_routes_templates_response' not in globals():
def template_response(*args, **kwargs):
res = gradio_routes_templates_response(*args, **kwargs)
res.body = res.body.replace(b'</head>', f'{javascript}</head>'.encode("utf8"))
res.init_headers()
return res

gradio_routes_templates_response = gradio.routes.templates.TemplateResponse
gradio.routes.templates.TemplateResponse = template_response

gradio_routes_templates_response = gradio.routes.templates.TemplateResponse
gradio.routes.templates.TemplateResponse = template_response

0 comments on commit afaa03c

Please sign in to comment.