File size: 7,538 Bytes
46c2869
 
 
88c525e
46c2869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17aa26e
46c2869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17aa26e
46c2869
 
 
 
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
from IPython.display import display, HTML, clear_output
from IPython import get_ipython
from pathlib import Path
from ipywidgets import widgets, Layout
import subprocess, time, os, shlex
from nenen88 import pull, say, download, clone, tempe

version = "v1.9.3"
xxx = "/home/studio-lab-user"
zzz = Path(xxx) / "asd"

if zzz.exists():
    git_dir = zzz / '.git'
    if git_dir.exists():
        os.chdir(zzz)
        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:
    mama = f"{xxx}/.conda/setup.css"
    fff = {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}

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

    gariz = """<div class="gradient-text">asd</div>"""
    garis = widgets.Output()
    sd_setup = widgets.Output()
    
    def ccss(mama):
        with open(mama, "r") as gantung:
            susu = gantung.read()
        display(HTML(f"<style>{susu}</style>"))

    def req_list(xxx, zzz):
        return [
            f"pip install -q -r requirements.txt basicsr insightface onnxruntime-gpu",
            f"rm -rf {xxx}/tmp/* {xxx}/tmp {zzz}/models/Stable-diffusion/tmp_ckpt {zzz}/models/Lora/tmp_lora {zzz}/models/ControlNet",
            f"mkdir -p {zzz}/models/Lora",
            f"mkdir -p {zzz}/models/ESRGAN",
            f"ln -vs /tmp {xxx}/tmp",
            f"ln -vs /tmp/ckpt {zzz}/models/Stable-diffusion/tmp_ckpt",
            f"ln -vs /tmp/lora {zzz}/models/Lora/tmp_lora",
            f"ln -vs /tmp/controlnet {zzz}/models/ControlNet"
        ]

    def sd_clone(xxx, zzz, fff):
        time.sleep(1)
        pull(f"https://github.com/gutris1/segsmaker sd {zzz}")
        os.chdir(zzz)
        req = req_list(xxx, zzz)
        for lines in req:
            subprocess.run(shlex.split(lines), **fff)

    def sd_1_5(xxx, zzz, fff):
        sd_clone(xxx, zzz, fff)
        extras = [
            f"https://civitai.com/api/download/models/150491 {zzz}/embeddings edgQuality.pt",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x-UltraSharp.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x-AnimeSharp.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_NMKD-Superscale-SP_178000_G.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_RealisticRescaler_100000_G.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/8x_RealESRGAN.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_foolhardy_Remacri.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors {zzz}/models/VAE",
            f"https://github.com/gutris1/segsmaker/raw/main/script/zrok_reg.py {zzz}/asd",
            f"https://huggingface.co/Carlos2312/asd/resolve/main/modelos.py {zzz}/asd",
            f"https://huggingface.co/Carlos2312/asd/resolve/main/ext-1_5.txt {zzz}/asd",
            f"https://github.com/gutris1/segsmaker/raw/main/script/zrok.py {zzz}",
            f"https://github.com/gutris1/segsmaker/raw/main/script/pinggy.py {zzz}"
        ]
        for items in extras:
            download(items)
        
        #add
        # extension
        os.chdir(f"{zzz}/extensions")
        clone(f"{zzz}/asd/ext-1_5.txt")

        weww = f"{zzz}/asd/cn-1_5.py"
        woww = f"{zzz}/asd/controlnet.py"
        os.rename(weww, woww)

        get_ipython().system(f"rm -rf {zzz}/embeddings")
        get_ipython().system(f"git clone https://huggingface.co/Carlos2312/emb {zzz}/embeddings")

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

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

        get_ipython().system(f"rm -rf {zzz}/extensions/sd-dynamic-prompts/wildcards")
        get_ipython().system(f"git clone https://huggingface.co/Carlos2312/Wilcards {zzz}/extensions/sd-dynamic-prompts/wildcards")

    def sd_xl(xxx, zzz, fff):
        sd_clone(xxx, zzz, fff)
        extras = [
            f"https://civitai.com/api/download/models/182974 {zzz}/embeddings",
            f"https://civitai.com/api/download/models/159385 {zzz}/embeddings",
            f"https://civitai.com/api/download/models/159184 {zzz}/embeddings",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x-UltraSharp.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x-AnimeSharp.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_NMKD-Superscale-SP_178000_G.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_RealisticRescaler_100000_G.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/8x_RealESRGAN.pth {zzz}/models/ESRGAN",
            f"https://huggingface.co/pantat88/ui/resolve/main/4x_foolhardy_Remacri.pth {zzz}/models/ESRGAN",
            f"https://civitai.com/api/download/models/264491 {zzz}/models/VAE XL_VAE_F1.safetensors",
            f"https://github.com/gutris1/segsmaker/raw/main/script/zrok_reg.py {zzz}/asd",
            f"https://github.com/gutris1/segsmaker/raw/main/script/zrok.py {zzz}",
            f"https://github.com/gutris1/segsmaker/raw/main/script/pinggy.py {zzz}"
        ]
        for items in extras:
            download(items)
        say("<br><b>【{red} Installing Extensions{d} 】{red}</b>")
        os.chdir(f"{zzz}/extensions")
        clone(f"{zzz}/asd/ext-xl.txt")
        os.rename(f"{zzz}/asd/cn-xl.py", f"{zzz}/asd/controlnet.py")

    def zrok_install():
        zrok = Path(f"{xxx}/.zrok/bin")
        zrok.mkdir(parents=True, exist_ok=True)
        url = "https://github.com/openziti/zrok/releases/download/v0.4.25/zrok_0.4.25_linux_amd64.tar.gz"
        z = zrok / Path(url).name
        get_ipython().system(f"curl -sLo {z} {url}")
        get_ipython().system(f"tar -xzf {z} -C {zrok} --wildcards *zrok")
        get_ipython().system(f"rm -rf {xxx}/.cache/* {z}")

    def sd_install(selection):  
        with garis:
            display(HTML(gariz))
        with sd_setup:
            sd_setup.clear_output()
            os.chdir(xxx)
            say("<b>【{red} Installing Stable Diffusion{d} 】{red}</b>")
            get_ipython().system(f"git clone -q -b {version} https://github.com/gutris1/asd")
            if selection == 'SD 1.5':
                sd_1_5(xxx, zzz, fff)
            else:
                sd_xl(xxx, zzz, fff)
            with garis:
                garis.clear_output()
            say("<br><b>【{red} Done{d} 】{red}</b>")

    def uuwaaahhh(button):
        selection = 'SD 1.5'
        if selection:
            sd_setup.clear_output()
            sd_install(selection)
        else:
            with sd_setup:
                print("at least make a choice")
                print("ε°‘γͺγγ¨γ‚‚ιΈζŠžγ—γ¦γ‚ˆγ€‚")
            return

    ccss(mama)
    display(sd_setup, garis)
    zrok_install()
    tempe()
    # Automatically trigger the installation of SD 1.5
    uuwaaahhh(None)