-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathia_ui_gradio.py
More file actions
30 lines (18 loc) · 782 Bytes
/
ia_ui_gradio.py
File metadata and controls
30 lines (18 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import gradio as gr
GradioTemplateResponseOriginal = gr.routes.templates.TemplateResponse
def webpath(fn):
web_path = os.path.realpath(fn)
return f'file={web_path}?{os.path.getmtime(fn)}'
def javascript_html():
script_path = os.path.join(os.path.dirname(__file__), "javascript", "inpaint-anything.js")
head = f'<script type="text/javascript" src="{webpath(script_path)}"></script>\n'
return head
def reload_javascript():
js = javascript_html()
def template_response(*args, **kwargs):
res = GradioTemplateResponseOriginal(*args, **kwargs)
res.body = res.body.replace(b'</head>', f'{js}</head>'.encode("utf8"))
res.init_headers()
return res
gr.routes.templates.TemplateResponse = template_response