mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
rework open folder
This commit is contained in:
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import torch
|
||||
import diffusers
|
||||
import safetensors
|
||||
import safetensors.torch as sf
|
||||
|
||||
log = logging.getLogger("sdnext")
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s | %(message)s')
|
||||
|
||||
|
||||
def convert(model_id, output_name):
|
||||
if os.path.exists(output_name):
|
||||
log.error(f'Output already exists: {output_name}')
|
||||
return
|
||||
pipe = diffusers.DiffusionPipeline.from_pretrained(model_id)
|
||||
metadata = { 'model_id': model_id }
|
||||
model = {}
|
||||
model['state_dict'] = vars(pipe)['_internal_dict']
|
||||
for k in model['state_dict'].keys():
|
||||
# print(k, getattr(pipe, k))
|
||||
model[k] = getattr(pipe, k)
|
||||
sf.save_model(model, output_name, metadata=metadata)
|
||||
# log.info(f'Saved model: {output_name}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.argv.pop(0)
|
||||
if len(sys.argv) < 2:
|
||||
log.info('Usage: hf-convert.py <model_id> <output_name>')
|
||||
sys.exit(1)
|
||||
log.debug(f'Packages: torch={torch.__version__} diffusers={diffusers.__version__} safetensors={safetensors.__version__}')
|
||||
convert(sys.argv[0], sys.argv[1])
|
||||
+4
-4
@@ -51,8 +51,8 @@ sample_img2img = sample_img2img if os.path.exists(sample_img2img) else None
|
||||
paste_function = None
|
||||
|
||||
|
||||
def create_output_panel(tabname, outdir): # may be referenced by extensions
|
||||
a, b, c, _d, e = ui_common.create_output_panel(tabname, outdir)
|
||||
def create_output_panel(tabname, outdir): # pylint: disable=unused-argument # outdir is used by extensions
|
||||
a, b, c, _d, e = ui_common.create_output_panel(tabname)
|
||||
return a, b, c, e
|
||||
|
||||
def plaintext_to_html(text): # may be referenced by extensions
|
||||
@@ -460,7 +460,7 @@ def create_ui(startup_timer = None):
|
||||
show_progress=False,
|
||||
)
|
||||
|
||||
txt2img_gallery, generation_info, html_info, _html_info_formatted, html_log = ui_common.create_output_panel("txt2img", opts.outdir_txt2img_samples)
|
||||
txt2img_gallery, generation_info, html_info, _html_info_formatted, html_log = ui_common.create_output_panel("txt2img")
|
||||
connect_reuse_seed(seed, reuse_seed, generation_info, dummy_component, is_subseed=False)
|
||||
connect_reuse_seed(subseed, reuse_subseed, generation_info, dummy_component, is_subseed=True)
|
||||
|
||||
@@ -744,7 +744,7 @@ def create_ui(startup_timer = None):
|
||||
with FormGroup(elem_id="img2img_script_container"):
|
||||
custom_inputs = modules.scripts.scripts_img2img.setup_ui()
|
||||
|
||||
img2img_gallery, generation_info, html_info, _html_info_formatted, html_log = ui_common.create_output_panel("img2img", opts.outdir_img2img_samples)
|
||||
img2img_gallery, generation_info, html_info, _html_info_formatted, html_log = ui_common.create_output_panel("img2img")
|
||||
|
||||
connect_reuse_seed(seed, reuse_seed, generation_info, dummy_component, is_subseed=False)
|
||||
connect_reuse_seed(subseed, reuse_subseed, generation_info, dummy_component, is_subseed=True)
|
||||
|
||||
+25
-25
@@ -148,33 +148,32 @@ def save_files(js_data, images, html_info, index):
|
||||
return gr.File.update(value=fullfns, visible=True), plaintext_to_html(f"Saved: {filenames[0] if len(filenames) > 0 else 'none'}")
|
||||
|
||||
|
||||
def create_output_panel(tabname, outdir):
|
||||
import modules.generation_parameters_copypaste as parameters_copypaste
|
||||
def open_folder(result_gallery, gallery_index = 0):
|
||||
try:
|
||||
folder = os.path.dirname(result_gallery[gallery_index]['name'])
|
||||
except Exception:
|
||||
folder = shared.opts.outdir_samples
|
||||
if not os.path.exists(folder):
|
||||
shared.log.warning(f'Folder open: folder={folder} does not exist')
|
||||
return
|
||||
elif not os.path.isdir(folder):
|
||||
shared.log.warning(f"Folder open: folder={folder} not a folder")
|
||||
return
|
||||
|
||||
def open_folder(gallery):
|
||||
if type(gallery) is str:
|
||||
folder = gallery
|
||||
elif gallery is not None and len(gallery) > 0:
|
||||
folder = os.path.dirname(gallery[-1]['name'])
|
||||
if not shared.cmd_opts.hide_ui_dir_config:
|
||||
path = os.path.normpath(folder)
|
||||
if platform.system() == "Windows":
|
||||
os.startfile(path) # pylint: disable=no-member
|
||||
elif platform.system() == "Darwin":
|
||||
subprocess.Popen(["open", path]) # pylint: disable=consider-using-with
|
||||
elif "microsoft-standard-WSL2" in platform.uname().release:
|
||||
subprocess.Popen(["wsl-open", path]) # pylint: disable=consider-using-with
|
||||
else:
|
||||
folder = shared.opts.outdir_samples or outdir
|
||||
if not os.path.exists(folder):
|
||||
shared.log.warning(f'Folder open: folder={folder} does not exist')
|
||||
return
|
||||
elif not os.path.isdir(folder):
|
||||
shared.log.warning(f"Folder open: folder={folder} not a folder")
|
||||
return
|
||||
subprocess.Popen(["xdg-open", path]) # pylint: disable=consider-using-with
|
||||
|
||||
if not shared.cmd_opts.hide_ui_dir_config:
|
||||
path = os.path.normpath(folder)
|
||||
if platform.system() == "Windows":
|
||||
os.startfile(path) # pylint: disable=no-member
|
||||
elif platform.system() == "Darwin":
|
||||
subprocess.Popen(["open", path]) # pylint: disable=consider-using-with
|
||||
elif "microsoft-standard-WSL2" in platform.uname().release:
|
||||
subprocess.Popen(["wsl-open", path]) # pylint: disable=consider-using-with
|
||||
else:
|
||||
subprocess.Popen(["xdg-open", path]) # pylint: disable=consider-using-with
|
||||
|
||||
def create_output_panel(tabname):
|
||||
import modules.generation_parameters_copypaste as parameters_copypaste
|
||||
|
||||
with gr.Column(variant='panel', elem_id=f"{tabname}_results"):
|
||||
with gr.Group(elem_id=f"{tabname}_gallery_container"):
|
||||
@@ -182,10 +181,11 @@ def create_output_panel(tabname, outdir):
|
||||
result_gallery = gr.Gallery(value=[], label='Output', show_label=False, show_download_button=True, elem_id=f"{tabname}_gallery", container=False, preview=True, columns=[1,2,3,4,5,6], object_fit='scale-down')
|
||||
|
||||
with gr.Column(elem_id=f"{tabname}_footer", elem_classes="gallery_footer"):
|
||||
dummy_component = gr.Label(visible=False)
|
||||
with gr.Row(elem_id=f"image_buttons_{tabname}", elem_classes="image-buttons"):
|
||||
if not shared.cmd_opts.listen:
|
||||
open_folder_button = gr.Button('Show', visible=not shared.cmd_opts.hide_ui_dir_config, elem_id=f'open_folder_{tabname}')
|
||||
open_folder_button.click(open_folder, inputs=[result_gallery], outputs=[])
|
||||
open_folder_button.click(open_folder, _js="(gallery, dummy) => [gallery, selected_gallery_index()]", inputs=[result_gallery, dummy_component], outputs=[])
|
||||
else:
|
||||
clip_files = gr.Button('Copy', elem_id=f'open_folder_{tabname}')
|
||||
clip_files.click(fn=None, _js='clip_gallery_urls', inputs=[result_gallery], outputs=[])
|
||||
|
||||
@@ -41,7 +41,7 @@ def create_ui():
|
||||
interrupt.click(fn=lambda: shared.state.interrupt(), inputs=[], outputs=[])
|
||||
skip = gr.Button('Skip', elem_id=f"{id_part}_skip", variant='secondary')
|
||||
skip.click(fn=lambda: shared.state.skip(), inputs=[], outputs=[])
|
||||
result_images, generation_info, html_info, html_info_formatted, html_log = ui_common.create_output_panel("extras", shared.opts.outdir_extras_samples)
|
||||
result_images, generation_info, html_info, html_info_formatted, html_log = ui_common.create_output_panel("extras")
|
||||
gr.HTML('File metadata')
|
||||
exif_info = gr.HTML(elem_id="pnginfo_html_info")
|
||||
gen_info = gr.Text(elem_id="pnginfo_gen_info", visible=False)
|
||||
|
||||
Reference in New Issue
Block a user