| 137 | |
| 138 | |
| 139 | def reload_javascript(): |
| 140 | scripts_list = [os.path.join(script_path, i) for i in os.listdir(script_path) if i.endswith(".js")] |
| 141 | javascript = "" |
| 142 | # with open("script.js", "r", encoding="utf8") as js_file: |
| 143 | # javascript = f'<script>{js_file.read()}</script>' |
| 144 | |
| 145 | for path in scripts_list: |
| 146 | with open(path, "r", encoding="utf8") as js_file: |
| 147 | javascript += f"\n<script>{js_file.read()}</script>" |
| 148 | |
| 149 | # todo: theme |
| 150 | # if cmd_opts.theme is not None: |
| 151 | # javascript += f"\n<script>set_theme('{cmd_opts.theme}');</script>\n" |
| 152 | |
| 153 | def template_response(*args, **kwargs): |
| 154 | res = _gradio_template_response_orig(*args, **kwargs) |
| 155 | res.body = res.body.replace( |
| 156 | b'</head>', f'{javascript}</head>'.encode("utf8")) |
| 157 | res.init_headers() |
| 158 | return res |
| 159 | |
| 160 | gr.routes.templates.TemplateResponse = template_response |