TheLastBen commited on
Commit
2aa9830
1 Parent(s): c2de314

Upload 2 files

Browse files
Scripts/mainpaperspacev1.py CHANGED
@@ -19,6 +19,7 @@ import requests
19
  from collections import defaultdict
20
  from math import log, sqrt
21
  import numpy as np
 
22
 
23
 
24
 
@@ -804,6 +805,97 @@ def test(Custom_Path, Previous_Session_Name, Session_Name, User, Password, Use_l
804
 
805
 
806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
807
  def clean():
808
 
809
  Sessions=os.listdir("/notebooks/Fast-Dreambooth/Sessions")
 
19
  from collections import defaultdict
20
  from math import log, sqrt
21
  import numpy as np
22
+ from pyngrok import ngrok, conf
23
 
24
 
25
 
 
805
 
806
 
807
 
808
+ def testui(Custom_Path, Previous_Session_Name, Session_Name, User, Password, Ngrok_token):
809
+
810
+
811
+ if Previous_Session_Name!="":
812
+ print("Loading a previous session model")
813
+ mdldir='/notebooks/Fast-Dreambooth/Sessions/'+Previous_Session_Name
814
+ path_to_trained_model=mdldir+"/"+Previous_Session_Name+'.ckpt'
815
+
816
+
817
+ while not os.path.exists(path_to_trained_model):
818
+ print("There is no trained model in the previous session")
819
+ time.sleep(5)
820
+
821
+ elif Custom_Path!="":
822
+ print("Loading model from a custom path")
823
+ path_to_trained_model=Custom_Path
824
+
825
+
826
+ while not os.path.exists(path_to_trained_model):
827
+ print("Wrong Path")
828
+ time.sleep(5)
829
+
830
+ else:
831
+ print("Loading the trained model")
832
+ mdldir='/notebooks/Fast-Dreambooth/Sessions/'+Session_Name
833
+ path_to_trained_model=mdldir+"/"+Session_Name+'.ckpt'
834
+
835
+
836
+ while not os.path.exists(path_to_trained_model):
837
+ print("There is no trained model in this session")
838
+ time.sleep(5)
839
+
840
+ auth=f"--gradio-auth {User}:{Password}"
841
+ if User =="" or Password=="":
842
+ auth=""
843
+
844
+ os.chdir('/notebooks')
845
+ if not os.path.exists('/notebooks/sd/stablediffusion'):
846
+ call('wget -q -O sd_rep.tar.zst https://huggingface.co/TheLastBen/dependencies/resolve/main/sd_rep.tar.zst', shell=True)
847
+ call('tar --zstd -xf sd_rep.tar.zst', shell=True)
848
+ call('rm sd_rep.tar.zst', shell=True)
849
+
850
+ os.chdir('/notebooks/sd')
851
+ if not os.path.exists('stable-diffusion-webui'):
852
+ call('git clone -q --depth 1 --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui', shell=True)
853
+
854
+ os.chdir('/notebooks/sd/stable-diffusion-webui/')
855
+ call('git reset --hard', shell=True, stdout=open('/dev/null', 'w'))
856
+ print('')
857
+ call('git pull', shell=True, stdout=open('/dev/null', 'w'))
858
+ os.chdir('/notebooks')
859
+ clear_output()
860
+
861
+ if not os.path.exists('/usr/lib/node_modules/localtunnel'):
862
+ call('npm install -g localtunnel --silent', shell=True, stdout=open('/dev/null', 'w'))
863
+
864
+ share=''
865
+ call('wget -q -O /usr/local/lib/python3.9/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py', shell=True)
866
+
867
+ if Ngrok_token!="":
868
+ ngrok.kill()
869
+ srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url
870
+
871
+ for line in fileinput.input('/usr/local/lib/python3.9/dist-packages/gradio/blocks.py', inplace=True):
872
+ if line.strip().startswith('self.server_name ='):
873
+ line = f' self.server_name = "{srv[8:]}"\n'
874
+ if line.strip().startswith('self.protocol = "https"'):
875
+ line = ' self.protocol = "https"\n'
876
+ if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'):
877
+ line = ''
878
+ if line.strip().startswith('else "http"'):
879
+ line = ''
880
+ sys.stdout.write(line)
881
+
882
+ else:
883
+ share='--share'
884
+
885
+ os.chdir('/notebooks/sd/stable-diffusion-webui/modules')
886
+ call('wget -q -O paths.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/paths.py', shell=True)
887
+ call("sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /notebooks/sd/stable-diffusion-webui/webui.py", shell=True)
888
+ call("sed -i 's@/content/gdrive/MyDrive/sd/stablediffusion@/notebooks/sd/stablediffusion@' /notebooks/sd/stable-diffusion-webui/modules/paths.py", shell=True)
889
+ call("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\"),@' /notebooks/sd/stable-diffusion-webui/modules/shared.py", shell=True)
890
+ os.chdir('/notebooks/sd/stable-diffusion-webui')
891
+ clear_output()
892
+
893
+ configf="--disable-console-progressbars --no-half-vae --disable-safe-unpickle --api --no-download-sd-model --xformers --enable-insecure-extension-access --skip-version-check --ckpt "+path_to_trained_model+" "+auth+" "+share
894
+
895
+ return configf
896
+
897
+
898
+
899
  def clean():
900
 
901
  Sessions=os.listdir("/notebooks/Fast-Dreambooth/Sessions")
Scripts/mainpaperspacev2.py CHANGED
@@ -20,6 +20,7 @@ from collections import defaultdict
20
  from math import log, sqrt
21
  import numpy as np
22
  from subprocess import check_output
 
23
 
24
 
25
  def Deps(force_reinstall):
@@ -848,7 +849,99 @@ def test(Custom_Path, Previous_Session_Name, Session_Name, User, Password, Use_l
848
 
849
  return configf
850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
851
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
852
 
853
  def clean():
854
 
 
20
  from math import log, sqrt
21
  import numpy as np
22
  from subprocess import check_output
23
+ from pyngrok import ngrok, conf
24
 
25
 
26
  def Deps(force_reinstall):
 
849
 
850
  return configf
851
 
852
+
853
+
854
+ def testui(Custom_Path, Previous_Session_Name, Session_Name, User, Password, Ngrok_token):
855
+
856
+
857
+ if Previous_Session_Name!="":
858
+ print("Loading a previous session model")
859
+ mdldir='/notebooks/Fast-Dreambooth/Sessions/'+Previous_Session_Name
860
+ path_to_trained_model=mdldir+"/"+Previous_Session_Name+'.ckpt'
861
+
862
+
863
+ while not os.path.exists(path_to_trained_model):
864
+ print("There is no trained model in the previous session")
865
+ time.sleep(5)
866
+
867
+ elif Custom_Path!="":
868
+ print("Loading model from a custom path")
869
+ path_to_trained_model=Custom_Path
870
+
871
+
872
+ while not os.path.exists(path_to_trained_model):
873
+ print("Wrong Path")
874
+ time.sleep(5)
875
+
876
+ else:
877
+ print("Loading the trained model")
878
+ mdldir='/notebooks/Fast-Dreambooth/Sessions/'+Session_Name
879
+ path_to_trained_model=mdldir+"/"+Session_Name+'.ckpt'
880
+
881
+
882
+ while not os.path.exists(path_to_trained_model):
883
+ print("There is no trained model in this session")
884
+ time.sleep(5)
885
+
886
+ auth=f"--gradio-auth {User}:{Password}"
887
+ if User =="" or Password=="":
888
+ auth=""
889
+
890
+ os.chdir('/notebooks')
891
+ if not os.path.exists('/notebooks/sd/stablediffusion'):
892
+ call('wget -q -O sd_rep.tar.zst https://huggingface.co/TheLastBen/dependencies/resolve/main/sd_rep.tar.zst', shell=True)
893
+ call('tar --zstd -xf sd_rep.tar.zst', shell=True)
894
+ call('rm sd_rep.tar.zst', shell=True)
895
+
896
+ os.chdir('/notebooks/sd')
897
+ if not os.path.exists('stable-diffusion-webui'):
898
+ call('git clone -q --depth 1 --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui', shell=True)
899
+
900
+ os.chdir('/notebooks/sd/stable-diffusion-webui/')
901
+ call('git reset --hard', shell=True, stdout=open('/dev/null', 'w'))
902
+ print('')
903
+ call('git pull', shell=True, stdout=open('/dev/null', 'w'))
904
+ os.chdir('/notebooks')
905
+ clear_output()
906
+
907
+ if not os.path.exists('/usr/lib/node_modules/localtunnel'):
908
+ call('npm install -g localtunnel --silent', shell=True, stdout=open('/dev/null', 'w'))
909
+
910
+ share=''
911
+ call('wget -q -O /usr/local/lib/python3.9/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py', shell=True)
912
+
913
+ if Ngrok_token!="":
914
+ ngrok.kill()
915
+ srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url
916
 
917
+ for line in fileinput.input('/usr/local/lib/python3.9/dist-packages/gradio/blocks.py', inplace=True):
918
+ if line.strip().startswith('self.server_name ='):
919
+ line = f' self.server_name = "{srv[8:]}"\n'
920
+ if line.strip().startswith('self.protocol = "https"'):
921
+ line = ' self.protocol = "https"\n'
922
+ if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'):
923
+ line = ''
924
+ if line.strip().startswith('else "http"'):
925
+ line = ''
926
+ sys.stdout.write(line)
927
+
928
+ else:
929
+ share='--share'
930
+
931
+ os.chdir('/notebooks/sd/stable-diffusion-webui/modules')
932
+ call('wget -q -O paths.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/paths.py', shell=True)
933
+ call("sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /notebooks/sd/stable-diffusion-webui/webui.py", shell=True)
934
+ call("sed -i 's@/content/gdrive/MyDrive/sd/stablediffusion@/notebooks/sd/stablediffusion@' /notebooks/sd/stable-diffusion-webui/modules/paths.py", shell=True)
935
+ call("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\"),@' /notebooks/sd/stable-diffusion-webui/modules/shared.py", shell=True)
936
+ os.chdir('/notebooks/sd/stable-diffusion-webui')
937
+ clear_output()
938
+
939
+ configf="--disable-console-progressbars --no-half-vae --disable-safe-unpickle --api --no-download-sd-model --xformers --enable-insecure-extension-access --skip-version-check --ckpt "+path_to_trained_model+" "+auth+" "+share
940
+
941
+ return configf
942
+
943
+
944
+
945
 
946
  def clean():
947