File size: 6,779 Bytes
1a9370c
19943f7
 
40945fb
 
19943f7
 
7e80a40
1a9370c
40945fb
1a9370c
 
 
 
 
 
 
 
40945fb
1a9370c
40945fb
 
 
 
 
19943f7
 
1a9370c
 
40945fb
1a9370c
40945fb
1a9370c
 
 
19943f7
1a9370c
19943f7
1a9370c
 
 
 
 
 
 
 
 
 
 
 
40945fb
19943f7
1a9370c
 
 
19943f7
1a9370c
19943f7
1a9370c
19943f7
1a9370c
 
 
 
 
 
 
 
 
40945fb
1a9370c
 
 
 
19943f7
40945fb
1a9370c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40945fb
1a9370c
 
19943f7
40945fb
1a9370c
 
 
 
 
 
40945fb
 
19943f7
1a9370c
 
 
 
 
 
 
8d07207
1a9370c
27d400a
8d07207
1a9370c
 
8d07207
1a9370c
 
 
 
 
 
 
19943f7
 
 
40945fb
1a9370c
19943f7
1a9370c
 
19943f7
1a9370c
 
19943f7
40945fb
19943f7
1a9370c
19943f7
 
1a9370c
19943f7
 
 
1a9370c
19943f7
40945fb
19943f7
 
 
 
 
 
 
1a9370c
 
19943f7
1a9370c
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from IPython.display import display, HTML, clear_output, Image
from ipywidgets import widgets, Layout
from IPython import get_ipython
from pathlib import Path
import subprocess, time, os, shlex
from nenen88 import pull, say, download, clone, tempe

version = "v1.9.4"
repo = f"git clone -q -b {version} https://github.com/gutris1/asd"

home = Path.home()
webui = home / "asd"
img = home / ".conda/loading.png"

os.chdir(home)

if webui.exists():
    git_dir = webui / '.git'
    if git_dir.exists():
        os.chdir(webui)
        commit_hash = os.popen('git rev-parse HEAD').read().strip()

        if commit_hash != version:
            get_ipython().system(f"git pull origin {version}")
            get_ipython().system("git fetch --tags")

