TheLastBen commited on
Commit
32c4260
1 Parent(s): 13040f6

Update mainpaperspacev2.py

Browse files
Files changed (1) hide show
  1. mainpaperspacev2.py +40 -32
mainpaperspacev2.py CHANGED
@@ -61,34 +61,37 @@ def Deps(force_reinstall):
61
 
62
  def downloadmodel_hfv2(Path_to_HuggingFace):
63
  import wget
64
- os.chdir('/models')
65
- if os.path.exists('stable-diffusion-custom'):
66
- call("rm -r stable-diffusion-custom", shell=True)
67
-
68
- if os.path.exists('/content/gdrive/MyDrive/Fast-Dreambooth/token.txt'):
69
- with open("/content/gdrive/MyDrive/Fast-Dreambooth/token.txt") as f:
 
70
  token = f.read()
71
  authe=f'https://USER:{token}@'
72
  else:
73
- authe="https://"
74
 
75
- call("mkdir stable-diffusion-custom", shell=True)
76
- os.chdir("stable-diffusion-custom")
 
77
  call("git init", shell=True)
78
  call("git lfs install --system --skip-repo", shell=True)
79
  call('git remote add -f origin '+authe+'huggingface.co/'+Path_to_HuggingFace, shell=True)
80
  call("git config core.sparsecheckout true", shell=True)
81
  call('echo -e "\nscheduler\ntext_encoder\ntokenizer\nunet\nvae\nfeature_extractor\nmodel_index.json\n!*.safetensors" > .git/info/sparse-checkout', shell=True)
82
  call("git pull origin main", shell=True)
83
- if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
84
- call("rm -r stable-diffusion-custom/.git", shell=True)
 
85
  clear_output()
86
  done()
87
- else:
88
- while not os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
89
- print('Check the link you provided')
90
- time.sleep(5)
91
- os.chdir('/notebooks')
92
 
93
 
94
 
@@ -107,18 +110,20 @@ def downloadmodel_pthv2(CKPT_Path, Custom_Model_Version):
107
  call('python convertodiff.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
108
  call('rm convertodiff.py', shell=True)
109
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
 
110
  clear_output()
111
  done()
112
- else:
113
- call('rm -r stable-diffusion-custom', shell=True)
114
- while not os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
115
- print('Conversion error')
116
- time.sleep(5)
117
  else:
118
  while not os.path.exists(str(CKPT_Path)):
119
  print('Wrong path, use the colab file explorer to copy the path')
 
120
  time.sleep(5)
121
- os.chdir('/notebooks')
122
 
123
 
124
 
@@ -133,26 +138,29 @@ def downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version):
133
  if Custom_Model_Version=='512':
134
  wget.download('https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dreambooth/convertodiffv2.py')
135
  clear_output()
136
- call('python convertodiff.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
137
  elif Custom_Model_Version=='768':
138
  wget.download('https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dreambooth/convertodiffv2.py')
139
  clear_output()
140
- call('python convertodiff.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
141
  call('rm convertodiff.py', shell=True)
142
  call('rm model.ckpt', shell=True)
143
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
 
144
  clear_output()
145
  done()
146
- else:
147
- call('rm -r stable-diffusion-custom', shell=True)
148
- while not os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
149
- print('Conversion error')
150
- time.sleep(5)
151
- else:
152
  while os.path.getsize('model.ckpt') < 1810671599:
153
  print('Wrong link, check that the link is valid')
 
154
  time.sleep(5)
155
- os.chdir('/notebooks')
 
156
 
157
 
158
  def dlv2(Path_to_HuggingFace, CKPT_Path, CKPT_Link, Model_Version, Custom_Model_Version):
@@ -171,7 +179,7 @@ def dlv2(Path_to_HuggingFace, CKPT_Path, CKPT_Link, Model_Version, Custom_Model_
171
  MODEL_NAMEv2="dataset"
172
  print('Using the original V2-512 model')
173
  elif Model_Version=="768":
174
- MODEL_NAMEv2="dataset"
175
  print('Using the original V2-768 model')
176
  else:
177
  MODEL_NAMEv2=""
 
61
 
62
  def downloadmodel_hfv2(Path_to_HuggingFace):
63
  import wget
64
+
65
+ if os.path.exists('/models/stable-diffusion-custom'):
66
+ call("rm -r /models/stable-diffusion-custom", shell=True)
67
+ clear_output()
68
+
69
+ if os.path.exists('/notebooks/Fast-Dreambooth/token.txt'):
70
+ with open("/notebooks/Fast-Dreambooth/token.txt") as f:
71
  token = f.read()
72
  authe=f'https://USER:{token}@'
73
  else:
74
+ authe="https://"
75
 
76
+ clear_output()
77
+ call("mkdir /models/stable-diffusion-custom", shell=True)
78
+ os.chdir("/models/stable-diffusion-custom")
79
  call("git init", shell=True)
80
  call("git lfs install --system --skip-repo", shell=True)
81
  call('git remote add -f origin '+authe+'huggingface.co/'+Path_to_HuggingFace, shell=True)
82
  call("git config core.sparsecheckout true", shell=True)
83
  call('echo -e "\nscheduler\ntext_encoder\ntokenizer\nunet\nvae\nfeature_extractor\nmodel_index.json\n!*.safetensors" > .git/info/sparse-checkout', shell=True)
84
  call("git pull origin main", shell=True)
85
+ if os.path.exists('unet/diffusion_pytorch_model.bin'):
86
+ call("rm -r .git", shell=True)
87
+ os.chdir('/notebooks')
88
  clear_output()
89
  done()
90
+ while not os.path.exists('/models/stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
91
+ print('Check the link you provided')
92
+ os.chdir('/notebooks')
93
+ time.sleep(5)
94
+
95
 
96
 
97
 
 
110
  call('python convertodiff.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
111
  call('rm convertodiff.py', shell=True)
112
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
113
+ os.chdir('/notebooks')
114
  clear_output()
115
  done()
116
+ while not os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
117
+ print('Conversion error')
118
+ os.chdir('/notebooks')
119
+ time.sleep(5)
120
+
121
  else:
122
  while not os.path.exists(str(CKPT_Path)):
123
  print('Wrong path, use the colab file explorer to copy the path')
124
+ os.chdir('/notebooks')
125
  time.sleep(5)
126
+
127
 
128
 
129
 
 
138
  if Custom_Model_Version=='512':
139
  wget.download('https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dreambooth/convertodiffv2.py')
140
  clear_output()
141
+ call('python convertodiff.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
142
  elif Custom_Model_Version=='768':
143
  wget.download('https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dreambooth/convertodiffv2.py')
144
  clear_output()
145
+ call('python convertodiff.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
146
  call('rm convertodiff.py', shell=True)
147
  call('rm model.ckpt', shell=True)
148
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
149
+ os.chdir('/notebooks')
150
  clear_output()
151
  done()
152
+
153
+ while not os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
154
+ print('Conversion error')
155
+ os.chdir('/notebooks')
156
+ time.sleep(5)
157
+
158
  while os.path.getsize('model.ckpt') < 1810671599:
159
  print('Wrong link, check that the link is valid')
160
+ os.chdir('/notebooks')
161
  time.sleep(5)
162
+
163
+
164
 
165
 
166
  def dlv2(Path_to_HuggingFace, CKPT_Path, CKPT_Link, Model_Version, Custom_Model_Version):
 
179
  MODEL_NAMEv2="dataset"
180
  print('Using the original V2-512 model')
181
  elif Model_Version=="768":
182
+ MODEL_NAMEv2="/datasets/stable-diffusion-v2-1/stable-diffusion-2-1"
183
  print('Using the original V2-768 model')
184
  else:
185
  MODEL_NAMEv2=""