Upload fast-pnginfo.py
Browse files- fast-pnginfo.py +54 -0
fast-pnginfo.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from modules import script_callbacks
|
3 |
+
import modules.generation_parameters_copypaste as parameters_copypaste
|
4 |
+
from modules import extensions
|
5 |
+
import os
|
6 |
+
|
7 |
+
def get_self_extension():
|
8 |
+
if '__file__' in globals():
|
9 |
+
filepath = __file__
|
10 |
+
else:
|
11 |
+
import inspect
|
12 |
+
filepath = inspect.getfile(lambda: None)
|
13 |
+
for ext in extensions.active():
|
14 |
+
if ext.path in filepath:
|
15 |
+
return ext
|
16 |
+
|
17 |
+
|
18 |
+
def on_ui_tabs():
|
19 |
+
|
20 |
+
ext = get_self_extension()
|
21 |
+
if ext is None:
|
22 |
+
return []
|
23 |
+
js_ = [f'{x.path}?{os.path.getmtime(x.path)}' for x in ext.list_files('js', '.js')]
|
24 |
+
js_.insert(0, ext.path)
|
25 |
+
|
26 |
+
|
27 |
+
with gr.Blocks(analytics_enabled=False) as fast_pnginfo:
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column(scale=2):
|
30 |
+
gr.HTML(value='\n'.join(js_), elem_id="fastpng_js_path", visible=False)
|
31 |
+
gr.Markdown(
|
32 |
+
f"""
|
33 |
+
<center>
|
34 |
+
|
35 |
+
</center>
|
36 |
+
""")
|
37 |
+
with gr.Row().style(equal_height=False):
|
38 |
+
with gr.Column(variant='panel'):
|
39 |
+
image = gr.Image(elem_id="fastpnginfo_image", label="Source", source="upload", interactive=True, type="pil")
|
40 |
+
# image.change(lambda x: x, _js='(e)=>{console.log(e);fastpngprocess()}')
|
41 |
+
|
42 |
+
with gr.Column(variant='panel'):
|
43 |
+
submit = gr.Button(label="Submit", elem_id="fastpnginfo_submit", interactive=True, variant="primary", visible=True)
|
44 |
+
fast_generation_info = gr.Textbox(label="Parameters", visible=True, elem_id="fastpnginfo_generation_info", interactive=False)
|
45 |
+
with gr.Row():
|
46 |
+
buttons = parameters_copypaste.create_buttons(["txt2img", "img2img", "inpaint", "extras"])
|
47 |
+
|
48 |
+
for tabname, button in buttons.items():
|
49 |
+
parameters_copypaste.register_paste_params_button(parameters_copypaste.ParamBinding(
|
50 |
+
paste_button=button, tabname=tabname, source_text_component=fast_generation_info, source_image_component=image,
|
51 |
+
))
|
52 |
+
return [(fast_pnginfo, "Fast PNG Info", "fast_pnginfo")];
|
53 |
+
|
54 |
+
script_callbacks.on_ui_tabs(on_ui_tabs)
|