having funn wrapping webui python scripts

This commit is contained in:
gbtb 2023-03-15 00:00:28 +10:00
parent c033caef7a
commit 89eec56d5b
3 changed files with 95 additions and 68 deletions

View File

@ -52,7 +52,8 @@
"invokeai-repo": "invokeai-repo",
"nixlib": "nixlib",
"nixpkgs": "nixpkgs",
"stable-diffusion-repo": "stable-diffusion-repo"
"stable-diffusion-repo": "stable-diffusion-repo",
"webui-repo": "webui-repo"
}
},
"stable-diffusion-repo": {
@ -71,6 +72,22 @@
"rev": "47b6b607fdd31875c9279cd2f4f16b92e4ea958e",
"type": "github"
}
},
"webui-repo": {
"flake": false,
"locked": {
"lastModified": 1678645522,
"narHash": "sha256-Z4hS9+tFrZUMxetPPExurw4xOlLeaFmYkrpjPaK5+Gk=",
"owner": "AUTOMATIC1111",
"repo": "stable-diffusion-webui",
"rev": "dfeee786f903e392dbef1519c7c246b9856ebab3",
"type": "github"
},
"original": {
"owner": "AUTOMATIC1111",
"repo": "stable-diffusion-webui",
"type": "github"
}
}
},
"root": "root",

View File

