MesutUnutur commited on
Commit
264fdc0
1 Parent(s): b640dfb

Create app

Browse files
Files changed (1) hide show
  1. app +160 -0
app ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import sys
4
+ import fileinput
5
+ from IPython.display import clear_output
6
+ from subprocess import getoutput
7
+ from IPython.utils import capture
8
+ from pyngrok import ngrok, conf
9
+ import base64
10
+
11
+ blasphemy=base64.b64decode(("d2VidWk=")).decode('ascii')
12
+
13
+ Previous_Session="" #@param{type: 'string'}
14
+
15
+ #@markdown - Leave empty if you want to use the current trained model.
16
+
17
+ Use_Custom_Path = False #@param {type:"boolean"}
18
+
19
+ try:
20
+ INSTANCE_NAME
21
+ INSTANCET=INSTANCE_NAME
22
+ except:
23
+ pass
24
+ #@markdown - if checked, an input box will ask the full path to a desired model.
25
+
26
+ if Previous_Session!="":
27
+ INSTANCET=Previous_Session
28
+ INSTANCET=INSTANCET.replace(" ","_")
29
+
30
+ if Use_Custom_Path:
31
+ try:
32
+ INSTANCET
33
+ del INSTANCET
34
+ except:
35
+ pass
36
+
37
+ try:
38
+ INSTANCET
39
+ if Previous_Session!="":
40
+ path_to_trained_model='/content/gdrive/MyDrive/Fast-Dreambooth/Sessions/'+Previous_Session+"/"+Previous_Session+'.ckpt'
41
+ else:
42
+ path_to_trained_model=SESSION_DIR+"/"+INSTANCET+'.ckpt'
43
+ except:
44
+ print('It seems that you did not perform training during this session or you chose to use a custom path,\nprovide the full path to the model (including the name of the model):\n')
45
+ path_to_trained_model=input()
46
+
47
+ while not os.path.exists(path_to_trained_model):
48
+ print("The model doesn't exist on you Gdrive, use the file explorer to get the path : ")
49
+ path_to_trained_model=input()
50
+
51
+ fgitclone = "git clone --depth 1"
52
+
53
+ with capture.capture_output() as cap:
54
+ if not os.path.exists('/content/gdrive/MyDrive'):
55
+ !mkdir -p /content/gdrive/MyDrive
56
+
57
+ if not os.path.exists('/content/gdrive/MyDrive/sd/stablediffusion'):
58
+ !wget -q -O /content/sd_rep.tar.zst https://huggingface.co/TheLastBen/dependencies/resolve/main/sd_rep.tar.zst
59
+ !tar -C /content/gdrive/MyDrive --zstd -xf /content/sd_rep.tar.zst
60
+ !rm /content/sd_rep.tar.zst
61
+ clear_output()
62
+
63
+ with capture.capture_output() as cap:
64
+ %cd /content/gdrive/MyDrive/sd
65
+ !git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-$blasphemy
66
+ %cd stable-diffusion-$blasphemy
67
+ !mkdir cache
68
+ !sed -i 's@~/.cache@/content/gdrive/MyDrive/sd/stable-diffusion-{blasphemy}/cache@' /usr/local/lib/python3.10/dist-packages/transformers/utils/hub.py
69
+
70
+ clear_output()
71
+ !git reset --hard
72
+ time.sleep(1)
73
+ !rm webui.sh
74
+ !git pull
75
+ !git fetch --unshallow
76
+ !git checkout a9eab236d7e8afa4d6205127904a385b2c43bb24
77
+
78
+ with capture.capture_output() as cap:
79
+ if not os.path.exists('/tools/node/bin/lt'):
80
+ !npm install -g localtunnel
81
+
82
+ Ngrok_token = "" #@param {type:"string"}
83
+
84
+ #@markdown - Input your ngrok token if you want to use ngrok server.
85
+
86
+ Use_localtunnel = False #@param {type:"boolean"}
87
+
88
+ User = "" #@param {type:"string"}
89
+ Password= "" #@param {type:"string"}
90
+ #@markdown - Add credentials to your Gradio interface (optional).
91
+
92
+ auth=f"--gradio-auth {User}:{Password}"
93
+ if User =="" or Password=="":
94
+ auth=""
95
+
96
+ with capture.capture_output() as cap:
97
+ %cd modules
98
+ !wget -q -O paths.py https://github.com/TheLastBen/fast-stable-diffusion/raw/5632d2ef7fffd940976538d270854ec4faf26855/AUTOMATIC1111_files/paths.py
99
+ !wget -q -O extras.py https://github.com/AUTOMATIC1111/stable-diffusion-$blasphemy/raw/a9eab236d7e8afa4d6205127904a385b2c43bb24/modules/extras.py
100
+ !wget -q -O sd_models.py https://github.com/AUTOMATIC1111/stable-diffusion-$blasphemy/raw/a9eab236d7e8afa4d6205127904a385b2c43bb24/modules/sd_models.py
101
+ !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://github.com/TheLastBen/fast-stable-diffusion/raw/7ff88eaa1fb4997bacd9845bd487f9a14335d625/AUTOMATIC1111_files/blocks.py
102
+ %cd /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy/
103
+
104
+ !sed -i "s@os.path.splitext(checkpoint_file)@os.path.splitext(checkpoint_file); map_location='cuda'@" /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy/modules/sd_models.py
105
+ !sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy/webui.py
106
+ !sed -i "s@map_location='cpu'@map_location='cuda'@" /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy/modules/extras.py
107
+ !sed -i 's@print(\"No module.*@@' /content/gdrive/MyDrive/sd/stablediffusion/ldm/modules/diffusionmodules/model.py
108
+ !sed -i 's@\"quicksettings\": OptionInfo(.*@"quicksettings": OptionInfo("sd_model_checkpoint, sd_vae, CLIP_stop_at_last_layers, inpainting_mask_weight, initial_noise_multiplier", "Quicksettings list"),@' /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy/modules/shared.py
109
+
110
+ share=''
111
+ if Ngrok_token!="":
112
+ ngrok.kill()
113
+ srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url
114
+
115
+ for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):
116
+ if line.strip().startswith('self.server_name ='):
117
+ line = f' self.server_name = "{srv[8:]}"\n'
118
+ if line.strip().startswith('self.protocol = "https"'):
119
+ line = ' self.protocol = "https"\n'
120
+ if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'):
121
+ line = ''
122
+ if line.strip().startswith('else "http"'):
123
+ line = ''
124
+ sys.stdout.write(line)
125
+
126
+ elif Use_localtunnel:
127
+ with capture.capture_output() as cap:
128
+ share=''
129
+ %cd /content
130
+ !nohup lt --port 7860 > srv.txt 2>&1 &
131
+ time.sleep(2)
132
+ !grep -o 'https[^ ]*' /content/srv.txt >srvr.txt
133
+ time.sleep(2)
134
+ srv= getoutput('cat /content/srvr.txt')
135
+
136
+ for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):
137
+ if line.strip().startswith('self.server_name ='):
138
+ line = f' self.server_name = "{srv[8:]}"\n'
139
+ if line.strip().startswith('self.protocol = "https"'):
140
+ line = ' self.protocol = "https"\n'
141
+ if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'):
142
+ line = ''
143
+ if line.strip().startswith('else "http"'):
144
+ line = ''
145
+ sys.stdout.write(line)
146
+
147
+ !rm /content/srv.txt /content/srvr.txt
148
+ %cd /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy
149
+
150
+ else:
151
+ share='--share'
152
+
153
+ configf="--api --disable-safe-unpickle --enable-insecure-extension-access --no-half-vae --opt-sdp-attention --no-download-sd-model --disable-console-progressbars"
154
+
155
+ clear_output()
156
+
157
+ if os.path.isfile(path_to_trained_model):
158
+ !python /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy/webui.py $share --ckpt "$path_to_trained_model" $auth $configf
159
+ else:
160
+ !python /content/gdrive/MyDrive/sd/stable-diffusion-$blasphemy/webui.py $share --ckpt-dir "$path_to_trained_model" $auth $configf