else:
    css = home / ".conda/setup.css"
    devnull = {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}

    get_ipython().system(f"curl -sLo {css} https://github.com/gutris1/segsmaker/raw/main/ui/sd/asd/setup.css")

    loading = widgets.Output()
    button1 = widgets.Button(description='SD 1.5')
    install_button = widgets.Button(description='Install')

    button_button = widgets.HBox([button1], layout=Layout(justify_content='space-between'))
    sd_setup = widgets.Output()
    panel = widgets.VBox([button_button, install_button],
                         layout=Layout(
                             width='400px',
                             height='150px',
                             display='flex',
                             flex_flow='column',
                             align_items='center',
                             justify_content='space-between',
                             padding='20px'))
    button1.add_class("b1")
    install_button.add_class("out")
    panel.add_class("boxxx")
    selected = [None]

    def load_css(css):
        with css.open("r") as file:
            ccs = file.read()

        display(HTML(f"<style>{ccs}</style>"))

    def req_list(home, webui):
        return [
            f"rm -rf {home}/tmp/* {home}/tmp {webui}/models/Stable-diffusion/tmp_ckpt {webui}/models/Lora/tmp_lora {webui}/models/ControlNet",
            f"mkdir -p {webui}/models/Lora",
            f"mkdir -p {webui}/models/ESRGAN",
            f"ln -vs /tmp {home}/tmp",
            f"ln -vs /tmp/ckpt {webui}/models/Stable-diffusion/tmp_ckpt",
            f"ln -vs /tmp/lora {webui}/models/Lora/tmp_lora",
            f"ln -vs /tmp/controlnet {webui}/models/ControlNet"]

    def sd_clone(home, webui, devnull):
        time.sleep(1)
        pull(f"https://github.com/gutris1/segsmaker sd {webui}")

        os.chdir(webui)
        req = req_list(home, webui)

        for lines in req:
            subprocess.run(shlex.split(lines), **devnull)
            
        scripts = [
            f"https://github.com/gutris1/segsmaker/raw/main/script/zrok_reg.py {webui}/asd",
            f"https://github.com/gutris1/segsmaker/raw/main/script/zrok.py {webui}",
            f"https://github.com/gutris1/segsmaker/raw/main/script/pinggy.py {webui}",
            f"https://github.com/gutris1/segsmaker/raw/main/script/ngrok.py {webui}",
            f"https://github.com/gutris1/segsmaker/raw/main/script/venv.py {webui}"]
            
        upscalers = [
            f"https://huggingface.co/pantat88/ui/resolve/main/4x-UltraSharp.pth {webui}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x-AnimeSharp.pth {webui}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_NMKD-Superscale-SP_178000_G.pth {webui}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_RealisticRescaler_100000_G.pth {webui}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/8x_RealESRGAN.pth {webui}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_foolhardy_Remacri.pth {webui}/models/ESRGAN"]
        
        line = scripts + upscalers
        for item in line:
            download(item)

    def sd_1_5(home, webui, devnull):
        sd_clone(home, webui, devnull)

        extras = [
            f"https://github.com/gutris1/segsmaker/raw/main/script/controlnet/cn-1_5.css {webui}/asd",
            f"https://github.com/gutris1/segsmaker/raw/main/script/controlnet/cn-1_5.py {webui}/asd",
            f"https://huggingface.co/Carlos2312/asd/resolve/main/modelos.py {webui}/asd",
            f"https://huggingface.co/Carlos2312/asd/resolve/main/ext-1_5.txt {webui}/asd",
            f"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors {webui}/models/VAE"]

        for items in extras:
            download(items)

        say("<br><b>【{red} Installing Extensions{d} 】{red}</b>")
        os.chdir(webui / "extensions")
        clone(str(webui / "asd/ext-1_5.txt"))
        os.rename(str(webui / "asd/cn-1_5.py"), str(webui / "asd/controlnet.py"))
        
        get_ipython().system(f"rm -rf {webui}/embeddings")
        get_ipython().system(f"git clone https://huggingface.co/Carlos2312/emb {webui}/embeddings")

        get_ipython().system(f"rm -rf {webui}/models/Lora")
        get_ipython().system(f"git clone https://huggingface.co/Carlos2312/lrs {webui}/models/Lora")

        get_ipython().system(f"rm -rf {webui}/models/adetailer")
        get_ipython().system(f"git clone https://huggingface.co/Carlos2312/md {webui}/models/adetailer")

        get_ipython().system(f"rm -rf {webui}/extensions/sd-dynamic-prompts/wildcards")
        get_ipython().system(f"git clone https://huggingface.co/Carlos2312/Wilcards {webui}/extensions/sd-dynamic-prompts/wildcards")
        
    def sd_install(selection):
        with loading:
            clear_output()
            display(Image(filename=str(img)))

        with sd_setup:
            sd_setup.clear_output()
            say("<b>【{red} Installing Stable Diffusion{d} 】{red}</b>")
            get_ipython().system(f"{repo}")

            if selection == 'SD 1.5':
                sd_1_5(home, webui, devnull)
                
            with loading:
                loading.clear_output()
                
            say("<br><b>【{red} Done{d} 】{red}</b>")

    def button_panel(button):
        selected[0] = button.description

    def installing(button):
        selection = selected[0]

        if selection:
            widgets.Widget.close(panel)
            sd_setup.clear_output()
            sd_install(selection)

        else:
            with sd_setup:
                print("at least make a choice")
                print("ε°‘γͺγγ¨γ‚‚ιΈζŠžγ—γ¦γ‚ˆγ€‚")
            return

    button1.on_click(button_panel)
    install_button.on_click(installing)

    load_css(css)
    display(panel, sd_setup, loading)
    tempe()