# based on https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/v1.6.0/modules/ui_gradio_extensions.py
import os
import gradio as gr
import args_manager
from modules.localization import localization_js
GradioTemplateResponseOriginal = gr.routes.templates.TemplateResponse
modules_path = os.path.dirname(os.path.realpath(__file__))
script_path = os.path.dirname(modules_path)
def webpath(fn):
    if fn.startswith(script_path):
        web_path = os.path.relpath(fn, script_path).replace('\\', '/')
    else:
        web_path = os.path.abspath(fn)
    return f'file={web_path}?{os.path.getmtime(fn)}'
def javascript_html():
    script_js_path = webpath('javascript/script.js')
    context_menus_js_path = webpath('javascript/contextMenus.js')
    localization_js_path = webpath('javascript/localization.js')
    zoom_js_path = webpath('javascript/zoom.js')
    head = f'\n'
    head += f'\n'
    head += f'\n'
    head += f'\n'
    head += f'\n'
    return head
def css_html():
    style_css_path = webpath('css/style.css')
    head = f''
    return head
def reload_javascript():
    js = javascript_html()
    css = css_html()
    def template_response(*args, **kwargs):
        res = GradioTemplateResponseOriginal(*args, **kwargs)
        res.body = res.body.replace(b'', f'{js}'.encode("utf8"))
        res.body = res.body.replace(b'