Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,60 @@
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
#Gitclone function
|
| 4 |
+
def Gitclone(URI:str,ClonePath:pathlib.Path ) -> int :
|
| 5 |
+
if pathlib.Path.exists(ClonePath):
|
| 6 |
+
return 0
|
| 7 |
+
for z in range(10):
|
| 8 |
+
i=subprocess.run([r"git",r"clone",str(URI),str(ClonePath)])
|
| 9 |
+
if(i.returncode == 0 ):
|
| 10 |
+
del i
|
| 11 |
+
return 0
|
| 12 |
+
else :
|
| 13 |
+
del i
|
| 14 |
+
raise Exception(str.format("clone \'{0}\' failed",URI))
|
| 15 |
|
| 16 |
+
#run_echo_command procedure
|
| 17 |
+
def run_echo_command():
|
| 18 |
+
try:
|
| 19 |
+
start_huggingface
|
| 20 |
+
except NameError:
|
| 21 |
+
start_huggingface = int(time.time()) - 5
|
| 22 |
|
| 23 |
+
cmd = f"echo -n {start_huggingface} > /home/user/app/stable-diffusion-webui/static/colabTimer.txt"
|
| 24 |
+
subprocess.run(cmd, shell=True)
|
| 25 |
+
|
| 26 |
+
user_home =pathlib.Path.home().resolve()
|
| 27 |
+
os.chdir(str(user_home))
|
| 28 |
+
|
| 29 |
+
#clone stable-diffusion-webui repo
|
| 30 |
+
print("cloning stable-diffusion-webui repo")
|
| 31 |
+
Gitclone(r"https://github.com/AUTOMATIC1111/stable-diffusion-webui.git",user_home / r"stable-diffusion-webui")
|
| 32 |
+
|
| 33 |
+
run_echo_command()
|
| 34 |
+
os.chdir(user_home / r"stable-diffusion-webui")
|
| 35 |
+
|
| 36 |
+
#strt Stable Diffusion Webui
|
| 37 |
+
print("Done\nStarting Webui...")
|
| 38 |
+
os.chdir(user_home / r"stable-diffusion-webui")
|
| 39 |
+
import subprocess
|
| 40 |
+
import pathlib
|
| 41 |
+
|
| 42 |
+
user_home = pathlib.Path("/home/user") # Gantilah dengan path yang sesuai
|
| 43 |
+
|
| 44 |
+
args = [
|
| 45 |
+
executable,
|
| 46 |
+
user_home / "stable-diffusion-webui" / "launch.py",
|
| 47 |
+
"--precision", "full",
|
| 48 |
+
"--no-half",
|
| 49 |
+
"--no-half-vae",
|
| 50 |
+
"--skip-torch-cuda-test",
|
| 51 |
+
"--ui-settings-file=" + str(pathlib.Path(__file__).parent / "config.json")
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
args = [arg.as_posix() if isinstance(arg, pathlib.PosixPath) else arg for arg in args]
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
ret = subprocess.run(args)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print("Error:", e)
|
| 60 |
+
del os ,user_home ,pyexecutable ,subprocess
|