@ -14,8 +14,12 @@
url = "github:invoke-ai/InvokeAI?ref=v2.3.1.post2";
flake = false;
};
webui-repo = {
url = "github:AUTOMATIC1111/stable-diffusion-webui";
flake = false;
};
};
outputs = { self, nixpkgs, nixlib, stable-diffusion-repo, invokeai-repo }@inputs:
outputs = { self, nixpkgs, nixlib, stable-diffusion-repo, invokeai-repo, webui-repo }@inputs:
let
nixlib = inputs.nixlib.outputs.lib;
system = "x86_64-linux";
@ -68,6 +72,7 @@
picklescan
]
++ nixlib.optional webui [
pip
addict
future
lmdb
@ -247,7 +252,7 @@
nixpkgs = (nixpkgs_ { });
nixpkgsAmd = (nixpkgs_ { amd = true; });
nixpkgsNvidia = (nixpkgs_ { nvidia = true; });
invokeaiF = nixpkgs: nixpkgs.python3.pkgs.buildPythonPackage {
invokeaiF = nixpkgs: nixpkgs.python3.pkgs.buildPythonApplication {
pname = "invokeai";
version = "2.3.1";
src = invokeai-repo;
@ -257,6 +262,59 @@
pythonRelaxDeps = [ "torch" "pytorch-lightning" "flask-socketio" "flask" "dnspython" ];
pythonRemoveDeps = [ "opencv-python" "flaskwebgui" "pyreadline3" ];
};
submodel = pkg: nixpkgs.pkgs.python3.pkgs.${pkg} + "/lib/python3.10/site-packages";
taming-transformers = submodel "taming-transformers-rom1504";
k_diffusion = submodel "k-diffusion";
codeformer = (submodel "codeformer") + "/codeformer";
blip = (submodel "blip") + "/blip";
webuiF = nixpkgs: nixpkgs.python3.pkgs.buildPythonApplication {
pname = "stable-diffusion-webui";
version = "2023-03-12";
src = webui-repo;
format = "other";
propagatedBuildInputs = requirementsFor { pkgs = nixpkgs; webui = true; nvidia = nixpkgs.nvidia; };
nativeBuildInputs = [ nixpkgs.pkgs.makeWrapper ];
patches = [ ./webui.patch ];
patchFlags = [ "--binary" ];
buildPhase = ''
runHook preBuild
cp -r . $out
chmod -R +w $out
cd $out
cat <<-EOF > launch.py
$(echo "#!/usr/bin/python")
$(cat launch.py)
EOF
chmod +x launch.py
mv launch.py launch.py.wrapped
makeWrapper "$(pwd)/launch.py.wrapped" launch.py \
--set-default PYTHONPATH $PYTHONPATH \
--add-flags "--skip-install"
mkdir $out/bin
pushd $out/bin
ln -s ../launch.py .
popd
runHook postBuild
'';
installPhase = ''
runHook preInstall
rm -rf repositories/
mkdir repositories
pushd repositories
ln -s ${inputs.stable-diffusion-repo}/ stable-diffusion-stability-ai
ln -s ${taming-transformers}/ taming-transformers
ln -s ${k_diffusion}/ k-diffusion
ln -s ${codeformer}/ CodeFormer
ln -s ${blip}/ BLIP
popd
#makeWrapper $out/launch.py "launch"
runHook postInstall
'';
};
in
{
invokeai = {
@ -264,6 +322,11 @@
nvidia = invokeaiF nixpkgsNvidia;
default = invokeaiF nixpkgs;
};
webui = {
amd = webuiF nixpkgsAmd;
nvidia = webuiF nixpkgsNvidia;
default = webuiF nixpkgs;
};
};
devShells.${system} =
{
@ -276,12 +339,9 @@
k_diffusion = submodel "k-diffusion";
codeformer = (submodel "codeformer") + "/codeformer";
blip = (submodel "blip") + "/blip";
joinedModels = nixpkgs.symlinkJoin { name = "webui-models"; paths = [ inputs.stable-diffusion-repo taming-transformers k_diffusion codeformer blip ]; };
in
''
cd stable-diffusion-webui
#git reset --hard HEAD
#git apply ${./webui.patch}
rm -rf repositories/
mkdir repositories
pushd repositories
@ -291,11 +351,6 @@
ln -s ${codeformer}/ CodeFormer
ln -s ${blip}/ BLIP
popd
/* substituteInPlace modules/paths.py \ */
/* --subst-var-by taming_transformers ${taming-transformers} \ */
/* --subst-var-by k_diffusion ${k_diffusion} \ */
/* --subst-var-by codeformer ${codeformer} \ */
/* --subst-var-by blip ${blip} */
'';
in
{

View File

@ -1,59 +1,14 @@
From 13dae9774101c2e8e7c757baf799552599c5b34e Mon Sep 17 00:00:00 2001
From: William Casarin <jb55@jb55.com>
Date: Sun, 27 Nov 2022 12:58:22 -0800
Subject: [PATCH] nix-stable-diffusion hacks
---
launch.py | 12 ++++++------
modules/paths.py | 8 ++++----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/launch.py b/launch.py
index 8affd41..394436e 100644
--- a/launch.py
+++ b/launch.py
@@ -176,16 +176,16 @@ def prepare_enviroment():
diff --git a/launch.py b/launch.py
index b943fed22c..12a02d27cb 100644
--- a/launch.py
+++ b/launch.py
@@ -153,8 +153,7 @@ def git_clone(url, dir, name, commithash=None):
# TODO clone into temporary dir and move if successful
os.makedirs(dir_repos, exist_ok=True)
if os.path.exists(dir):
- if commithash is None:
- return
+ return
- git_clone(stable_diffusion_repo, repo_dir('stable-diffusion'), "Stable Diffusion", stable_diffusion_commit_hash)
- git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
- git_clone(k_diffusion_repo, repo_dir('k-diffusion'), "K-diffusion", k_diffusion_commit_hash)
- git_clone(codeformer_repo, repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash)
- git_clone(blip_repo, repo_dir('BLIP'), "BLIP", blip_commit_hash)
+ #git_clone(stable_diffusion_repo, repo_dir('stable-diffusion'), "Stable Diffusion", stable_diffusion_commit_hash)
+ #git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
+ #git_clone(k_diffusion_repo, repo_dir('k-diffusion'), "K-diffusion", k_diffusion_commit_hash)
+ #git_clone(codeformer_repo, repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash)
+ #git_clone(blip_repo, repo_dir('BLIP'), "BLIP", blip_commit_hash)
if not is_installed("lpips"):
run_pip(f"install -r {os.path.join(repo_dir('CodeFormer'), 'requirements.txt')}", "requirements for CodeFormer")
- run_pip(f"install -r {requirements_file}", "requirements for Web UI")
+ #run_pip(f"install -r {requirements_file}", "requirements for Web UI")
if update_check:
version_check(commit)
diff --git a/modules/paths.py b/modules/paths.py
index 1e7a2fb..1298c58 100644
--- a/modules/paths.py
+++ b/modules/paths.py
@@ -19,10 +19,10 @@ assert sd_path is not None, "Couldn't find Stable Diffusion in any of: " + str(p
path_dirs = [
(sd_path, 'ldm', 'Stable Diffusion', []),
- (os.path.join(sd_path, '../taming-transformers'), 'taming', 'Taming Transformers', []),
- (os.path.join(sd_path, '../CodeFormer'), 'inference_codeformer.py', 'CodeFormer', []),
- (os.path.join(sd_path, '../BLIP'), 'models/blip.py', 'BLIP', []),
- (os.path.join(sd_path, '../k-diffusion'), 'k_diffusion/sampling.py', 'k_diffusion', ["atstart"]),
+ ('@taming_transformers@', 'taming', 'Taming Transformers', []),
+ ('@codeformer@', 'inference_codeformer.py', 'CodeFormer', []),
+ ('@blip@', 'models/blip.py', 'BLIP', []),
+ ('@k_diffusion@', 'k_diffusion/sampling.py', 'k_diffusion', ["atstart"]),
]
paths = {}
--
2.38.1
current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}").strip()
if current_hash == commithash: