my-sd/extensions-builtin/sd_forge_svd/scripts/forge_svd.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.6 KiB
Python
Raw Normal View History

2024-01-26 05:48:59 +00:00
import gradio as gr
2024-01-26 05:51:57 +00:00
import os
2024-01-26 06:00:36 +00:00
import pathlib
2024-01-26 05:48:59 +00:00
from modules import scripts, script_callbacks
2024-01-26 05:51:57 +00:00
from modules.paths import models_path
2024-01-26 06:03:43 +00:00
from modules.ui_common import ToolButton, refresh_symbol
2024-01-26 05:54:40 +00:00
from modules import shared
2024-01-26 05:51:57 +00:00
svd_root = os.path.join(models_path, 'svd')
os.makedirs(svd_root, exist_ok=True)
2024-01-26 05:54:40 +00:00
svd_filenames = []
def update_svd_filenames():
global svd_filenames
2024-01-26 06:00:36 +00:00
svd_filenames = [pathlib.Path(x).name for x in shared.walk_files(svd_root, allowed_extensions=[".pt", ".ckpt", ".safetensors"])]
2024-01-26 05:54:40 +00:00
return svd_filenames
2024-01-26 05:48:59 +00:00
class ForgeSVD(scripts.Script):
def __init__(self) -> None:
super().__init__()
def title(self):
return "SVD"
def show(self, is_img2img):
return scripts.AlwaysVisible
def ui(self, is_img2img):
return ()
def on_ui_tabs():
with gr.Blocks(analytics_enabled=False) as svd_block:
with gr.Row():
with gr.Column():
2024-01-26 06:03:43 +00:00
with gr.Row():
2024-01-26 06:07:28 +00:00
filename = gr.Dropdown(label="SVD Checkpoint Filename",
choices=svd_filenames,
value=svd_filenames[0] if len(svd_filenames) > 0 else None)
2024-01-26 06:03:43 +00:00
refresh_button = ToolButton(value=refresh_symbol, tooltip="Refresh")
2024-01-26 06:07:07 +00:00
refresh_button.click(
fn=lambda: gr.update(choices=update_svd_filenames),
inputs=[], outputs=filename)
2024-01-26 05:48:59 +00:00
with gr.Column():
png_output = gr.Button(value="Save PNG")
return [(svd_block, "SVD", "svd")]
2024-01-26 05:55:02 +00:00
update_svd_filenames()
2024-01-26 05:48:59 +00:00
script_callbacks.on_ui_tabs(on_ui_tabs)