Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🐶
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: blue
|
|
|
|
| 1 |
---
|
| 2 |
+
title: WebUI test
|
| 3 |
emoji: 🐶
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: blue
|
app.py
CHANGED
|
@@ -8,59 +8,23 @@ else:
|
|
| 8 |
def wrapper(*args, **kwargs):
|
| 9 |
return func(*args, **kwargs)
|
| 10 |
return wrapper
|
| 11 |
-
import subprocess
|
| 12 |
-
import gc
|
| 13 |
import sys
|
| 14 |
from pathlib import Path
|
| 15 |
-
from utils import set_token,
|
|
|
|
|
|
|
| 16 |
|
| 17 |
@spaces.GPU
|
| 18 |
def fake_gpu():
|
| 19 |
pass
|
| 20 |
|
| 21 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 22 |
-
CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
|
| 23 |
-
set_token(HF_TOKEN)
|
| 24 |
BASE_DIR = str(Path(__file__).resolve().parent.resolve())
|
| 25 |
WEBUI_DIR = str(Path(BASE_DIR, "stable-diffusion-webui").resolve())
|
| 26 |
#os.environ["PYTHONPATH"] = os.environ.get("PYTHONPATH") + f":{WEBUI_DIR}:."
|
| 27 |
|
| 28 |
-
def get_file(url: str, path: str):
|
| 29 |
-
print(f"Downloading {url} to {path}...")
|
| 30 |
-
get_download_file(path, url, CIVITAI_API_KEY)
|
| 31 |
-
|
| 32 |
-
def git_clone(url: str, path: str, pip: bool=False, addcmd: str=""):
|
| 33 |
-
os.makedirs(str(Path(BASE_DIR, path)), exist_ok=True)
|
| 34 |
-
os.chdir(Path(BASE_DIR, path))
|
| 35 |
-
print(f"Cloning {url} to {path}...")
|
| 36 |
-
cmd = f'git clone {url}'
|
| 37 |
-
print(f'Running {cmd} at {Path.cwd()}')
|
| 38 |
-
i = subprocess.run(cmd, shell=True).returncode
|
| 39 |
-
if i != 0: print(f'Error occured at running {cmd}')
|
| 40 |
-
p = url.split("/")[-1]
|
| 41 |
-
if not Path(p).exists: return
|
| 42 |
-
if pip:
|
| 43 |
-
os.chdir(Path(BASE_DIR, path, p))
|
| 44 |
-
cmd = f'pip install -r requirements.txt'
|
| 45 |
-
print(f'Running {cmd} at {Path.cwd()}')
|
| 46 |
-
i = subprocess.run(cmd, shell=True).returncode
|
| 47 |
-
if i != 0: print(f'Error occured at running {cmd}')
|
| 48 |
-
if addcmd:
|
| 49 |
-
os.chdir(Path(BASE_DIR, path, p))
|
| 50 |
-
cmd = addcmd
|
| 51 |
-
print(f'Running {cmd} at {Path.cwd()}')
|
| 52 |
-
i = subprocess.run(cmd, shell=True).returncode
|
| 53 |
-
if i != 0: print(f'Error occured at running {cmd}')
|
| 54 |
-
|
| 55 |
-
def run(cmd: str):
|
| 56 |
-
print(f'Running {cmd} at {Path.cwd()}')
|
| 57 |
-
i = subprocess.run(cmd, shell=True).returncode
|
| 58 |
-
if i != 0: print(f'Error occured at running {cmd}')
|
| 59 |
-
|
| 60 |
git_clone("https://github.com/AUTOMATIC1111/stable-diffusion-webui.git", BASE_DIR)
|
| 61 |
|
| 62 |
os.chdir(WEBUI_DIR)
|
| 63 |
#sys.path.insert(0, WEBUI_DIR)
|
| 64 |
#run(f"python3 launch.py --precision full --no-half --no-half-vae --enable-insecure-extension-access --medvram --always-cpu --skip-torch-cuda-test --disable-gpu-warning --enable-console-prompts")
|
| 65 |
run(f"python3 launch.py --precision full --no-half --no-half-vae --enable-insecure-extension-access --medvram --skip-torch-cuda-test --enable-console-prompts")
|
| 66 |
-
|
|
|
|
| 8 |
def wrapper(*args, **kwargs):
|
| 9 |
return func(*args, **kwargs)
|
| 10 |
return wrapper
|
|
|
|
|
|
|
| 11 |
import sys
|
| 12 |
from pathlib import Path
|
| 13 |
+
from utils import set_token, git_clone, run, get_file
|
| 14 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 15 |
+
set_token(HF_TOKEN)
|
| 16 |
|
| 17 |
@spaces.GPU
|
| 18 |
def fake_gpu():
|
| 19 |
pass
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
BASE_DIR = str(Path(__file__).resolve().parent.resolve())
|
| 22 |
WEBUI_DIR = str(Path(BASE_DIR, "stable-diffusion-webui").resolve())
|
| 23 |
#os.environ["PYTHONPATH"] = os.environ.get("PYTHONPATH") + f":{WEBUI_DIR}:."
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
git_clone("https://github.com/AUTOMATIC1111/stable-diffusion-webui.git", BASE_DIR)
|
| 26 |
|
| 27 |
os.chdir(WEBUI_DIR)
|
| 28 |
#sys.path.insert(0, WEBUI_DIR)
|
| 29 |
#run(f"python3 launch.py --precision full --no-half --no-half-vae --enable-insecure-extension-access --medvram --always-cpu --skip-torch-cuda-test --disable-gpu-warning --enable-console-prompts")
|
| 30 |
run(f"python3 launch.py --precision full --no-half --no-half-vae --enable-insecure-extension-access --medvram --skip-torch-cuda-test --enable-console-prompts")
|
|
|
packages.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
git-lfs
|
|
|
|
| 1 |
+
aria2 git libgl1 libglib2.0-0 make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev git git-lfs ffmpeg libsm6 libxext6 cmake libgl1-mesa-glx
|
utils.py
CHANGED
|
@@ -6,6 +6,7 @@ import shutil
|
|
| 6 |
import gc
|
| 7 |
import re
|
| 8 |
import urllib.parse
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def get_token():
|
|
@@ -227,3 +228,41 @@ def duplicate_hf_repo(src_repo: str, dst_repo: str, src_repo_type: str, dst_repo
|
|
| 227 |
print(f"Error: Failed to duplicate repo {src_repo} to {dst_repo}. {e}")
|
| 228 |
return ""
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import gc
|
| 7 |
import re
|
| 8 |
import urllib.parse
|
| 9 |
+
import subprocess
|
| 10 |
|
| 11 |
|
| 12 |
def get_token():
|
|
|
|
| 228 |
print(f"Error: Failed to duplicate repo {src_repo} to {dst_repo}. {e}")
|
| 229 |
return ""
|
| 230 |
|
| 231 |
+
|
| 232 |
+
BASE_DIR = str(Path(__file__).resolve().parent.resolve())
|
| 233 |
+
CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def get_file(url: str, path: str): # requires aria2, gdown
|
| 237 |
+
print(f"Downloading {url} to {path}...")
|
| 238 |
+
get_download_file(path, url, CIVITAI_API_KEY)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def git_clone(url: str, path: str, pip: bool=False, addcmd: str=""): # requires git
|
| 242 |
+
os.makedirs(str(Path(BASE_DIR, path)), exist_ok=True)
|
| 243 |
+
os.chdir(Path(BASE_DIR, path))
|
| 244 |
+
print(f"Cloning {url} to {path}...")
|
| 245 |
+
cmd = f'git clone {url}'
|
| 246 |
+
print(f'Running {cmd} at {Path.cwd()}')
|
| 247 |
+
i = subprocess.run(cmd, shell=True).returncode
|
| 248 |
+
if i != 0: print(f'Error occured at running {cmd}')
|
| 249 |
+
p = url.split("/")[-1]
|
| 250 |
+
if not Path(p).exists: return
|
| 251 |
+
if pip:
|
| 252 |
+
os.chdir(Path(BASE_DIR, path, p))
|
| 253 |
+
cmd = f'pip install -r requirements.txt'
|
| 254 |
+
print(f'Running {cmd} at {Path.cwd()}')
|
| 255 |
+
i = subprocess.run(cmd, shell=True).returncode
|
| 256 |
+
if i != 0: print(f'Error occured at running {cmd}')
|
| 257 |
+
if addcmd:
|
| 258 |
+
os.chdir(Path(BASE_DIR, path, p))
|
| 259 |
+
cmd = addcmd
|
| 260 |
+
print(f'Running {cmd} at {Path.cwd()}')
|
| 261 |
+
i = subprocess.run(cmd, shell=True).returncode
|
| 262 |
+
if i != 0: print(f'Error occured at running {cmd}')
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def run(cmd: str):
|
| 266 |
+
print(f'Running {cmd} at {Path.cwd()}')
|
| 267 |
+
i = subprocess.run(cmd, shell=True).returncode
|
| 268 |
+
if i != 0: print(f'Error occured at running {cmd}')
|