mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2024-11-22 16:23:28 +01:00
Merge branch 'beta' into splash
This commit is contained in:
commit
f05b815c5d
15
CHANGES.md
15
CHANGES.md
@ -22,6 +22,21 @@
|
|||||||
Our focus continues to remain on an easy installation experience, and an easy user-interface. While still remaining pretty powerful, in terms of features and speed.
|
Our focus continues to remain on an easy installation experience, and an easy user-interface. While still remaining pretty powerful, in terms of features and speed.
|
||||||
|
|
||||||
### Detailed changelog
|
### Detailed changelog
|
||||||
|
* 2.5.41 - 24 Jun 2023 - (beta-only) Fix broken inpainting in low VRAM usage mode.
|
||||||
|
* 2.5.41 - 24 Jun 2023 - (beta-only) Fix a recent regression where the LoRA would not get applied when changing SD models.
|
||||||
|
* 2.5.41 - 23 Jun 2023 - Fix a regression where latent upscaler stopped working on PCs without a graphics card.
|
||||||
|
* 2.5.41 - 20 Jun 2023 - Automatically fix black images if fp32 attention precision is required in diffusers.
|
||||||
|
* 2.5.41 - 19 Jun 2023 - Another fix for multi-gpu rendering (in all VRAM usage modes).
|
||||||
|
* 2.5.41 - 13 Jun 2023 - Fix multi-gpu bug with "low" VRAM usage mode while generating images.
|
||||||
|
* 2.5.41 - 12 Jun 2023 - Fix multi-gpu bug with CodeFormer.
|
||||||
|
* 2.5.41 - 6 Jun 2023 - Allow changing the strength of CodeFormer, and slightly improved styling of the CodeFormer options.
|
||||||
|
* 2.5.41 - 5 Jun 2023 - Allow sharing an Easy Diffusion instance via https://try.cloudflare.com/ . You can find this option at the bottom of the Settings tab. Thanks @JeLuf.
|
||||||
|
* 2.5.41 - 5 Jun 2023 - Show an option to download for tiled images. Shows a button on the generated image. Creates larger images by tiling them with the image generated by Easy Diffusion. Thanks @JeLuf.
|
||||||
|
* 2.5.41 - 5 Jun 2023 - (beta-only) Allow LoRA strengths between -2 and 2. Thanks @ogmaresca.
|
||||||
|
* 2.5.40 - 5 Jun 2023 - Reduce the VRAM usage of Latent Upscaling when using "balanced" VRAM usage mode.
|
||||||
|
* 2.5.40 - 5 Jun 2023 - Fix the "realesrgan" key error when using CodeFormer with more than 1 image in a batch.
|
||||||
|
* 2.5.40 - 3 Jun 2023 - Added CodeFormer as another option for fixing faces and eyes. CodeFormer tends to perform better than GFPGAN for many images. Thanks @patriceac for the implementation, and for contacting the CodeFormer team (who were supportive of it being integrated into Easy Diffusion).
|
||||||
|
* 2.5.39 - 25 May 2023 - (beta-only) Seamless Tiling - make seamlessly tiled images, e.g. rock and grass textures. Thanks @JeLuf.
|
||||||
* 2.5.38 - 24 May 2023 - Better reporting of errors, and show an explanation if the user cannot disable the "Use CPU" setting.
|
* 2.5.38 - 24 May 2023 - Better reporting of errors, and show an explanation if the user cannot disable the "Use CPU" setting.
|
||||||
* 2.5.38 - 23 May 2023 - Add Latent Upscaler as another option for upscaling images. Thanks @JeLuf for the implementation of the Latent Upscaler model.
|
* 2.5.38 - 23 May 2023 - Add Latent Upscaler as another option for upscaling images. Thanks @JeLuf for the implementation of the Latent Upscaler model.
|
||||||
* 2.5.37 - 19 May 2023 - (beta-only) Two more samplers: DDPM and DEIS. Also disables the samplers that aren't working yet in the Diffusers version. Thanks @ogmaresca.
|
* 2.5.37 - 19 May 2023 - (beta-only) Two more samplers: DDPM and DEIS. Also disables the samplers that aren't working yet in the Diffusers version. Thanks @ogmaresca.
|
||||||
|
9
PRIVACY.md
Normal file
9
PRIVACY.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// placeholder until a more formal and legal-sounding privacy policy document is written. but the information below is true.
|
||||||
|
|
||||||
|
This is a summary of whether Easy Diffusion uses your data or tracks you:
|
||||||
|
* The short answer is - Easy Diffusion does *not* use your data, and does *not* track you.
|
||||||
|
* Easy Diffusion does not send your prompts or usage or analytics to anyone. There is no tracking. We don't even know how many people use Easy Diffusion, let alone their prompts.
|
||||||
|
* Easy Diffusion fetches updates to the code whenever it starts up. It does this by contacting GitHub directly, via SSL (secure connection). Only your computer and GitHub and [this repository](https://github.com/cmdr2/stable-diffusion-ui) are involved, and no third party is involved. Some countries intercepts SSL connections, that's not something we can do much about. GitHub does *not* share statistics (even with me) about how many people fetched code updates.
|
||||||
|
* Easy Diffusion fetches the models from huggingface.co and github.com, if they don't exist on your PC. For e.g. if the safety checker (NSFW) model doesn't exist, it'll try to download it.
|
||||||
|
* Easy Diffusion fetches code packages from pypi.org, which is the standard hosting service for all Python projects. That's where packages installed via `pip install` are stored.
|
||||||
|
* Occasionally, antivirus software are known to *incorrectly* flag and delete some model files, which will result in Easy Diffusion re-downloading `pytorch_model.bin`. This *incorrect deletion* affects other Stable Diffusion UIs as well, like Invoke AI - https://itch.io/post/7509488
|
18
README.md
18
README.md
@ -17,9 +17,11 @@ Click the download button for your operating system:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
**Hardware requirements:**
|
**Hardware requirements:**
|
||||||
- **Windows:** NVIDIA graphics card, or run on your CPU
|
- **Windows:** NVIDIA graphics card (minimum 2 GB RAM), or run on your CPU.
|
||||||
- **Linux:** NVIDIA or AMD graphics card, or run on your CPU
|
- **Linux:** NVIDIA or AMD graphics card (minimum 2 GB RAM), or run on your CPU.
|
||||||
- **Mac:** M1 or M2, or run on your CPU
|
- **Mac:** M1 or M2, or run on your CPU.
|
||||||
|
- Minimum 8 GB of system RAM.
|
||||||
|
- Atleast 25 GB of space on the hard disk.
|
||||||
|
|
||||||
The installer will take care of whatever is needed. If you face any problems, you can join the friendly [Discord community](https://discord.com/invite/u9yhsFmEkB) and ask for assistance.
|
The installer will take care of whatever is needed. If you face any problems, you can join the friendly [Discord community](https://discord.com/invite/u9yhsFmEkB) and ask for assistance.
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ Just delete the `EasyDiffusion` folder to uninstall all the downloaded packages.
|
|||||||
|
|
||||||
### Performance and security
|
### Performance and security
|
||||||
- **Fast**: Creates a 512x512 image with euler_a in 5 seconds, on an NVIDIA 3060 12GB.
|
- **Fast**: Creates a 512x512 image with euler_a in 5 seconds, on an NVIDIA 3060 12GB.
|
||||||
- **Low Memory Usage**: Create 512x512 images with less than 3 GB of GPU RAM, and 768x768 images with less than 4 GB of GPU RAM!
|
- **Low Memory Usage**: Create 512x512 images with less than 2 GB of GPU RAM, and 768x768 images with less than 3 GB of GPU RAM!
|
||||||
- **Use CPU setting**: If you don't have a compatible graphics card, but still want to run it on your CPU.
|
- **Use CPU setting**: If you don't have a compatible graphics card, but still want to run it on your CPU.
|
||||||
- **Multi-GPU support**: Automatically spreads your tasks across multiple GPUs (if available), for faster performance!
|
- **Multi-GPU support**: Automatically spreads your tasks across multiple GPUs (if available), for faster performance!
|
||||||
- **Auto scan for malicious models**: Uses picklescan to prevent malicious models.
|
- **Auto scan for malicious models**: Uses picklescan to prevent malicious models.
|
||||||
@ -113,14 +115,6 @@ Useful for judging (and stopping) an image quickly, without waiting for it to fi
|
|||||||
![Screenshot of task queue](https://user-images.githubusercontent.com/844287/217043984-0b35f73b-1318-47cb-9eed-a2a91b430490.png)
|
![Screenshot of task queue](https://user-images.githubusercontent.com/844287/217043984-0b35f73b-1318-47cb-9eed-a2a91b430490.png)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# System Requirements
|
|
||||||
1. Windows 10/11, or Linux. Experimental support for Mac is coming soon.
|
|
||||||
2. An NVIDIA graphics card, preferably with 4GB or more of VRAM. If you don't have a compatible graphics card, it'll automatically run in the slower "CPU Mode".
|
|
||||||
3. Minimum 8 GB of RAM and 25GB of disk space.
|
|
||||||
|
|
||||||
You don't need to install or struggle with Python, Anaconda, Docker etc. The installer will take care of whatever is needed.
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
# How to use?
|
# How to use?
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
echo "Opening Stable Diffusion UI - Developer Console.." & echo.
|
echo "Opening Stable Diffusion UI - Developer Console.." & echo.
|
||||||
|
|
||||||
|
cd /d %~dp0
|
||||||
|
|
||||||
set PATH=C:\Windows\System32;%PATH%
|
set PATH=C:\Windows\System32;%PATH%
|
||||||
|
|
||||||
@rem set legacy and new installer's PATH, if they exist
|
@rem set legacy and new installer's PATH, if they exist
|
||||||
@ -21,6 +23,8 @@ call git --version
|
|||||||
call where conda
|
call where conda
|
||||||
call conda --version
|
call conda --version
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo COMSPEC=%COMSPEC%
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
@rem activate the legacy environment (if present) and set PYTHONPATH
|
@rem activate the legacy environment (if present) and set PYTHONPATH
|
||||||
|
@ -36,8 +36,9 @@ call git --version
|
|||||||
|
|
||||||
call where conda
|
call where conda
|
||||||
call conda --version
|
call conda --version
|
||||||
|
echo .
|
||||||
|
echo COMSPEC=%COMSPEC%
|
||||||
|
|
||||||
@rem Download the rest of the installer and UI
|
@rem Download the rest of the installer and UI
|
||||||
call scripts\on_env_start.bat
|
call scripts\on_env_start.bat
|
||||||
|
|
||||||
@pause
|
@pause
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
# this script runs inside the legacy "stable-diffusion" folder
|
|
||||||
|
|
||||||
from sdkit.models import download_model, get_model_info_from_db
|
|
||||||
from sdkit.utils import hash_file_quick
|
|
||||||
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
from glob import glob
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
models_base_dir = os.path.abspath(os.path.join("..", "models"))
|
|
||||||
|
|
||||||
models_to_check = {
|
|
||||||
"stable-diffusion": [
|
|
||||||
{"file_name": "sd-v1-4.ckpt", "model_id": "1.4"},
|
|
||||||
],
|
|
||||||
"gfpgan": [
|
|
||||||
{"file_name": "GFPGANv1.4.pth", "model_id": "1.4"},
|
|
||||||
],
|
|
||||||
"realesrgan": [
|
|
||||||
{"file_name": "RealESRGAN_x4plus.pth", "model_id": "x4plus"},
|
|
||||||
{"file_name": "RealESRGAN_x4plus_anime_6B.pth", "model_id": "x4plus_anime_6"},
|
|
||||||
],
|
|
||||||
"vae": [
|
|
||||||
{"file_name": "vae-ft-mse-840000-ema-pruned.ckpt", "model_id": "vae-ft-mse-840000-ema-pruned"},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
MODEL_EXTENSIONS = { # copied from easydiffusion/model_manager.py
|
|
||||||
"stable-diffusion": [".ckpt", ".safetensors"],
|
|
||||||
"vae": [".vae.pt", ".ckpt", ".safetensors"],
|
|
||||||
"hypernetwork": [".pt", ".safetensors"],
|
|
||||||
"gfpgan": [".pth"],
|
|
||||||
"realesrgan": [".pth"],
|
|
||||||
"lora": [".ckpt", ".safetensors"],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def download_if_necessary(model_type: str, file_name: str, model_id: str):
|
|
||||||
model_path = os.path.join(models_base_dir, model_type, file_name)
|
|
||||||
expected_hash = get_model_info_from_db(model_type=model_type, model_id=model_id)["quick_hash"]
|
|
||||||
|
|
||||||
other_models_exist = any_model_exists(model_type)
|
|
||||||
known_model_exists = os.path.exists(model_path)
|
|
||||||
known_model_is_corrupt = known_model_exists and hash_file_quick(model_path) != expected_hash
|
|
||||||
|
|
||||||
if known_model_is_corrupt or (not other_models_exist and not known_model_exists):
|
|
||||||
print("> download", model_type, model_id)
|
|
||||||
download_model(model_type, model_id, download_base_dir=models_base_dir)
|
|
||||||
|
|
||||||
|
|
||||||
def init():
|
|
||||||
migrate_legacy_model_location()
|
|
||||||
|
|
||||||
for model_type, models in models_to_check.items():
|
|
||||||
for model in models:
|
|
||||||
try:
|
|
||||||
download_if_necessary(model_type, model["file_name"], model["model_id"])
|
|
||||||
except:
|
|
||||||
traceback.print_exc()
|
|
||||||
fail(model_type)
|
|
||||||
|
|
||||||
print(model_type, "model(s) found.")
|
|
||||||
|
|
||||||
|
|
||||||
### utilities
|
|
||||||
def any_model_exists(model_type: str) -> bool:
|
|
||||||
extensions = MODEL_EXTENSIONS.get(model_type, [])
|
|
||||||
for ext in extensions:
|
|
||||||
if any(glob(f"{models_base_dir}/{model_type}/**/*{ext}", recursive=True)):
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_legacy_model_location():
|
|
||||||
'Move the models inside the legacy "stable-diffusion" folder, to their respective folders'
|
|
||||||
|
|
||||||
for model_type, models in models_to_check.items():
|
|
||||||
for model in models:
|
|
||||||
file_name = model["file_name"]
|
|
||||||
if os.path.exists(file_name):
|
|
||||||
dest_dir = os.path.join(models_base_dir, model_type)
|
|
||||||
os.makedirs(dest_dir, exist_ok=True)
|
|
||||||
shutil.move(file_name, os.path.join(dest_dir, file_name))
|
|
||||||
|
|
||||||
|
|
||||||
def fail(model_name):
|
|
||||||
print(
|
|
||||||
f"""Error downloading the {model_name} model. Sorry about that, please try to:
|
|
||||||
1. Run this installer again.
|
|
||||||
2. If that doesn't fix it, please try to download the file manually. The address to download from, and the destination to save to are printed above this message.
|
|
||||||
3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB
|
|
||||||
4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues
|
|
||||||
Thanks!"""
|
|
||||||
)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
### start
|
|
||||||
|
|
||||||
init()
|
|
@ -18,13 +18,15 @@ os_name = platform.system()
|
|||||||
modules_to_check = {
|
modules_to_check = {
|
||||||
"torch": ("1.11.0", "1.13.1", "2.0.0"),
|
"torch": ("1.11.0", "1.13.1", "2.0.0"),
|
||||||
"torchvision": ("0.12.0", "0.14.1", "0.15.1"),
|
"torchvision": ("0.12.0", "0.14.1", "0.15.1"),
|
||||||
"sdkit": "1.0.97",
|
"sdkit": "1.0.112",
|
||||||
"stable-diffusion-sdkit": "2.1.4",
|
"stable-diffusion-sdkit": "2.1.4",
|
||||||
"rich": "12.6.0",
|
"rich": "12.6.0",
|
||||||
"uvicorn": "0.19.0",
|
"uvicorn": "0.19.0",
|
||||||
"fastapi": "0.85.1",
|
"fastapi": "0.85.1",
|
||||||
|
"pycloudflared": "0.2.0",
|
||||||
# "xformers": "0.0.16",
|
# "xformers": "0.0.16",
|
||||||
}
|
}
|
||||||
|
modules_to_log = ["torch", "torchvision", "sdkit", "stable-diffusion-sdkit"]
|
||||||
|
|
||||||
|
|
||||||
def version(module_name: str) -> str:
|
def version(module_name: str) -> str:
|
||||||
@ -89,6 +91,7 @@ def init():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
fail(module_name)
|
fail(module_name)
|
||||||
|
|
||||||
|
if module_name in modules_to_log:
|
||||||
print(f"{module_name}: {version(module_name)}")
|
print(f"{module_name}: {version(module_name)}")
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ if [ "$0" == "bash" ]; then
|
|||||||
export PYTHONPATH="$(pwd)/stable-diffusion/env/lib/python3.8/site-packages"
|
export PYTHONPATH="$(pwd)/stable-diffusion/env/lib/python3.8/site-packages"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export PYTHONNOUSERSITE=y
|
||||||
|
|
||||||
which python
|
which python
|
||||||
python --version
|
python --version
|
||||||
|
|
||||||
|
@ -67,7 +67,6 @@ if "%update_branch%"=="" (
|
|||||||
@xcopy sd-ui-files\ui ui /s /i /Y /q
|
@xcopy sd-ui-files\ui ui /s /i /Y /q
|
||||||
@copy sd-ui-files\scripts\on_sd_start.bat scripts\ /Y
|
@copy sd-ui-files\scripts\on_sd_start.bat scripts\ /Y
|
||||||
@copy sd-ui-files\scripts\check_modules.py scripts\ /Y
|
@copy sd-ui-files\scripts\check_modules.py scripts\ /Y
|
||||||
@copy sd-ui-files\scripts\check_models.py scripts\ /Y
|
|
||||||
@copy sd-ui-files\scripts\get_config.py scripts\ /Y
|
@copy sd-ui-files\scripts\get_config.py scripts\ /Y
|
||||||
@copy "sd-ui-files\scripts\Start Stable Diffusion UI.cmd" . /Y
|
@copy "sd-ui-files\scripts\Start Stable Diffusion UI.cmd" . /Y
|
||||||
@copy "sd-ui-files\scripts\Developer Console.cmd" . /Y
|
@copy "sd-ui-files\scripts\Developer Console.cmd" . /Y
|
||||||
|
@ -50,7 +50,6 @@ cp -Rf sd-ui-files/ui .
|
|||||||
cp sd-ui-files/scripts/on_sd_start.sh scripts/
|
cp sd-ui-files/scripts/on_sd_start.sh scripts/
|
||||||
cp sd-ui-files/scripts/bootstrap.sh scripts/
|
cp sd-ui-files/scripts/bootstrap.sh scripts/
|
||||||
cp sd-ui-files/scripts/check_modules.py scripts/
|
cp sd-ui-files/scripts/check_modules.py scripts/
|
||||||
cp sd-ui-files/scripts/check_models.py scripts/
|
|
||||||
cp sd-ui-files/scripts/get_config.py scripts/
|
cp sd-ui-files/scripts/get_config.py scripts/
|
||||||
cp sd-ui-files/scripts/start.sh .
|
cp sd-ui-files/scripts/start.sh .
|
||||||
cp sd-ui-files/scripts/developer_console.sh .
|
cp sd-ui-files/scripts/developer_console.sh .
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
@copy sd-ui-files\scripts\on_env_start.bat scripts\ /Y
|
@copy sd-ui-files\scripts\on_env_start.bat scripts\ /Y
|
||||||
@copy sd-ui-files\scripts\check_modules.py scripts\ /Y
|
@copy sd-ui-files\scripts\check_modules.py scripts\ /Y
|
||||||
@copy sd-ui-files\scripts\check_models.py scripts\ /Y
|
|
||||||
@copy sd-ui-files\scripts\get_config.py scripts\ /Y
|
@copy sd-ui-files\scripts\get_config.py scripts\ /Y
|
||||||
|
|
||||||
if exist "%cd%\profile" (
|
if exist "%cd%\profile" (
|
||||||
@ -79,13 +78,6 @@ call WHERE uvicorn > .tmp
|
|||||||
@echo conda_sd_ui_deps_installed >> ..\scripts\install_status.txt
|
@echo conda_sd_ui_deps_installed >> ..\scripts\install_status.txt
|
||||||
)
|
)
|
||||||
|
|
||||||
@rem Download the required models
|
|
||||||
call python ..\scripts\check_models.py
|
|
||||||
if "%ERRORLEVEL%" NEQ "0" (
|
|
||||||
pause
|
|
||||||
exit /b
|
|
||||||
)
|
|
||||||
|
|
||||||
@>nul findstr /m "sd_install_complete" ..\scripts\install_status.txt
|
@>nul findstr /m "sd_install_complete" ..\scripts\install_status.txt
|
||||||
@if "%ERRORLEVEL%" NEQ "0" (
|
@if "%ERRORLEVEL%" NEQ "0" (
|
||||||
@echo sd_weights_downloaded >> ..\scripts\install_status.txt
|
@echo sd_weights_downloaded >> ..\scripts\install_status.txt
|
||||||
|
@ -4,7 +4,6 @@ cp sd-ui-files/scripts/functions.sh scripts/
|
|||||||
cp sd-ui-files/scripts/on_env_start.sh scripts/
|
cp sd-ui-files/scripts/on_env_start.sh scripts/
|
||||||
cp sd-ui-files/scripts/bootstrap.sh scripts/
|
cp sd-ui-files/scripts/bootstrap.sh scripts/
|
||||||
cp sd-ui-files/scripts/check_modules.py scripts/
|
cp sd-ui-files/scripts/check_modules.py scripts/
|
||||||
cp sd-ui-files/scripts/check_models.py scripts/
|
|
||||||
cp sd-ui-files/scripts/get_config.py scripts/
|
cp sd-ui-files/scripts/get_config.py scripts/
|
||||||
|
|
||||||
source ./scripts/functions.sh
|
source ./scripts/functions.sh
|
||||||
@ -51,12 +50,6 @@ if ! command -v uvicorn &> /dev/null; then
|
|||||||
fail "UI packages not found!"
|
fail "UI packages not found!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Download the required models
|
|
||||||
if ! python ../scripts/check_models.py; then
|
|
||||||
read -p "Press any key to continue"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ `grep -c sd_install_complete ../scripts/install_status.txt` -gt "0" ]; then
|
if [ `grep -c sd_install_complete ../scripts/install_status.txt` -gt "0" ]; then
|
||||||
echo sd_weights_downloaded >> ../scripts/install_status.txt
|
echo sd_weights_downloaded >> ../scripts/install_status.txt
|
||||||
echo sd_install_complete >> ../scripts/install_status.txt
|
echo sd_install_complete >> ../scripts/install_status.txt
|
||||||
|
@ -90,7 +90,7 @@ def init():
|
|||||||
os.makedirs(USER_SERVER_PLUGINS_DIR, exist_ok=True)
|
os.makedirs(USER_SERVER_PLUGINS_DIR, exist_ok=True)
|
||||||
|
|
||||||
# https://pytorch.org/docs/stable/storage.html
|
# https://pytorch.org/docs/stable/storage.html
|
||||||
warnings.filterwarnings('ignore', category=UserWarning, message='TypedStorage is deprecated')
|
warnings.filterwarnings("ignore", category=UserWarning, message="TypedStorage is deprecated")
|
||||||
|
|
||||||
load_server_plugins()
|
load_server_plugins()
|
||||||
|
|
||||||
@ -221,12 +221,41 @@ def open_browser():
|
|||||||
|
|
||||||
webbrowser.open(f"http://localhost:{port}")
|
webbrowser.open(f"http://localhost:{port}")
|
||||||
|
|
||||||
Console().print(Panel(
|
Console().print(
|
||||||
"\n" +
|
Panel(
|
||||||
"[white]Easy Diffusion is ready to serve requests.\n\n" +
|
"\n"
|
||||||
"A new browser tab should have been opened by now.\n" +
|
+ "[white]Easy Diffusion is ready to serve requests.\n\n"
|
||||||
f"If not, please open your web browser and navigate to [bold yellow underline]http://localhost:{port}/\n",
|
+ "A new browser tab should have been opened by now.\n"
|
||||||
title="Easy Diffusion is ready", style="bold yellow on blue"))
|
+ f"If not, please open your web browser and navigate to [bold yellow underline]http://localhost:{port}/\n",
|
||||||
|
title="Easy Diffusion is ready",
|
||||||
|
style="bold yellow on blue",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def fail_and_die(fail_type: str, data: str):
|
||||||
|
suggestions = [
|
||||||
|
"Run this installer again.",
|
||||||
|
"If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB",
|
||||||
|
"If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues",
|
||||||
|
]
|
||||||
|
|
||||||
|
if fail_type == "model_download":
|
||||||
|
fail_label = f"Error downloading the {data} model"
|
||||||
|
suggestions.insert(
|
||||||
|
1,
|
||||||
|
"If that doesn't fix it, please try to download the file manually. The address to download from, and the destination to save to are printed above this message.",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
fail_label = "Error while installing Easy Diffusion"
|
||||||
|
|
||||||
|
msg = [f"{fail_label}. Sorry about that, please try to:"]
|
||||||
|
for i, suggestion in enumerate(suggestions):
|
||||||
|
msg.append(f"{i+1}. {suggestion}")
|
||||||
|
msg.append("Thanks!")
|
||||||
|
|
||||||
|
print("\n".join(msg))
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_image_modifiers():
|
def get_image_modifiers():
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
from glob import glob
|
||||||
|
import traceback
|
||||||
|
|
||||||
from easydiffusion import app
|
from easydiffusion import app
|
||||||
from easydiffusion.types import TaskData
|
from easydiffusion.types import TaskData
|
||||||
from easydiffusion.utils import log
|
from easydiffusion.utils import log
|
||||||
from sdkit import Context
|
from sdkit import Context
|
||||||
from sdkit.models import load_model, scan_model, unload_model
|
from sdkit.models import load_model, scan_model, unload_model, download_model, get_model_info_from_db
|
||||||
|
from sdkit.utils import hash_file_quick
|
||||||
|
|
||||||
KNOWN_MODEL_TYPES = [
|
KNOWN_MODEL_TYPES = [
|
||||||
"stable-diffusion",
|
"stable-diffusion",
|
||||||
@ -13,6 +17,7 @@ KNOWN_MODEL_TYPES = [
|
|||||||
"gfpgan",
|
"gfpgan",
|
||||||
"realesrgan",
|
"realesrgan",
|
||||||
"lora",
|
"lora",
|
||||||
|
"codeformer",
|
||||||
]
|
]
|
||||||
MODEL_EXTENSIONS = {
|
MODEL_EXTENSIONS = {
|
||||||
"stable-diffusion": [".ckpt", ".safetensors"],
|
"stable-diffusion": [".ckpt", ".safetensors"],
|
||||||
@ -21,14 +26,22 @@ MODEL_EXTENSIONS = {
|
|||||||
"gfpgan": [".pth"],
|
"gfpgan": [".pth"],
|
||||||
"realesrgan": [".pth"],
|
"realesrgan": [".pth"],
|
||||||
"lora": [".ckpt", ".safetensors"],
|
"lora": [".ckpt", ".safetensors"],
|
||||||
|
"codeformer": [".pth"],
|
||||||
}
|
}
|
||||||
DEFAULT_MODELS = {
|
DEFAULT_MODELS = {
|
||||||
"stable-diffusion": [ # needed to support the legacy installations
|
"stable-diffusion": [
|
||||||
"custom-model", # only one custom model file was supported initially, creatively named 'custom-model'
|
{"file_name": "sd-v1-4.ckpt", "model_id": "1.4"},
|
||||||
"sd-v1-4", # Default fallback.
|
],
|
||||||
|
"gfpgan": [
|
||||||
|
{"file_name": "GFPGANv1.4.pth", "model_id": "1.4"},
|
||||||
|
],
|
||||||
|
"realesrgan": [
|
||||||
|
{"file_name": "RealESRGAN_x4plus.pth", "model_id": "x4plus"},
|
||||||
|
{"file_name": "RealESRGAN_x4plus_anime_6B.pth", "model_id": "x4plus_anime_6"},
|
||||||
|
],
|
||||||
|
"vae": [
|
||||||
|
{"file_name": "vae-ft-mse-840000-ema-pruned.ckpt", "model_id": "vae-ft-mse-840000-ema-pruned"},
|
||||||
],
|
],
|
||||||
"gfpgan": ["GFPGANv1.3"],
|
|
||||||
"realesrgan": ["RealESRGAN_x4plus"],
|
|
||||||
}
|
}
|
||||||
MODELS_TO_LOAD_ON_START = ["stable-diffusion", "vae", "hypernetwork", "lora"]
|
MODELS_TO_LOAD_ON_START = ["stable-diffusion", "vae", "hypernetwork", "lora"]
|
||||||
|
|
||||||
@ -37,6 +50,8 @@ known_models = {}
|
|||||||
|
|
||||||
def init():
|
def init():
|
||||||
make_model_folders()
|
make_model_folders()
|
||||||
|
migrate_legacy_model_location() # if necessary
|
||||||
|
download_default_models_if_necessary()
|
||||||
getModels() # run this once, to cache the picklescan results
|
getModels() # run this once, to cache the picklescan results
|
||||||
|
|
||||||
|
|
||||||
@ -45,7 +60,7 @@ def load_default_models(context: Context):
|
|||||||
|
|
||||||
# init default model paths
|
# init default model paths
|
||||||
for model_type in MODELS_TO_LOAD_ON_START:
|
for model_type in MODELS_TO_LOAD_ON_START:
|
||||||
context.model_paths[model_type] = resolve_model_to_use(model_type=model_type)
|
context.model_paths[model_type] = resolve_model_to_use(model_type=model_type, fail_if_not_found=False)
|
||||||
try:
|
try:
|
||||||
load_model(
|
load_model(
|
||||||
context,
|
context,
|
||||||
@ -57,6 +72,11 @@ def load_default_models(context: Context):
|
|||||||
del context.model_load_errors[model_type]
|
del context.model_load_errors[model_type]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"[red]Error while loading {model_type} model: {context.model_paths[model_type]}[/red]")
|
log.error(f"[red]Error while loading {model_type} model: {context.model_paths[model_type]}[/red]")
|
||||||
|
if "DefaultCPUAllocator: not enough memory" in str(e):
|
||||||
|
log.error(
|
||||||
|
f"[red]Your PC is low on system RAM. Please add some virtual memory (or swap space) by following the instructions at this link: https://www.ibm.com/docs/en/opw/8.2.0?topic=tuning-optional-increasing-paging-file-size-windows-computers[/red]"
|
||||||
|
)
|
||||||
|
else:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
del context.model_paths[model_type]
|
del context.model_paths[model_type]
|
||||||
|
|
||||||
@ -70,12 +90,12 @@ def unload_all(context: Context):
|
|||||||
del context.model_load_errors[model_type]
|
del context.model_load_errors[model_type]
|
||||||
|
|
||||||
|
|
||||||
def resolve_model_to_use(model_name: str = None, model_type: str = None):
|
def resolve_model_to_use(model_name: str = None, model_type: str = None, fail_if_not_found: bool = True):
|
||||||
model_extensions = MODEL_EXTENSIONS.get(model_type, [])
|
model_extensions = MODEL_EXTENSIONS.get(model_type, [])
|
||||||
default_models = DEFAULT_MODELS.get(model_type, [])
|
default_models = DEFAULT_MODELS.get(model_type, [])
|
||||||
config = app.getConfig()
|
config = app.getConfig()
|
||||||
|
|
||||||
model_dirs = [os.path.join(app.MODELS_DIR, model_type), app.SD_DIR]
|
model_dir = os.path.join(app.MODELS_DIR, model_type)
|
||||||
if not model_name: # When None try user configured model.
|
if not model_name: # When None try user configured model.
|
||||||
# config = getConfig()
|
# config = getConfig()
|
||||||
if "model" in config and model_type in config["model"]:
|
if "model" in config and model_type in config["model"]:
|
||||||
@ -83,45 +103,42 @@ def resolve_model_to_use(model_name: str = None, model_type: str = None):
|
|||||||
|
|
||||||
if model_name:
|
if model_name:
|
||||||
# Check models directory
|
# Check models directory
|
||||||
models_dir_path = os.path.join(app.MODELS_DIR, model_type, model_name)
|
model_path = os.path.join(model_dir, model_name)
|
||||||
|
if os.path.exists(model_path):
|
||||||
|
return model_path
|
||||||
for model_extension in model_extensions:
|
for model_extension in model_extensions:
|
||||||
if os.path.exists(models_dir_path + model_extension):
|
if os.path.exists(model_path + model_extension):
|
||||||
return models_dir_path + model_extension
|
return model_path + model_extension
|
||||||
if os.path.exists(model_name + model_extension):
|
if os.path.exists(model_name + model_extension):
|
||||||
return os.path.abspath(model_name + model_extension)
|
return os.path.abspath(model_name + model_extension)
|
||||||
|
|
||||||
# Default locations
|
|
||||||
if model_name in default_models:
|
|
||||||
default_model_path = os.path.join(app.SD_DIR, model_name)
|
|
||||||
for model_extension in model_extensions:
|
|
||||||
if os.path.exists(default_model_path + model_extension):
|
|
||||||
return default_model_path + model_extension
|
|
||||||
|
|
||||||
# Can't find requested model, check the default paths.
|
# Can't find requested model, check the default paths.
|
||||||
|
if model_type == "stable-diffusion" and not fail_if_not_found:
|
||||||
for default_model in default_models:
|
for default_model in default_models:
|
||||||
for model_dir in model_dirs:
|
default_model_path = os.path.join(model_dir, default_model["file_name"])
|
||||||
default_model_path = os.path.join(model_dir, default_model)
|
if os.path.exists(default_model_path):
|
||||||
for model_extension in model_extensions:
|
|
||||||
if os.path.exists(default_model_path + model_extension):
|
|
||||||
if model_name is not None:
|
if model_name is not None:
|
||||||
log.warn(
|
log.warn(
|
||||||
f"Could not find the configured custom model {model_name}{model_extension}. Using the default one: {default_model_path}{model_extension}"
|
f"Could not find the configured custom model {model_name}. Using the default one: {default_model_path}"
|
||||||
)
|
)
|
||||||
return default_model_path + model_extension
|
return default_model_path
|
||||||
|
|
||||||
return None
|
if model_name and fail_if_not_found:
|
||||||
|
raise Exception(f"Could not find the desired model {model_name}! Is it present in the {model_dir} folder?")
|
||||||
|
|
||||||
|
|
||||||
def reload_models_if_necessary(context: Context, task_data: TaskData):
|
def reload_models_if_necessary(context: Context, task_data: TaskData):
|
||||||
use_upscale_lower = task_data.use_upscale.lower() if task_data.use_upscale else ""
|
face_fix_lower = task_data.use_face_correction.lower() if task_data.use_face_correction else ""
|
||||||
|
upscale_lower = task_data.use_upscale.lower() if task_data.use_upscale else ""
|
||||||
|
|
||||||
model_paths_in_req = {
|
model_paths_in_req = {
|
||||||
"stable-diffusion": task_data.use_stable_diffusion_model,
|
"stable-diffusion": task_data.use_stable_diffusion_model,
|
||||||
"vae": task_data.use_vae_model,
|
"vae": task_data.use_vae_model,
|
||||||
"hypernetwork": task_data.use_hypernetwork_model,
|
"hypernetwork": task_data.use_hypernetwork_model,
|
||||||
"gfpgan": task_data.use_face_correction,
|
"codeformer": task_data.use_face_correction if "codeformer" in face_fix_lower else None,
|
||||||
"realesrgan": task_data.use_upscale if "realesrgan" in use_upscale_lower else None,
|
"gfpgan": task_data.use_face_correction if "gfpgan" in face_fix_lower else None,
|
||||||
"latent_upscaler": True if task_data.use_upscale == "latent_upscaler" else None,
|
"realesrgan": task_data.use_upscale if "realesrgan" in upscale_lower else None,
|
||||||
|
"latent_upscaler": True if "latent_upscaler" in upscale_lower else None,
|
||||||
"nsfw_checker": True if task_data.block_nsfw else None,
|
"nsfw_checker": True if task_data.block_nsfw else None,
|
||||||
"lora": task_data.use_lora_model,
|
"lora": task_data.use_lora_model,
|
||||||
}
|
}
|
||||||
@ -131,6 +148,13 @@ def reload_models_if_necessary(context: Context, task_data: TaskData):
|
|||||||
if context.model_paths.get(model_type) != path
|
if context.model_paths.get(model_type) != path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if task_data.codeformer_upscale_faces:
|
||||||
|
if "realesrgan" not in models_to_reload and "realesrgan" not in context.models:
|
||||||
|
default_realesrgan = DEFAULT_MODELS["realesrgan"][0]["file_name"]
|
||||||
|
models_to_reload["realesrgan"] = resolve_model_to_use(default_realesrgan, "realesrgan")
|
||||||
|
elif "realesrgan" in models_to_reload and models_to_reload["realesrgan"] is None:
|
||||||
|
del models_to_reload["realesrgan"] # don't unload realesrgan
|
||||||
|
|
||||||
if set_vram_optimizations(context) or set_clip_skip(context, task_data): # reload SD
|
if set_vram_optimizations(context) or set_clip_skip(context, task_data): # reload SD
|
||||||
models_to_reload["stable-diffusion"] = model_paths_in_req["stable-diffusion"]
|
models_to_reload["stable-diffusion"] = model_paths_in_req["stable-diffusion"]
|
||||||
|
|
||||||
@ -157,7 +181,13 @@ def resolve_model_paths(task_data: TaskData):
|
|||||||
task_data.use_lora_model = resolve_model_to_use(task_data.use_lora_model, model_type="lora")
|
task_data.use_lora_model = resolve_model_to_use(task_data.use_lora_model, model_type="lora")
|
||||||
|
|
||||||
if task_data.use_face_correction:
|
if task_data.use_face_correction:
|
||||||
task_data.use_face_correction = resolve_model_to_use(task_data.use_face_correction, "gfpgan")
|
if "gfpgan" in task_data.use_face_correction.lower():
|
||||||
|
model_type = "gfpgan"
|
||||||
|
elif "codeformer" in task_data.use_face_correction.lower():
|
||||||
|
model_type = "codeformer"
|
||||||
|
download_if_necessary("codeformer", "codeformer.pth", "codeformer-0.1.0")
|
||||||
|
|
||||||
|
task_data.use_face_correction = resolve_model_to_use(task_data.use_face_correction, model_type)
|
||||||
if task_data.use_upscale and "realesrgan" in task_data.use_upscale.lower():
|
if task_data.use_upscale and "realesrgan" in task_data.use_upscale.lower():
|
||||||
task_data.use_upscale = resolve_model_to_use(task_data.use_upscale, "realesrgan")
|
task_data.use_upscale = resolve_model_to_use(task_data.use_upscale, "realesrgan")
|
||||||
|
|
||||||
@ -167,7 +197,31 @@ def fail_if_models_did_not_load(context: Context):
|
|||||||
if model_type in context.model_load_errors:
|
if model_type in context.model_load_errors:
|
||||||
e = context.model_load_errors[model_type]
|
e = context.model_load_errors[model_type]
|
||||||
raise Exception(f"Could not load the {model_type} model! Reason: " + e)
|
raise Exception(f"Could not load the {model_type} model! Reason: " + e)
|
||||||
# concat 'e', don't use in format string (injection attack)
|
|
||||||
|
|
||||||
|
def download_default_models_if_necessary():
|
||||||
|
for model_type, models in DEFAULT_MODELS.items():
|
||||||
|
for model in models:
|
||||||
|
try:
|
||||||
|
download_if_necessary(model_type, model["file_name"], model["model_id"])
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
app.fail_and_die(fail_type="model_download", data=model_type)
|
||||||
|
|
||||||
|
print(model_type, "model(s) found.")
|
||||||
|
|
||||||
|
|
||||||
|
def download_if_necessary(model_type: str, file_name: str, model_id: str):
|
||||||
|
model_path = os.path.join(app.MODELS_DIR, model_type, file_name)
|
||||||
|
expected_hash = get_model_info_from_db(model_type=model_type, model_id=model_id)["quick_hash"]
|
||||||
|
|
||||||
|
other_models_exist = any_model_exists(model_type)
|
||||||
|
known_model_exists = os.path.exists(model_path)
|
||||||
|
known_model_is_corrupt = known_model_exists and hash_file_quick(model_path) != expected_hash
|
||||||
|
|
||||||
|
if known_model_is_corrupt or (not other_models_exist and not known_model_exists):
|
||||||
|
print("> download", model_type, model_id)
|
||||||
|
download_model(model_type, model_id, download_base_dir=app.MODELS_DIR)
|
||||||
|
|
||||||
|
|
||||||
def set_vram_optimizations(context: Context):
|
def set_vram_optimizations(context: Context):
|
||||||
@ -181,6 +235,26 @@ def set_vram_optimizations(context: Context):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_legacy_model_location():
|
||||||
|
'Move the models inside the legacy "stable-diffusion" folder, to their respective folders'
|
||||||
|
|
||||||
|
for model_type, models in DEFAULT_MODELS.items():
|
||||||
|
for model in models:
|
||||||
|
file_name = model["file_name"]
|
||||||
|
legacy_path = os.path.join(app.SD_DIR, file_name)
|
||||||
|
if os.path.exists(legacy_path):
|
||||||
|
shutil.move(legacy_path, os.path.join(app.MODELS_DIR, model_type, file_name))
|
||||||
|
|
||||||
|
|
||||||
|
def any_model_exists(model_type: str) -> bool:
|
||||||
|
extensions = MODEL_EXTENSIONS.get(model_type, [])
|
||||||
|
for ext in extensions:
|
||||||
|
if any(glob(f"{app.MODELS_DIR}/{model_type}/**/*{ext}", recursive=True)):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def set_clip_skip(context: Context, task_data: TaskData):
|
def set_clip_skip(context: Context, task_data: TaskData):
|
||||||
clip_skip = task_data.clip_skip
|
clip_skip = task_data.clip_skip
|
||||||
|
|
||||||
@ -238,17 +312,12 @@ def is_malicious_model(file_path):
|
|||||||
|
|
||||||
def getModels():
|
def getModels():
|
||||||
models = {
|
models = {
|
||||||
"active": {
|
|
||||||
"stable-diffusion": "sd-v1-4",
|
|
||||||
"vae": "",
|
|
||||||
"hypernetwork": "",
|
|
||||||
"lora": "",
|
|
||||||
},
|
|
||||||
"options": {
|
"options": {
|
||||||
"stable-diffusion": ["sd-v1-4"],
|
"stable-diffusion": ["sd-v1-4"],
|
||||||
"vae": [],
|
"vae": [],
|
||||||
"hypernetwork": [],
|
"hypernetwork": [],
|
||||||
"lora": [],
|
"lora": [],
|
||||||
|
"codeformer": ["codeformer"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,9 +378,4 @@ def getModels():
|
|||||||
if models_scanned > 0:
|
if models_scanned > 0:
|
||||||
log.info(f"[green]Scanned {models_scanned} models. Nothing infected[/]")
|
log.info(f"[green]Scanned {models_scanned} models. Nothing infected[/]")
|
||||||
|
|
||||||
# legacy
|
|
||||||
custom_weight_path = os.path.join(app.SD_DIR, "custom-model.ckpt")
|
|
||||||
if os.path.exists(custom_weight_path):
|
|
||||||
models["options"]["stable-diffusion"].append("custom-model")
|
|
||||||
|
|
||||||
return models
|
return models
|
||||||
|
@ -7,10 +7,12 @@ from easydiffusion import device_manager
|
|||||||
from easydiffusion.types import GenerateImageRequest
|
from easydiffusion.types import GenerateImageRequest
|
||||||
from easydiffusion.types import Image as ResponseImage
|
from easydiffusion.types import Image as ResponseImage
|
||||||
from easydiffusion.types import Response, TaskData, UserInitiatedStop
|
from easydiffusion.types import Response, TaskData, UserInitiatedStop
|
||||||
|
from easydiffusion.model_manager import DEFAULT_MODELS, resolve_model_to_use
|
||||||
from easydiffusion.utils import get_printable_request, log, save_images_to_disk
|
from easydiffusion.utils import get_printable_request, log, save_images_to_disk
|
||||||
from sdkit import Context
|
from sdkit import Context
|
||||||
from sdkit.filter import apply_filters
|
from sdkit.filter import apply_filters
|
||||||
from sdkit.generate import generate_images
|
from sdkit.generate import generate_images
|
||||||
|
from sdkit.models import load_model
|
||||||
from sdkit.utils import (
|
from sdkit.utils import (
|
||||||
diffusers_latent_samples_to_images,
|
diffusers_latent_samples_to_images,
|
||||||
gc,
|
gc,
|
||||||
@ -34,6 +36,7 @@ def init(device):
|
|||||||
context.temp_images = {}
|
context.temp_images = {}
|
||||||
context.partial_x_samples = None
|
context.partial_x_samples = None
|
||||||
context.model_load_errors = {}
|
context.model_load_errors = {}
|
||||||
|
context.enable_codeformer = True
|
||||||
|
|
||||||
from easydiffusion import app
|
from easydiffusion import app
|
||||||
|
|
||||||
@ -156,33 +159,52 @@ def filter_images(req: GenerateImageRequest, task_data: TaskData, images: list,
|
|||||||
if user_stopped:
|
if user_stopped:
|
||||||
return images
|
return images
|
||||||
|
|
||||||
filters_to_apply = []
|
|
||||||
filter_params = {}
|
|
||||||
if task_data.block_nsfw:
|
if task_data.block_nsfw:
|
||||||
filters_to_apply.append("nsfw_checker")
|
images = apply_filters(context, "nsfw_checker", images)
|
||||||
if task_data.use_face_correction and "gfpgan" in task_data.use_face_correction.lower():
|
|
||||||
filters_to_apply.append("gfpgan")
|
if task_data.use_face_correction and "codeformer" in task_data.use_face_correction.lower():
|
||||||
|
default_realesrgan = DEFAULT_MODELS["realesrgan"][0]["file_name"]
|
||||||
|
prev_realesrgan_path = None
|
||||||
|
if task_data.codeformer_upscale_faces and default_realesrgan not in context.model_paths["realesrgan"]:
|
||||||
|
prev_realesrgan_path = context.model_paths["realesrgan"]
|
||||||
|
context.model_paths["realesrgan"] = resolve_model_to_use(default_realesrgan, "realesrgan")
|
||||||
|
load_model(context, "realesrgan")
|
||||||
|
|
||||||
|
try:
|
||||||
|
images = apply_filters(
|
||||||
|
context,
|
||||||
|
"codeformer",
|
||||||
|
images,
|
||||||
|
upscale_faces=task_data.codeformer_upscale_faces,
|
||||||
|
codeformer_fidelity=task_data.codeformer_fidelity,
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
if prev_realesrgan_path:
|
||||||
|
context.model_paths["realesrgan"] = prev_realesrgan_path
|
||||||
|
load_model(context, "realesrgan")
|
||||||
|
elif task_data.use_face_correction and "gfpgan" in task_data.use_face_correction.lower():
|
||||||
|
images = apply_filters(context, "gfpgan", images)
|
||||||
|
|
||||||
if task_data.use_upscale:
|
if task_data.use_upscale:
|
||||||
if "realesrgan" in task_data.use_upscale.lower():
|
if "realesrgan" in task_data.use_upscale.lower():
|
||||||
filters_to_apply.append("realesrgan")
|
images = apply_filters(context, "realesrgan", images, scale=task_data.upscale_amount)
|
||||||
elif task_data.use_upscale == "latent_upscaler":
|
elif task_data.use_upscale == "latent_upscaler":
|
||||||
filters_to_apply.append("latent_upscaler")
|
images = apply_filters(
|
||||||
|
context,
|
||||||
filter_params["latent_upscaler_options"] = {
|
"latent_upscaler",
|
||||||
|
images,
|
||||||
|
scale=task_data.upscale_amount,
|
||||||
|
latent_upscaler_options={
|
||||||
"prompt": req.prompt,
|
"prompt": req.prompt,
|
||||||
"negative_prompt": req.negative_prompt,
|
"negative_prompt": req.negative_prompt,
|
||||||
"seed": req.seed,
|
"seed": req.seed,
|
||||||
"num_inference_steps": task_data.latent_upscaler_steps,
|
"num_inference_steps": task_data.latent_upscaler_steps,
|
||||||
"guidance_scale": 0,
|
"guidance_scale": 0,
|
||||||
}
|
},
|
||||||
|
)
|
||||||
|
|
||||||
filter_params["scale"] = task_data.upscale_amount
|
|
||||||
|
|
||||||
if len(filters_to_apply) == 0:
|
|
||||||
return images
|
return images
|
||||||
|
|
||||||
return apply_filters(context, filters_to_apply, images, **filter_params)
|
|
||||||
|
|
||||||
|
|
||||||
def construct_response(images: list, seeds: list, task_data: TaskData, base_seed: int):
|
def construct_response(images: list, seeds: list, task_data: TaskData, base_seed: int):
|
||||||
return [
|
return [
|
||||||
|
@ -15,6 +15,7 @@ from fastapi import FastAPI, HTTPException
|
|||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from pydantic import BaseModel, Extra
|
from pydantic import BaseModel, Extra
|
||||||
from starlette.responses import FileResponse, JSONResponse, StreamingResponse
|
from starlette.responses import FileResponse, JSONResponse, StreamingResponse
|
||||||
|
from pycloudflared import try_cloudflare
|
||||||
|
|
||||||
log.info(f"started in {app.SD_DIR}")
|
log.info(f"started in {app.SD_DIR}")
|
||||||
log.info(f"started at {datetime.datetime.now():%x %X}")
|
log.info(f"started at {datetime.datetime.now():%x %X}")
|
||||||
@ -113,6 +114,14 @@ def init():
|
|||||||
def get_image(task_id: int, img_id: int):
|
def get_image(task_id: int, img_id: int):
|
||||||
return get_image_internal(task_id, img_id)
|
return get_image_internal(task_id, img_id)
|
||||||
|
|
||||||
|
@server_api.post("/tunnel/cloudflare/start")
|
||||||
|
def start_cloudflare_tunnel(req: dict):
|
||||||
|
return start_cloudflare_tunnel_internal(req)
|
||||||
|
|
||||||
|
@server_api.post("/tunnel/cloudflare/stop")
|
||||||
|
def stop_cloudflare_tunnel(req: dict):
|
||||||
|
return stop_cloudflare_tunnel_internal(req)
|
||||||
|
|
||||||
@server_api.get("/")
|
@server_api.get("/")
|
||||||
def read_root():
|
def read_root():
|
||||||
return FileResponse(os.path.join(app.SD_UI_DIR, "index.html"), headers=NOCACHE_HEADERS)
|
return FileResponse(os.path.join(app.SD_UI_DIR, "index.html"), headers=NOCACHE_HEADERS)
|
||||||
@ -211,6 +220,8 @@ def ping_internal(session_id: str = None):
|
|||||||
session = task_manager.get_cached_session(session_id, update_ttl=True)
|
session = task_manager.get_cached_session(session_id, update_ttl=True)
|
||||||
response["tasks"] = {id(t): t.status for t in session.tasks}
|
response["tasks"] = {id(t): t.status for t in session.tasks}
|
||||||
response["devices"] = task_manager.get_devices()
|
response["devices"] = task_manager.get_devices()
|
||||||
|
if cloudflare.address != None:
|
||||||
|
response["cloudflare"] = cloudflare.address
|
||||||
return JSONResponse(response, headers=NOCACHE_HEADERS)
|
return JSONResponse(response, headers=NOCACHE_HEADERS)
|
||||||
|
|
||||||
|
|
||||||
@ -322,3 +333,47 @@ def get_image_internal(task_id: int, img_id: int):
|
|||||||
return StreamingResponse(img_data, media_type="image/jpeg")
|
return StreamingResponse(img_data, media_type="image/jpeg")
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
#---- Cloudflare Tunnel ----
|
||||||
|
class CloudflareTunnel:
|
||||||
|
def __init__(self):
|
||||||
|
config = app.getConfig()
|
||||||
|
self.urls = None
|
||||||
|
self.port = config.get("net", {}).get("listen_port")
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
if self.port:
|
||||||
|
self.urls = try_cloudflare(self.port)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
if self.urls:
|
||||||
|
try_cloudflare.terminate(self.port)
|
||||||
|
self.urls = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def address(self):
|
||||||
|
if self.urls:
|
||||||
|
return self.urls.tunnel
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
cloudflare = CloudflareTunnel()
|
||||||
|
|
||||||
|
def start_cloudflare_tunnel_internal(req: dict):
|
||||||
|
try:
|
||||||
|
cloudflare.start()
|
||||||
|
log.info(f"- Started cloudflare tunnel. Using address: {cloudflare.address}")
|
||||||
|
return JSONResponse({"address":cloudflare.address})
|
||||||
|
except Exception as e:
|
||||||
|
log.error(str(e))
|
||||||
|
log.error(traceback.format_exc())
|
||||||
|
return HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
def stop_cloudflare_tunnel_internal(req: dict):
|
||||||
|
try:
|
||||||
|
cloudflare.stop()
|
||||||
|
except Exception as e:
|
||||||
|
log.error(str(e))
|
||||||
|
log.error(traceback.format_exc())
|
||||||
|
return HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ class GenerateImageRequest(BaseModel):
|
|||||||
sampler_name: str = None # "ddim", "plms", "heun", "euler", "euler_a", "dpm2", "dpm2_a", "lms"
|
sampler_name: str = None # "ddim", "plms", "heun", "euler", "euler_a", "dpm2", "dpm2_a", "lms"
|
||||||
hypernetwork_strength: float = 0
|
hypernetwork_strength: float = 0
|
||||||
lora_alpha: float = 0
|
lora_alpha: float = 0
|
||||||
|
tiling: str = "none" # "none", "x", "y", "xy"
|
||||||
|
|
||||||
|
|
||||||
class TaskData(BaseModel):
|
class TaskData(BaseModel):
|
||||||
@ -50,6 +51,8 @@ class TaskData(BaseModel):
|
|||||||
stream_image_progress: bool = False
|
stream_image_progress: bool = False
|
||||||
stream_image_progress_interval: int = 5
|
stream_image_progress_interval: int = 5
|
||||||
clip_skip: bool = False
|
clip_skip: bool = False
|
||||||
|
codeformer_upscale_faces: bool = False
|
||||||
|
codeformer_fidelity: float = 0.5
|
||||||
|
|
||||||
|
|
||||||
class MergeRequest(BaseModel):
|
class MergeRequest(BaseModel):
|
||||||
|
@ -30,9 +30,11 @@ TASK_TEXT_MAPPING = {
|
|||||||
"lora_alpha": "LoRA Strength",
|
"lora_alpha": "LoRA Strength",
|
||||||
"use_hypernetwork_model": "Hypernetwork model",
|
"use_hypernetwork_model": "Hypernetwork model",
|
||||||
"hypernetwork_strength": "Hypernetwork Strength",
|
"hypernetwork_strength": "Hypernetwork Strength",
|
||||||
|
"tiling": "Seamless Tiling",
|
||||||
"use_face_correction": "Use Face Correction",
|
"use_face_correction": "Use Face Correction",
|
||||||
"use_upscale": "Use Upscaling",
|
"use_upscale": "Use Upscaling",
|
||||||
"upscale_amount": "Upscale By",
|
"upscale_amount": "Upscale By",
|
||||||
|
"latent_upscaler_steps": "Latent Upscaler Steps"
|
||||||
}
|
}
|
||||||
|
|
||||||
time_placeholders = {
|
time_placeholders = {
|
||||||
@ -169,7 +171,9 @@ def save_images_to_disk(images: list, filtered_images: list, req: GenerateImageR
|
|||||||
output_quality=task_data.output_quality,
|
output_quality=task_data.output_quality,
|
||||||
output_lossless=task_data.output_lossless,
|
output_lossless=task_data.output_lossless,
|
||||||
)
|
)
|
||||||
if task_data.metadata_output_format.lower() in ["json", "txt", "embed"]:
|
if task_data.metadata_output_format:
|
||||||
|
for metadata_output_format in task_data.metadata_output_format.split(","):
|
||||||
|
if metadata_output_format.lower() in ["json", "txt", "embed"]:
|
||||||
save_dicts(
|
save_dicts(
|
||||||
metadata_entries,
|
metadata_entries,
|
||||||
save_dir_path,
|
save_dir_path,
|
||||||
@ -183,7 +187,7 @@ def get_metadata_entries_for_request(req: GenerateImageRequest, task_data: TaskD
|
|||||||
metadata = get_printable_request(req, task_data)
|
metadata = get_printable_request(req, task_data)
|
||||||
|
|
||||||
# if text, format it in the text format expected by the UI
|
# if text, format it in the text format expected by the UI
|
||||||
is_txt_format = task_data.metadata_output_format.lower() == "txt"
|
is_txt_format = task_data.metadata_output_format and "txt" in task_data.metadata_output_format.lower().split(",")
|
||||||
if is_txt_format:
|
if is_txt_format:
|
||||||
metadata = {TASK_TEXT_MAPPING[key]: val for key, val in metadata.items() if key in TASK_TEXT_MAPPING}
|
metadata = {TASK_TEXT_MAPPING[key]: val for key, val in metadata.items() if key in TASK_TEXT_MAPPING}
|
||||||
|
|
||||||
@ -215,10 +219,12 @@ def get_printable_request(req: GenerateImageRequest, task_data: TaskData):
|
|||||||
del metadata["hypernetwork_strength"]
|
del metadata["hypernetwork_strength"]
|
||||||
if task_data.use_lora_model is None and "lora_alpha" in metadata:
|
if task_data.use_lora_model is None and "lora_alpha" in metadata:
|
||||||
del metadata["lora_alpha"]
|
del metadata["lora_alpha"]
|
||||||
|
if task_data.use_upscale != "latent_upscaler" and "latent_upscaler_steps" in metadata:
|
||||||
|
del metadata["latent_upscaler_steps"]
|
||||||
|
|
||||||
app_config = app.getConfig()
|
app_config = app.getConfig()
|
||||||
if not app_config.get("test_diffusers", False):
|
if not app_config.get("test_diffusers", False):
|
||||||
for key in (x for x in ["use_lora_model", "lora_alpha", "clip_skip"] if x in metadata):
|
for key in (x for x in ["use_lora_model", "lora_alpha", "clip_skip", "tiling", "latent_upscaler_steps"] if x in metadata):
|
||||||
del metadata[key]
|
del metadata[key]
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<h1>
|
<h1>
|
||||||
<img id="logo_img" src="/media/images/icon-512x512.png" >
|
<img id="logo_img" src="/media/images/icon-512x512.png" >
|
||||||
Easy Diffusion
|
Easy Diffusion
|
||||||
<small><span id="version">v2.5.38</span> <span id="updateBranchLabel"></span></small>
|
<small><span id="version">v2.5.41</span> <span id="updateBranchLabel"></span></small>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div id="server-status">
|
<div id="server-status">
|
||||||
@ -167,7 +167,7 @@
|
|||||||
<option value="unipc_snr" class="k_diffusion-only">UniPC SNR</option>
|
<option value="unipc_snr" class="k_diffusion-only">UniPC SNR</option>
|
||||||
<option value="unipc_tu">UniPC TU</option>
|
<option value="unipc_tu">UniPC TU</option>
|
||||||
<option value="unipc_snr_2" class="k_diffusion-only">UniPC SNR 2</option>
|
<option value="unipc_snr_2" class="k_diffusion-only">UniPC SNR 2</option>
|
||||||
<option value="unipc_tu_2">UniPC TU 2</option>
|
<option value="unipc_tu_2" class="k_diffusion-only">UniPC TU 2</option>
|
||||||
<option value="unipc_tq" class="k_diffusion-only">UniPC TQ</option>
|
<option value="unipc_tq" class="k_diffusion-only">UniPC TQ</option>
|
||||||
</select>
|
</select>
|
||||||
<a href="https://github.com/cmdr2/stable-diffusion-ui/wiki/How-to-Use#samplers" target="_blank"><i class="fa-solid fa-circle-question help-btn"><span class="simple-tooltip top-left">Click to learn more about samplers</span></i></a>
|
<a href="https://github.com/cmdr2/stable-diffusion-ui/wiki/How-to-Use#samplers" target="_blank"><i class="fa-solid fa-circle-question help-btn"><span class="simple-tooltip top-left">Click to learn more about samplers</span></i></a>
|
||||||
@ -227,7 +227,10 @@
|
|||||||
</td></tr>
|
</td></tr>
|
||||||
<tr id="lora_alpha_container" class="pl-5">
|
<tr id="lora_alpha_container" class="pl-5">
|
||||||
<td><label for="lora_alpha_slider">LoRA Strength:</label></td>
|
<td><label for="lora_alpha_slider">LoRA Strength:</label></td>
|
||||||
<td> <input id="lora_alpha_slider" name="lora_alpha_slider" class="editor-slider" value="50" type="range" min="0" max="100"> <input id="lora_alpha" name="lora_alpha" size="4" pattern="^[0-9\.]+$" onkeypress="preventNonNumericalInput(event)"><br/></td>
|
<td>
|
||||||
|
<small>-2</small> <input id="lora_alpha_slider" name="lora_alpha_slider" class="editor-slider" value="50" type="range" min="-200" max="200"> <small>2</small>
|
||||||
|
<input id="lora_alpha" name="lora_alpha" size="4" pattern="^-?[0-9]*\.?[0-9]*$" onkeypress="preventNonNumericalInput(event)"><br/>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="pl-5"><td><label for="hypernetwork_model">Hypernetwork:</label></td><td>
|
<tr class="pl-5"><td><label for="hypernetwork_model">Hypernetwork:</label></td><td>
|
||||||
<input id="hypernetwork_model" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" />
|
<input id="hypernetwork_model" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" />
|
||||||
@ -236,6 +239,15 @@
|
|||||||
<td><label for="hypernetwork_strength_slider">Hypernetwork Strength:</label></td>
|
<td><label for="hypernetwork_strength_slider">Hypernetwork Strength:</label></td>
|
||||||
<td> <input id="hypernetwork_strength_slider" name="hypernetwork_strength_slider" class="editor-slider" value="100" type="range" min="0" max="100"> <input id="hypernetwork_strength" name="hypernetwork_strength" size="4" pattern="^[0-9\.]+$" onkeypress="preventNonNumericalInput(event)"><br/></td>
|
<td> <input id="hypernetwork_strength_slider" name="hypernetwork_strength_slider" class="editor-slider" value="100" type="range" min="0" max="100"> <input id="hypernetwork_strength" name="hypernetwork_strength" size="4" pattern="^[0-9\.]+$" onkeypress="preventNonNumericalInput(event)"><br/></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr id="tiling_container" class="pl-5"><td><label for="tiling">Seamless Tiling:</label></td><td>
|
||||||
|
<select id="tiling" name="tiling">
|
||||||
|
<option value="none" selected>None</option>
|
||||||
|
<option value="x">Horizontal</option>
|
||||||
|
<option value="y">Vertical</option>
|
||||||
|
<option value="xy">Both</option>
|
||||||
|
</select>
|
||||||
|
<a href="https://github.com/cmdr2/stable-diffusion-ui/wiki/Seamless-Tiling" target="_blank"><i class="fa-solid fa-circle-question help-btn"><span class="simple-tooltip top-left">Click to learn more about Seamless Tiling</span></i></a>
|
||||||
|
</td></tr>
|
||||||
<tr class="pl-5"><td><label for="output_format">Output Format:</label></td><td>
|
<tr class="pl-5"><td><label for="output_format">Output Format:</label></td><td>
|
||||||
<select id="output_format" name="output_format">
|
<select id="output_format" name="output_format">
|
||||||
<option value="jpeg" selected>jpeg</option>
|
<option value="jpeg" selected>jpeg</option>
|
||||||
@ -254,7 +266,13 @@
|
|||||||
<div><ul>
|
<div><ul>
|
||||||
<li><b class="settings-subheader">Render Settings</b></li>
|
<li><b class="settings-subheader">Render Settings</b></li>
|
||||||
<li class="pl-5"><input id="stream_image_progress" name="stream_image_progress" type="checkbox"> <label for="stream_image_progress">Show a live preview <small>(uses more VRAM, slower images)</small></label></li>
|
<li class="pl-5"><input id="stream_image_progress" name="stream_image_progress" type="checkbox"> <label for="stream_image_progress">Show a live preview <small>(uses more VRAM, slower images)</small></label></li>
|
||||||
<li class="pl-5"><input id="use_face_correction" name="use_face_correction" type="checkbox"> <label for="use_face_correction">Fix incorrect faces and eyes</label> <div style="display:inline-block;"><input id="gfpgan_model" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" /></div></li>
|
<li class="pl-5" id="use_face_correction_container">
|
||||||
|
<input id="use_face_correction" name="use_face_correction" type="checkbox"> <label for="use_face_correction">Fix incorrect faces and eyes</label> <div style="display:inline-block;"><input id="gfpgan_model" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" /></div>
|
||||||
|
<table id="codeformer_settings" class="displayNone sub-settings">
|
||||||
|
<tr class="pl-5"><td><label for="codeformer_fidelity_slider">Strength:</label></td><td><input id="codeformer_fidelity_slider" name="codeformer_fidelity_slider" class="editor-slider" value="5" type="range" min="0" max="10"> <input id="codeformer_fidelity" name="codeformer_fidelity" size="4" pattern="^[0-9\.]+$" onkeypress="preventNonNumericalInput(event)"></td></tr>
|
||||||
|
<tr class="pl-5"><td><label for="codeformer_upscale_faces">Upscale Faces:</label></td><td><input id="codeformer_upscale_faces" name="codeformer_upscale_faces" type="checkbox" checked> <label><small>(improves the resolution of faces)</small></label></td></tr>
|
||||||
|
</table>
|
||||||
|
</li>
|
||||||
<li class="pl-5">
|
<li class="pl-5">
|
||||||
<input id="use_upscale" name="use_upscale" type="checkbox"> <label for="use_upscale">Scale up by</label>
|
<input id="use_upscale" name="use_upscale" type="checkbox"> <label for="use_upscale">Scale up by</label>
|
||||||
<select id="upscale_amount" name="upscale_amount">
|
<select id="upscale_amount" name="upscale_amount">
|
||||||
@ -267,9 +285,9 @@
|
|||||||
<option value="RealESRGAN_x4plus_anime_6B">RealESRGAN_x4plus_anime_6B</option>
|
<option value="RealESRGAN_x4plus_anime_6B">RealESRGAN_x4plus_anime_6B</option>
|
||||||
<option value="latent_upscaler">Latent Upscaler 2x</option>
|
<option value="latent_upscaler">Latent Upscaler 2x</option>
|
||||||
</select>
|
</select>
|
||||||
<div id="latent_upscaler_settings" class="displayNone">
|
<table id="latent_upscaler_settings" class="displayNone sub-settings">
|
||||||
<label for="latent_upscaler_steps_slider">Upscaling Steps:</label></td><td> <input id="latent_upscaler_steps_slider" name="latent_upscaler_steps_slider" class="editor-slider" value="10" type="range" min="1" max="50"> <input id="latent_upscaler_steps" name="latent_upscaler_steps" size="4" pattern="^[0-9\.]+$" onkeypress="preventNonNumericalInput(event)">
|
<tr class="pl-5"><td><label for="latent_upscaler_steps_slider">Upscaling Steps:</label></td><td><input id="latent_upscaler_steps_slider" name="latent_upscaler_steps_slider" class="editor-slider" value="10" type="range" min="1" max="50"> <input id="latent_upscaler_steps" name="latent_upscaler_steps" size="4" pattern="^[0-9\.]+$" onkeypress="preventNonNumericalInput(event)"></td></tr>
|
||||||
</div>
|
</table>
|
||||||
</li>
|
</li>
|
||||||
<li class="pl-5"><input id="show_only_filtered_image" name="show_only_filtered_image" type="checkbox" checked> <label for="show_only_filtered_image">Show only the corrected/upscaled image</label></li>
|
<li class="pl-5"><input id="show_only_filtered_image" name="show_only_filtered_image" type="checkbox" checked> <label for="show_only_filtered_image">Show only the corrected/upscaled image</label></li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
@ -347,10 +365,16 @@
|
|||||||
<div id="tab-content-settings" class="tab-content">
|
<div id="tab-content-settings" class="tab-content">
|
||||||
<div id="system-settings" class="tab-content-inner">
|
<div id="system-settings" class="tab-content-inner">
|
||||||
<h1>System Settings</h1>
|
<h1>System Settings</h1>
|
||||||
<div class="parameters-table"></div>
|
<div class="parameters-table" id="system-settings-table"></div>
|
||||||
<br/>
|
<br/>
|
||||||
<button id="save-system-settings-btn" class="primaryButton">Save</button>
|
<button id="save-system-settings-btn" class="primaryButton">Save</button>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
<div id="share-easy-diffusion">
|
||||||
|
<h3><i class="fa fa-user-group"></i> Share Easy Diffusion</h3>
|
||||||
|
<div class="parameters-table" id="system-settings-network-table">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br/><br/>
|
||||||
<div>
|
<div>
|
||||||
<h3><i class="fa fa-microchip icon"></i> System Info</h3>
|
<h3><i class="fa fa-microchip icon"></i> System Info</h3>
|
||||||
<div id="system-info">
|
<div id="system-info">
|
||||||
@ -571,7 +595,8 @@ async function init() {
|
|||||||
SD.init({
|
SD.init({
|
||||||
events: {
|
events: {
|
||||||
statusChange: setServerStatus,
|
statusChange: setServerStatus,
|
||||||
idle: onIdle
|
idle: onIdle,
|
||||||
|
ping: tunnelUpdate
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
splashScreen()
|
splashScreen()
|
||||||
|
@ -69,11 +69,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.parameters-table > div:first-child {
|
.parameters-table > div:first-child {
|
||||||
border-radius: 12px 12px 0px 0px;
|
border-top-left-radius: 12px;
|
||||||
|
border-top-right-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.parameters-table > div:last-child {
|
.parameters-table > div:last-child {
|
||||||
border-radius: 0px 0px 12px 12px;
|
border-bottom-left-radius: 12px;
|
||||||
|
border-bottom-right-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.parameters-table .fa-fire {
|
.parameters-table .fa-fire {
|
||||||
|
@ -96,7 +96,7 @@
|
|||||||
|
|
||||||
.editor-controls-center {
|
.editor-controls-center {
|
||||||
/* background: var(--background-color2); */
|
/* background: var(--background-color2); */
|
||||||
flex: 1;
|
flex: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -105,6 +105,8 @@
|
|||||||
.editor-controls-center > div {
|
.editor-controls-center > div {
|
||||||
position: relative;
|
position: relative;
|
||||||
background: black;
|
background: black;
|
||||||
|
margin: 20pt;
|
||||||
|
margin-top: 40pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-controls-center canvas {
|
.editor-controls-center canvas {
|
||||||
@ -164,8 +166,10 @@
|
|||||||
margin: var(--popup-margin);
|
margin: var(--popup-margin);
|
||||||
padding: var(--popup-padding);
|
padding: var(--popup-padding);
|
||||||
min-height: calc(99h - (2 * var(--popup-margin)));
|
min-height: calc(99h - (2 * var(--popup-margin)));
|
||||||
max-width: none;
|
max-width: fit-content;
|
||||||
min-width: fit-content;
|
min-width: fit-content;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-editor-popup h1 {
|
.image-editor-popup h1 {
|
||||||
|
@ -1346,12 +1346,35 @@ body.wait-pause {
|
|||||||
display:none !important;
|
display:none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
#latent_upscaler_settings {
|
.sub-settings {
|
||||||
padding-top: 3pt;
|
padding-top: 3pt;
|
||||||
padding-bottom: 3pt;
|
padding-bottom: 3pt;
|
||||||
padding-left: 5pt;
|
padding-left: 5pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#cloudflare-address {
|
||||||
|
background-color: var(--background-color3);
|
||||||
|
padding: 6px;
|
||||||
|
border-radius: var(--input-border-radius);
|
||||||
|
border: var(--input-border-size) solid var(--input-border-color);
|
||||||
|
margin-top: 0.2em;
|
||||||
|
margin-bottom: 0.2em;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
#copy-cloudflare-address {
|
||||||
|
padding: 4px 8px;
|
||||||
|
margin-left: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.expandedSettingRow {
|
||||||
|
background: var(--background-color1);
|
||||||
|
width: 95%;
|
||||||
|
border-radius: 4pt;
|
||||||
|
margin-top: 5pt;
|
||||||
|
margin-bottom: 3pt;
|
||||||
|
}
|
||||||
|
|
||||||
/* TOAST NOTIFICATIONS */
|
/* TOAST NOTIFICATIONS */
|
||||||
.toast-notification {
|
.toast-notification {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@ -1365,7 +1388,7 @@ body.wait-pause {
|
|||||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
animation: slideInRight 0.5s ease forwards;
|
animation: slideInRight 0.5s ease forwards;
|
||||||
transition: bottom 0.5s ease; // Add a transition to smoothly reposition the toasts
|
transition: bottom 0.5s ease; /* Add a transition to smoothly reposition the toasts */
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast-notification-error {
|
.toast-notification-error {
|
||||||
|
@ -25,6 +25,7 @@ const SETTINGS_IDS_LIST = [
|
|||||||
"prompt_strength",
|
"prompt_strength",
|
||||||
"hypernetwork_strength",
|
"hypernetwork_strength",
|
||||||
"lora_alpha",
|
"lora_alpha",
|
||||||
|
"tiling",
|
||||||
"output_format",
|
"output_format",
|
||||||
"output_quality",
|
"output_quality",
|
||||||
"output_lossless",
|
"output_lossless",
|
||||||
@ -34,6 +35,7 @@ const SETTINGS_IDS_LIST = [
|
|||||||
"gfpgan_model",
|
"gfpgan_model",
|
||||||
"use_upscale",
|
"use_upscale",
|
||||||
"upscale_amount",
|
"upscale_amount",
|
||||||
|
"latent_upscaler_steps",
|
||||||
"block_nsfw",
|
"block_nsfw",
|
||||||
"show_only_filtered_image",
|
"show_only_filtered_image",
|
||||||
"upscale_model",
|
"upscale_model",
|
||||||
|
@ -79,6 +79,7 @@ const TASK_MAPPING = {
|
|||||||
if (!widthField.value) {
|
if (!widthField.value) {
|
||||||
widthField.value = oldVal
|
widthField.value = oldVal
|
||||||
}
|
}
|
||||||
|
widthField.dispatchEvent(new Event("change"))
|
||||||
},
|
},
|
||||||
readUI: () => parseInt(widthField.value),
|
readUI: () => parseInt(widthField.value),
|
||||||
parse: (val) => parseInt(val),
|
parse: (val) => parseInt(val),
|
||||||
@ -91,6 +92,7 @@ const TASK_MAPPING = {
|
|||||||
if (!heightField.value) {
|
if (!heightField.value) {
|
||||||
heightField.value = oldVal
|
heightField.value = oldVal
|
||||||
}
|
}
|
||||||
|
heightField.dispatchEvent(new Event("change"))
|
||||||
},
|
},
|
||||||
readUI: () => parseInt(heightField.value),
|
readUI: () => parseInt(heightField.value),
|
||||||
parse: (val) => parseInt(val),
|
parse: (val) => parseInt(val),
|
||||||
@ -172,6 +174,11 @@ const TASK_MAPPING = {
|
|||||||
name: "Use Face Correction",
|
name: "Use Face Correction",
|
||||||
setUI: (use_face_correction) => {
|
setUI: (use_face_correction) => {
|
||||||
const oldVal = gfpganModelField.value
|
const oldVal = gfpganModelField.value
|
||||||
|
console.log("use face correction", use_face_correction)
|
||||||
|
if (use_face_correction == null || use_face_correction == "None") {
|
||||||
|
gfpganModelField.disabled = true
|
||||||
|
useFaceCorrectionField.checked = false
|
||||||
|
} else {
|
||||||
gfpganModelField.value = getModelPath(use_face_correction, [".pth"])
|
gfpganModelField.value = getModelPath(use_face_correction, [".pth"])
|
||||||
if (gfpganModelField.value) {
|
if (gfpganModelField.value) {
|
||||||
// Is a valid value for the field.
|
// Is a valid value for the field.
|
||||||
@ -183,6 +190,7 @@ const TASK_MAPPING = {
|
|||||||
gfpganModelField.value = oldVal
|
gfpganModelField.value = oldVal
|
||||||
useFaceCorrectionField.checked = false
|
useFaceCorrectionField.checked = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//useFaceCorrectionField.checked = parseBoolean(use_face_correction)
|
//useFaceCorrectionField.checked = parseBoolean(use_face_correction)
|
||||||
},
|
},
|
||||||
@ -218,6 +226,14 @@ const TASK_MAPPING = {
|
|||||||
readUI: () => upscaleAmountField.value,
|
readUI: () => upscaleAmountField.value,
|
||||||
parse: (val) => val,
|
parse: (val) => val,
|
||||||
},
|
},
|
||||||
|
latent_upscaler_steps: {
|
||||||
|
name: "Latent Upscaler Steps",
|
||||||
|
setUI: (latent_upscaler_steps) => {
|
||||||
|
latentUpscalerStepsField.value = latent_upscaler_steps
|
||||||
|
},
|
||||||
|
readUI: () => latentUpscalerStepsField.value,
|
||||||
|
parse: (val) => val,
|
||||||
|
},
|
||||||
sampler_name: {
|
sampler_name: {
|
||||||
name: "Sampler",
|
name: "Sampler",
|
||||||
setUI: (sampler_name) => {
|
setUI: (sampler_name) => {
|
||||||
@ -249,6 +265,14 @@ const TASK_MAPPING = {
|
|||||||
readUI: () => clip_skip.checked,
|
readUI: () => clip_skip.checked,
|
||||||
parse: (val) => Boolean(val),
|
parse: (val) => Boolean(val),
|
||||||
},
|
},
|
||||||
|
tiling: {
|
||||||
|
name: "Tiling",
|
||||||
|
setUI: (val) => {
|
||||||
|
tilingField.value = val
|
||||||
|
},
|
||||||
|
readUI: () => tilingField.value,
|
||||||
|
parse: (val) => val,
|
||||||
|
},
|
||||||
use_vae_model: {
|
use_vae_model: {
|
||||||
name: "VAE model",
|
name: "VAE model",
|
||||||
setUI: (use_vae_model) => {
|
setUI: (use_vae_model) => {
|
||||||
@ -411,6 +435,7 @@ function restoreTaskToUI(task, fieldsToSkip) {
|
|||||||
if (!("original_prompt" in task.reqBody)) {
|
if (!("original_prompt" in task.reqBody)) {
|
||||||
promptField.value = task.reqBody.prompt
|
promptField.value = task.reqBody.prompt
|
||||||
}
|
}
|
||||||
|
promptField.dispatchEvent(new Event("input"))
|
||||||
|
|
||||||
// properly reset checkboxes
|
// properly reset checkboxes
|
||||||
if (!("use_face_correction" in task.reqBody)) {
|
if (!("use_face_correction" in task.reqBody)) {
|
||||||
|
@ -186,6 +186,7 @@
|
|||||||
const EVENT_TASK_START = "taskStart"
|
const EVENT_TASK_START = "taskStart"
|
||||||
const EVENT_TASK_END = "taskEnd"
|
const EVENT_TASK_END = "taskEnd"
|
||||||
const EVENT_TASK_ERROR = "task_error"
|
const EVENT_TASK_ERROR = "task_error"
|
||||||
|
const EVENT_PING = "ping"
|
||||||
const EVENT_UNEXPECTED_RESPONSE = "unexpectedResponse"
|
const EVENT_UNEXPECTED_RESPONSE = "unexpectedResponse"
|
||||||
const EVENTS_TYPES = [
|
const EVENTS_TYPES = [
|
||||||
EVENT_IDLE,
|
EVENT_IDLE,
|
||||||
@ -196,6 +197,7 @@
|
|||||||
EVENT_TASK_START,
|
EVENT_TASK_START,
|
||||||
EVENT_TASK_END,
|
EVENT_TASK_END,
|
||||||
EVENT_TASK_ERROR,
|
EVENT_TASK_ERROR,
|
||||||
|
EVENT_PING,
|
||||||
|
|
||||||
EVENT_UNEXPECTED_RESPONSE,
|
EVENT_UNEXPECTED_RESPONSE,
|
||||||
]
|
]
|
||||||
@ -240,6 +242,7 @@
|
|||||||
setServerStatus("error", "offline")
|
setServerStatus("error", "offline")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set status
|
// Set status
|
||||||
switch (serverState.status) {
|
switch (serverState.status) {
|
||||||
case ServerStates.init:
|
case ServerStates.init:
|
||||||
@ -261,6 +264,7 @@
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
serverState.time = Date.now()
|
serverState.time = Date.now()
|
||||||
|
await eventSource.fireEvent(EVENT_PING, serverState)
|
||||||
return true
|
return true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
@ -789,9 +793,10 @@
|
|||||||
use_hypernetwork_model: "string",
|
use_hypernetwork_model: "string",
|
||||||
hypernetwork_strength: "number",
|
hypernetwork_strength: "number",
|
||||||
output_lossless: "boolean",
|
output_lossless: "boolean",
|
||||||
|
tiling: "string",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Higer values will result in...
|
// Higher values will result in...
|
||||||
// pytorch_lightning/utilities/seed.py:60: UserWarning: X is not in bounds, numpy accepts from 0 to 4294967295
|
// pytorch_lightning/utilities/seed.py:60: UserWarning: X is not in bounds, numpy accepts from 0 to 4294967295
|
||||||
const MAX_SEED_VALUE = 4294967295
|
const MAX_SEED_VALUE = 4294967295
|
||||||
|
|
||||||
|
@ -18,6 +18,11 @@ const taskConfigSetup = {
|
|||||||
visible: ({ reqBody }) => reqBody?.clip_skip,
|
visible: ({ reqBody }) => reqBody?.clip_skip,
|
||||||
value: ({ reqBody }) => "yes",
|
value: ({ reqBody }) => "yes",
|
||||||
},
|
},
|
||||||
|
tiling: {
|
||||||
|
label: "Tiling",
|
||||||
|
visible: ({ reqBody }) => reqBody?.tiling != "none",
|
||||||
|
value: ({ reqBody }) => reqBody?.tiling,
|
||||||
|
},
|
||||||
use_vae_model: {
|
use_vae_model: {
|
||||||
label: "VAE",
|
label: "VAE",
|
||||||
visible: ({ reqBody }) => reqBody?.use_vae_model !== undefined && reqBody?.use_vae_model.trim() !== "",
|
visible: ({ reqBody }) => reqBody?.use_vae_model !== undefined && reqBody?.use_vae_model.trim() !== "",
|
||||||
@ -82,15 +87,18 @@ let promptStrengthField = document.querySelector("#prompt_strength")
|
|||||||
let samplerField = document.querySelector("#sampler_name")
|
let samplerField = document.querySelector("#sampler_name")
|
||||||
let samplerSelectionContainer = document.querySelector("#samplerSelection")
|
let samplerSelectionContainer = document.querySelector("#samplerSelection")
|
||||||
let useFaceCorrectionField = document.querySelector("#use_face_correction")
|
let useFaceCorrectionField = document.querySelector("#use_face_correction")
|
||||||
let gfpganModelField = new ModelDropdown(document.querySelector("#gfpgan_model"), "gfpgan")
|
let gfpganModelField = new ModelDropdown(document.querySelector("#gfpgan_model"), ["gfpgan", "codeformer"], "", false)
|
||||||
let useUpscalingField = document.querySelector("#use_upscale")
|
let useUpscalingField = document.querySelector("#use_upscale")
|
||||||
let upscaleModelField = document.querySelector("#upscale_model")
|
let upscaleModelField = document.querySelector("#upscale_model")
|
||||||
let upscaleAmountField = document.querySelector("#upscale_amount")
|
let upscaleAmountField = document.querySelector("#upscale_amount")
|
||||||
let latentUpscalerSettings = document.querySelector("#latent_upscaler_settings")
|
let latentUpscalerSettings = document.querySelector("#latent_upscaler_settings")
|
||||||
let latentUpscalerStepsSlider = document.querySelector("#latent_upscaler_steps_slider")
|
let latentUpscalerStepsSlider = document.querySelector("#latent_upscaler_steps_slider")
|
||||||
let latentUpscalerStepsField = document.querySelector("#latent_upscaler_steps")
|
let latentUpscalerStepsField = document.querySelector("#latent_upscaler_steps")
|
||||||
|
let codeformerFidelitySlider = document.querySelector("#codeformer_fidelity_slider")
|
||||||
|
let codeformerFidelityField = document.querySelector("#codeformer_fidelity")
|
||||||
let stableDiffusionModelField = new ModelDropdown(document.querySelector("#stable_diffusion_model"), "stable-diffusion")
|
let stableDiffusionModelField = new ModelDropdown(document.querySelector("#stable_diffusion_model"), "stable-diffusion")
|
||||||
let clipSkipField = document.querySelector("#clip_skip")
|
let clipSkipField = document.querySelector("#clip_skip")
|
||||||
|
let tilingField = document.querySelector("#tiling")
|
||||||
let vaeModelField = new ModelDropdown(document.querySelector("#vae_model"), "vae", "None")
|
let vaeModelField = new ModelDropdown(document.querySelector("#vae_model"), "vae", "None")
|
||||||
let hypernetworkModelField = new ModelDropdown(document.querySelector("#hypernetwork_model"), "hypernetwork", "None")
|
let hypernetworkModelField = new ModelDropdown(document.querySelector("#hypernetwork_model"), "hypernetwork", "None")
|
||||||
let hypernetworkStrengthSlider = document.querySelector("#hypernetwork_strength_slider")
|
let hypernetworkStrengthSlider = document.querySelector("#hypernetwork_strength_slider")
|
||||||
@ -266,7 +274,9 @@ function shiftOrConfirm(e, prompt, fn) {
|
|||||||
confirm(
|
confirm(
|
||||||
'<small>Tip: To skip this dialog, use shift-click or disable the "Confirm dangerous actions" setting in the Settings tab.</small>',
|
'<small>Tip: To skip this dialog, use shift-click or disable the "Confirm dangerous actions" setting in the Settings tab.</small>',
|
||||||
prompt,
|
prompt,
|
||||||
fn
|
() => {
|
||||||
|
fn(e)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1223,6 +1233,7 @@ function getCurrentUserRequest() {
|
|||||||
//render_device: undefined, // Set device affinity. Prefer this device, but wont activate.
|
//render_device: undefined, // Set device affinity. Prefer this device, but wont activate.
|
||||||
use_stable_diffusion_model: stableDiffusionModelField.value,
|
use_stable_diffusion_model: stableDiffusionModelField.value,
|
||||||
clip_skip: clipSkipField.checked,
|
clip_skip: clipSkipField.checked,
|
||||||
|
tiling: tilingField.value,
|
||||||
use_vae_model: vaeModelField.value,
|
use_vae_model: vaeModelField.value,
|
||||||
stream_progress_updates: true,
|
stream_progress_updates: true,
|
||||||
stream_image_progress: numOutputsTotal > 50 ? false : streamImageProgressField.checked,
|
stream_image_progress: numOutputsTotal > 50 ? false : streamImageProgressField.checked,
|
||||||
@ -1256,6 +1267,11 @@ function getCurrentUserRequest() {
|
|||||||
}
|
}
|
||||||
if (useFaceCorrectionField.checked) {
|
if (useFaceCorrectionField.checked) {
|
||||||
newTask.reqBody.use_face_correction = gfpganModelField.value
|
newTask.reqBody.use_face_correction = gfpganModelField.value
|
||||||
|
|
||||||
|
if (gfpganModelField.value.includes("codeformer")) {
|
||||||
|
newTask.reqBody.codeformer_upscale_faces = document.querySelector("#codeformer_upscale_faces").checked
|
||||||
|
newTask.reqBody.codeformer_fidelity = 1 - parseFloat(codeformerFidelityField.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (useUpscalingField.checked) {
|
if (useUpscalingField.checked) {
|
||||||
newTask.reqBody.use_upscale = upscaleModelField.value
|
newTask.reqBody.use_upscale = upscaleModelField.value
|
||||||
@ -1569,24 +1585,43 @@ metadataOutputFormatField.disabled = !saveToDiskField.checked
|
|||||||
gfpganModelField.disabled = !useFaceCorrectionField.checked
|
gfpganModelField.disabled = !useFaceCorrectionField.checked
|
||||||
useFaceCorrectionField.addEventListener("change", function(e) {
|
useFaceCorrectionField.addEventListener("change", function(e) {
|
||||||
gfpganModelField.disabled = !this.checked
|
gfpganModelField.disabled = !this.checked
|
||||||
|
|
||||||
|
onFixFaceModelChange()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function onFixFaceModelChange() {
|
||||||
|
let codeformerSettings = document.querySelector("#codeformer_settings")
|
||||||
|
if (gfpganModelField.value === "codeformer" && !gfpganModelField.disabled) {
|
||||||
|
codeformerSettings.classList.remove("displayNone")
|
||||||
|
codeformerSettings.classList.add("expandedSettingRow")
|
||||||
|
} else {
|
||||||
|
codeformerSettings.classList.add("displayNone")
|
||||||
|
codeformerSettings.classList.remove("expandedSettingRow")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gfpganModelField.addEventListener("change", onFixFaceModelChange)
|
||||||
|
onFixFaceModelChange()
|
||||||
|
|
||||||
upscaleModelField.disabled = !useUpscalingField.checked
|
upscaleModelField.disabled = !useUpscalingField.checked
|
||||||
upscaleAmountField.disabled = !useUpscalingField.checked
|
upscaleAmountField.disabled = !useUpscalingField.checked
|
||||||
useUpscalingField.addEventListener("change", function(e) {
|
useUpscalingField.addEventListener("change", function(e) {
|
||||||
upscaleModelField.disabled = !this.checked
|
upscaleModelField.disabled = !this.checked
|
||||||
upscaleAmountField.disabled = !this.checked
|
upscaleAmountField.disabled = !this.checked
|
||||||
|
|
||||||
|
onUpscaleModelChange()
|
||||||
})
|
})
|
||||||
|
|
||||||
function onUpscaleModelChange() {
|
function onUpscaleModelChange() {
|
||||||
let upscale4x = document.querySelector("#upscale_amount_4x")
|
let upscale4x = document.querySelector("#upscale_amount_4x")
|
||||||
if (upscaleModelField.value === "latent_upscaler") {
|
if (upscaleModelField.value === "latent_upscaler" && !upscaleModelField.disabled) {
|
||||||
upscale4x.disabled = true
|
upscale4x.disabled = true
|
||||||
upscaleAmountField.value = "2"
|
upscaleAmountField.value = "2"
|
||||||
latentUpscalerSettings.classList.remove("displayNone")
|
latentUpscalerSettings.classList.remove("displayNone")
|
||||||
|
latentUpscalerSettings.classList.add("expandedSettingRow")
|
||||||
} else {
|
} else {
|
||||||
upscale4x.disabled = false
|
upscale4x.disabled = false
|
||||||
latentUpscalerSettings.classList.add("displayNone")
|
latentUpscalerSettings.classList.add("displayNone")
|
||||||
|
latentUpscalerSettings.classList.remove("expandedSettingRow")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
upscaleModelField.addEventListener("change", onUpscaleModelChange)
|
upscaleModelField.addEventListener("change", onUpscaleModelChange)
|
||||||
@ -1601,6 +1636,27 @@ document.onkeydown = function(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************* CodeFormer Fidelity **************************/
|
||||||
|
function updateCodeformerFidelity() {
|
||||||
|
codeformerFidelityField.value = codeformerFidelitySlider.value / 10
|
||||||
|
codeformerFidelityField.dispatchEvent(new Event("change"))
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateCodeformerFidelitySlider() {
|
||||||
|
if (codeformerFidelityField.value < 0) {
|
||||||
|
codeformerFidelityField.value = 0
|
||||||
|
} else if (codeformerFidelityField.value > 1) {
|
||||||
|
codeformerFidelityField.value = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
codeformerFidelitySlider.value = codeformerFidelityField.value * 10
|
||||||
|
codeformerFidelitySlider.dispatchEvent(new Event("change"))
|
||||||
|
}
|
||||||
|
|
||||||
|
codeformerFidelitySlider.addEventListener("input", updateCodeformerFidelity)
|
||||||
|
codeformerFidelityField.addEventListener("input", updateCodeformerFidelitySlider)
|
||||||
|
updateCodeformerFidelity()
|
||||||
|
|
||||||
/********************* Latent Upscaler Steps **************************/
|
/********************* Latent Upscaler Steps **************************/
|
||||||
function updateLatentUpscalerSteps() {
|
function updateLatentUpscalerSteps() {
|
||||||
latentUpscalerStepsField.value = latentUpscalerStepsSlider.value
|
latentUpscalerStepsField.value = latentUpscalerStepsSlider.value
|
||||||
@ -1699,10 +1755,10 @@ function updateLoraAlpha() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateLoraAlphaSlider() {
|
function updateLoraAlphaSlider() {
|
||||||
if (loraAlphaField.value < 0) {
|
if (loraAlphaField.value < -2) {
|
||||||
loraAlphaField.value = 0
|
loraAlphaField.value = -2
|
||||||
} else if (loraAlphaField.value > 1) {
|
} else if (loraAlphaField.value > 2) {
|
||||||
loraAlphaField.value = 1
|
loraAlphaField.value = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
loraAlphaSlider.value = loraAlphaField.value * 100
|
loraAlphaSlider.value = loraAlphaField.value * 100
|
||||||
@ -1968,6 +2024,38 @@ resumeBtn.addEventListener("click", function() {
|
|||||||
document.body.classList.remove("wait-pause")
|
document.body.classList.remove("wait-pause")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function tunnelUpdate(event) {
|
||||||
|
if ("cloudflare" in event) {
|
||||||
|
document.getElementById("cloudflare-off").classList.add("displayNone")
|
||||||
|
document.getElementById("cloudflare-on").classList.remove("displayNone")
|
||||||
|
cloudflareAddressField.innerHTML = event.cloudflare
|
||||||
|
document.getElementById("toggle-cloudflare-tunnel").innerHTML = "Stop"
|
||||||
|
} else {
|
||||||
|
document.getElementById("cloudflare-on").classList.add("displayNone")
|
||||||
|
document.getElementById("cloudflare-off").classList.remove("displayNone")
|
||||||
|
document.getElementById("toggle-cloudflare-tunnel").innerHTML = "Start"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("toggle-cloudflare-tunnel").addEventListener("click", async function() {
|
||||||
|
let command = "stop"
|
||||||
|
if (document.getElementById("toggle-cloudflare-tunnel").innerHTML == "Start") {
|
||||||
|
command = "start"
|
||||||
|
}
|
||||||
|
showToast(`Cloudflare tunnel ${command} initiated. Please wait.`)
|
||||||
|
|
||||||
|
let res = await fetch("/tunnel/cloudflare/" + command, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({}),
|
||||||
|
})
|
||||||
|
res = await res.json()
|
||||||
|
|
||||||
|
console.log(`Cloudflare tunnel ${command} result:`, res)
|
||||||
|
})
|
||||||
|
|
||||||
/* Pause function */
|
/* Pause function */
|
||||||
document.querySelectorAll(".tab").forEach(linkTabContents)
|
document.querySelectorAll(".tab").forEach(linkTabContents)
|
||||||
|
|
||||||
|
@ -11,6 +11,12 @@ var ParameterType = {
|
|||||||
custom: "custom",
|
custom: "custom",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Element shortcuts
|
||||||
|
*/
|
||||||
|
let parametersTable = document.querySelector("#system-settings-table")
|
||||||
|
let networkParametersTable = document.querySelector("#system-settings-network-table")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSDoc style
|
* JSDoc style
|
||||||
* @typedef {object} Parameter
|
* @typedef {object} Parameter
|
||||||
@ -186,6 +192,7 @@ var PARAMETERS = [
|
|||||||
icon: "fa-network-wired",
|
icon: "fa-network-wired",
|
||||||
default: true,
|
default: true,
|
||||||
saveInAppConfig: true,
|
saveInAppConfig: true,
|
||||||
|
table: networkParametersTable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "listen_port",
|
id: "listen_port",
|
||||||
@ -198,6 +205,7 @@ var PARAMETERS = [
|
|||||||
return `<input id="${parameter.id}" name="${parameter.id}" size="6" value="9000" onkeypress="preventNonNumericalInput(event)">`
|
return `<input id="${parameter.id}" name="${parameter.id}" size="6" value="9000" onkeypress="preventNonNumericalInput(event)">`
|
||||||
},
|
},
|
||||||
saveInAppConfig: true,
|
saveInAppConfig: true,
|
||||||
|
table: networkParametersTable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "use_beta_channel",
|
id: "use_beta_channel",
|
||||||
@ -218,6 +226,21 @@ var PARAMETERS = [
|
|||||||
default: false,
|
default: false,
|
||||||
saveInAppConfig: true,
|
saveInAppConfig: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "cloudflare",
|
||||||
|
type: ParameterType.custom,
|
||||||
|
label: "Cloudflare tunnel",
|
||||||
|
note: `<span id="cloudflare-off">Create a VPN tunnel to share your Easy Diffusion instance with your friends. This will
|
||||||
|
generate a web server address on the public Internet for your Easy Diffusion instance. </span>
|
||||||
|
<div id="cloudflare-on" class="displayNone"><div>This Easy Diffusion server is available on the Internet using the
|
||||||
|
address:</div><div><div id="cloudflare-address"></div><button id="copy-cloudflare-address">Copy</button></div></div>
|
||||||
|
<b>Anyone knowing this address can access your server.</b> The address of your server will change each time
|
||||||
|
you share a session.<br>
|
||||||
|
Uses <a href="https://try.cloudflare.com/" target="_blank">Cloudflare services</a>.`,
|
||||||
|
icon: ["fa-brands", "fa-cloudflare"],
|
||||||
|
render: () => '<button id="toggle-cloudflare-tunnel" class="primaryButton">Start</button>',
|
||||||
|
table: networkParametersTable,
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
function getParameterSettingsEntry(id) {
|
function getParameterSettingsEntry(id) {
|
||||||
@ -266,7 +289,6 @@ function getParameterElement(parameter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let parametersTable = document.querySelector("#system-settings .parameters-table")
|
|
||||||
/**
|
/**
|
||||||
* fill in the system settings popup table
|
* fill in the system settings popup table
|
||||||
* @param {Array<Parameter> | undefined} parameters
|
* @param {Array<Parameter> | undefined} parameters
|
||||||
@ -293,7 +315,10 @@ function initParameters(parameters) {
|
|||||||
noteElements.push(noteElement)
|
noteElements.push(noteElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
const icon = parameter.icon ? [createElement("i", undefined, ["fa", parameter.icon])] : []
|
if (typeof(parameter.icon) == "string") {
|
||||||
|
parameter.icon = [parameter.icon]
|
||||||
|
}
|
||||||
|
const icon = parameter.icon ? [createElement("i", undefined, ["fa", ...parameter.icon])] : []
|
||||||
|
|
||||||
const label = typeof parameter.label === "function" ? parameter.label(parameter) : parameter.label
|
const label = typeof parameter.label === "function" ? parameter.label(parameter) : parameter.label
|
||||||
const labelElement = createElement("label", { for: parameter.id })
|
const labelElement = createElement("label", { for: parameter.id })
|
||||||
@ -313,7 +338,13 @@ function initParameters(parameters) {
|
|||||||
elementWrapper,
|
elementWrapper,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
parametersTable.appendChild(newrow)
|
|
||||||
|
let p = parametersTable
|
||||||
|
if (parameter.table) {
|
||||||
|
p = parameter.table
|
||||||
|
}
|
||||||
|
p.appendChild(newrow)
|
||||||
|
|
||||||
parameter.settingsEntry = newrow
|
parameter.settingsEntry = newrow
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -396,6 +427,7 @@ async function getAppConfig() {
|
|||||||
if (!testDiffusersEnabled) {
|
if (!testDiffusersEnabled) {
|
||||||
document.querySelector("#lora_model_container").style.display = "none"
|
document.querySelector("#lora_model_container").style.display = "none"
|
||||||
document.querySelector("#lora_alpha_container").style.display = "none"
|
document.querySelector("#lora_alpha_container").style.display = "none"
|
||||||
|
document.querySelector("#tiling_container").style.display = "none"
|
||||||
|
|
||||||
document.querySelectorAll("#sampler_name option.diffusers-only").forEach((option) => {
|
document.querySelectorAll("#sampler_name option.diffusers-only").forEach((option) => {
|
||||||
option.style.display = "none"
|
option.style.display = "none"
|
||||||
@ -403,6 +435,7 @@ async function getAppConfig() {
|
|||||||
} else {
|
} else {
|
||||||
document.querySelector("#lora_model_container").style.display = ""
|
document.querySelector("#lora_model_container").style.display = ""
|
||||||
document.querySelector("#lora_alpha_container").style.display = loraModelField.value ? "" : "none"
|
document.querySelector("#lora_alpha_container").style.display = loraModelField.value ? "" : "none"
|
||||||
|
document.querySelector("#tiling_container").style.display = ""
|
||||||
|
|
||||||
document.querySelectorAll("#sampler_name option.k_diffusion-only").forEach((option) => {
|
document.querySelectorAll("#sampler_name option.k_diffusion-only").forEach((option) => {
|
||||||
option.disabled = true
|
option.disabled = true
|
||||||
@ -631,7 +664,7 @@ saveSettingsBtn.addEventListener("click", function() {
|
|||||||
update_branch: updateBranch,
|
update_branch: updateBranch,
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.from(parametersTable.children).forEach((parameterRow) => {
|
document.querySelectorAll('#system-settings [data-setting-id]').forEach((parameterRow) => {
|
||||||
if (parameterRow.dataset.saveInAppConfig === "true") {
|
if (parameterRow.dataset.saveInAppConfig === "true") {
|
||||||
const parameterElement =
|
const parameterElement =
|
||||||
document.getElementById(parameterRow.dataset.settingId) ||
|
document.getElementById(parameterRow.dataset.settingId) ||
|
||||||
@ -665,8 +698,25 @@ saveSettingsBtn.addEventListener("click", function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const savePromise = changeAppConfig(updateAppConfigRequest)
|
const savePromise = changeAppConfig(updateAppConfigRequest)
|
||||||
|
showToast("Settings saved")
|
||||||
saveSettingsBtn.classList.add("active")
|
saveSettingsBtn.classList.add("active")
|
||||||
Promise.all([savePromise, asyncDelay(300)]).then(() => saveSettingsBtn.classList.remove("active"))
|
Promise.all([savePromise, asyncDelay(300)]).then(() => saveSettingsBtn.classList.remove("active"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
listenToNetworkField.addEventListener("change", debounce( ()=>{
|
||||||
|
saveSettingsBtn.click()
|
||||||
|
}, 1000))
|
||||||
|
|
||||||
|
listenPortField.addEventListener("change", debounce( ()=>{
|
||||||
|
saveSettingsBtn.click()
|
||||||
|
}, 1000))
|
||||||
|
|
||||||
|
let copyCloudflareAddressBtn = document.querySelector("#copy-cloudflare-address")
|
||||||
|
let cloudflareAddressField = document.getElementById("cloudflare-address")
|
||||||
|
|
||||||
|
copyCloudflareAddressBtn.addEventListener("click", (e) => {
|
||||||
|
navigator.clipboard.writeText(cloudflareAddressField.innerHTML)
|
||||||
|
showToast("Copied server address to clipboard")
|
||||||
|
})
|
||||||
|
|
||||||
document.addEventListener("system_info_update", (e) => setDeviceInfo(e.detail))
|
document.addEventListener("system_info_update", (e) => setDeviceInfo(e.detail))
|
||||||
|
@ -38,6 +38,8 @@ class ModelDropdown {
|
|||||||
noneEntry //= ''
|
noneEntry //= ''
|
||||||
modelFilterInitialized //= undefined
|
modelFilterInitialized //= undefined
|
||||||
|
|
||||||
|
sorted //= true
|
||||||
|
|
||||||
/* MIMIC A REGULAR INPUT FIELD */
|
/* MIMIC A REGULAR INPUT FIELD */
|
||||||
get parentElement() {
|
get parentElement() {
|
||||||
return this.modelFilter.parentElement
|
return this.modelFilter.parentElement
|
||||||
@ -83,21 +85,34 @@ class ModelDropdown {
|
|||||||
|
|
||||||
/* SEARCHABLE INPUT */
|
/* SEARCHABLE INPUT */
|
||||||
|
|
||||||
constructor(input, modelKey, noneEntry = "") {
|
constructor(input, modelKey, noneEntry = "", sorted = true) {
|
||||||
this.modelFilter = input
|
this.modelFilter = input
|
||||||
this.noneEntry = noneEntry
|
this.noneEntry = noneEntry
|
||||||
this.modelKey = modelKey
|
this.modelKey = modelKey
|
||||||
|
this.sorted = sorted
|
||||||
|
|
||||||
if (modelsOptions !== undefined) {
|
if (modelsOptions !== undefined) {
|
||||||
// reuse models from cache (only useful for plugins, which are loaded after models)
|
// reuse models from cache (only useful for plugins, which are loaded after models)
|
||||||
this.inputModels = modelsOptions[this.modelKey]
|
this.inputModels = []
|
||||||
|
let modelKeys = Array.isArray(this.modelKey) ? this.modelKey : [this.modelKey]
|
||||||
|
for (let i = 0; i < modelKeys.length; i++) {
|
||||||
|
let key = modelKeys[i]
|
||||||
|
let k = Array.isArray(modelsOptions[key]) ? modelsOptions[key] : [modelsOptions[key]]
|
||||||
|
this.inputModels.push(...k)
|
||||||
|
}
|
||||||
this.populateModels()
|
this.populateModels()
|
||||||
}
|
}
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"refreshModels",
|
"refreshModels",
|
||||||
this.bind(function(e) {
|
this.bind(function(e) {
|
||||||
// reload the models
|
// reload the models
|
||||||
this.inputModels = modelsOptions[this.modelKey]
|
this.inputModels = []
|
||||||
|
let modelKeys = Array.isArray(this.modelKey) ? this.modelKey : [this.modelKey]
|
||||||
|
for (let i = 0; i < modelKeys.length; i++) {
|
||||||
|
let key = modelKeys[i]
|
||||||
|
let k = Array.isArray(modelsOptions[key]) ? modelsOptions[key] : [modelsOptions[key]]
|
||||||
|
this.inputModels.push(...k)
|
||||||
|
}
|
||||||
this.populateModels()
|
this.populateModels()
|
||||||
}, this)
|
}, this)
|
||||||
)
|
)
|
||||||
@ -554,11 +569,15 @@ class ModelDropdown {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const childFolderNames = Array.from(foldersMap.keys())
|
const childFolderNames = Array.from(foldersMap.keys())
|
||||||
|
if (this.sorted) {
|
||||||
this.sortStringArray(childFolderNames)
|
this.sortStringArray(childFolderNames)
|
||||||
|
}
|
||||||
const folderElements = childFolderNames.map((name) => foldersMap.get(name))
|
const folderElements = childFolderNames.map((name) => foldersMap.get(name))
|
||||||
|
|
||||||
const modelNames = Array.from(modelsMap.keys())
|
const modelNames = Array.from(modelsMap.keys())
|
||||||
|
if (this.sorted) {
|
||||||
this.sortStringArray(modelNames)
|
this.sortStringArray(modelNames)
|
||||||
|
}
|
||||||
const modelElements = modelNames.map((name) => modelsMap.get(name))
|
const modelElements = modelNames.map((name) => modelsMap.get(name))
|
||||||
|
|
||||||
if (modelElements.length && folderName) {
|
if (modelElements.length && folderName) {
|
||||||
|
@ -402,12 +402,12 @@ function debounce(func, wait, immediate) {
|
|||||||
|
|
||||||
function preventNonNumericalInput(e) {
|
function preventNonNumericalInput(e) {
|
||||||
e = e || window.event
|
e = e || window.event
|
||||||
let charCode = typeof e.which == "undefined" ? e.keyCode : e.which
|
const charCode = typeof e.which == "undefined" ? e.keyCode : e.which
|
||||||
let charStr = String.fromCharCode(charCode)
|
const charStr = String.fromCharCode(charCode)
|
||||||
let re = e.target.getAttribute("pattern") || "^[0-9]+$"
|
const newInputValue = `${e.target.value}${charStr}`
|
||||||
re = new RegExp(re)
|
const re = new RegExp(e.target.getAttribute("pattern") || "^[0-9]+$")
|
||||||
|
|
||||||
if (!charStr.match(re)) {
|
if (!re.test(charStr) && !re.test(newInputValue)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -918,9 +918,7 @@ function confirm(msg, title, fn) {
|
|||||||
animateFromElement: false,
|
animateFromElement: false,
|
||||||
content: msg,
|
content: msg,
|
||||||
buttons: {
|
buttons: {
|
||||||
yes: () => {
|
yes: fn,
|
||||||
fn(e)
|
|
||||||
},
|
|
||||||
cancel: () => {},
|
cancel: () => {},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -403,6 +403,8 @@
|
|||||||
// Batch main loop
|
// Batch main loop
|
||||||
for (let i = 0; i < iterations; i++) {
|
for (let i = 0; i < iterations; i++) {
|
||||||
let alpha = (start + i * step) / 100
|
let alpha = (start + i * step) / 100
|
||||||
|
|
||||||
|
if (isTabActive(tabSettingsBatch)) {
|
||||||
switch (document.querySelector("#merge-interpolation").value) {
|
switch (document.querySelector("#merge-interpolation").value) {
|
||||||
case "SmoothStep":
|
case "SmoothStep":
|
||||||
alpha = smoothstep(alpha)
|
alpha = smoothstep(alpha)
|
||||||
@ -414,13 +416,15 @@
|
|||||||
alpha = smootheststep(alpha)
|
alpha = smootheststep(alpha)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
addLogMessage(`merging batch job ${i + 1}/${iterations}, alpha = ${alpha.toFixed(5)}...`)
|
addLogMessage(`merging batch job ${i + 1}/${iterations}, alpha = ${alpha.toFixed(5)}...`)
|
||||||
|
|
||||||
request["out_path"] = document.querySelector("#merge-filename").value
|
request["out_path"] = document.querySelector("#merge-filename").value
|
||||||
request["out_path"] += "-" + alpha.toFixed(5) + "." + document.querySelector("#merge-format").value
|
request["out_path"] += "-" + alpha.toFixed(5) + "." + document.querySelector("#merge-format").value
|
||||||
addLogMessage(` filename: ${request["out_path"]}`)
|
addLogMessage(` filename: ${request["out_path"]}`)
|
||||||
|
|
||||||
request["ratio"] = alpha
|
// sdkit documentation: "ratio - the ratio of the second model. 1 means only the second model will be used."
|
||||||
|
request["ratio"] = 1-alpha
|
||||||
let res = await fetch("/model/merge", {
|
let res = await fetch("/model/merge", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
326
ui/plugins/ui/tiled-image-download.plugin.js
Normal file
326
ui/plugins/ui/tiled-image-download.plugin.js
Normal file
@ -0,0 +1,326 @@
|
|||||||
|
;(function(){
|
||||||
|
"use strict";
|
||||||
|
const PAPERSIZE = [
|
||||||
|
{id: "a3p", width: 297, height: 420, unit: "mm"},
|
||||||
|
{id: "a3l", width: 420, height: 297, unit: "mm"},
|
||||||
|
{id: "a4p", width: 210, height: 297, unit: "mm"},
|
||||||
|
{id: "a4l", width: 297, height: 210, unit: "mm"},
|
||||||
|
{id: "ll", width: 279, height: 216, unit: "mm"},
|
||||||
|
{id: "lp", width: 216, height: 279, unit: "mm"},
|
||||||
|
{id: "hd", width: 1920, height: 1080, unit: "pixels"},
|
||||||
|
{id: "4k", width: 3840, height: 2160, unit: "pixels"},
|
||||||
|
]
|
||||||
|
|
||||||
|
// ---- Register plugin
|
||||||
|
PLUGINS['IMAGE_INFO_BUTTONS'].push({
|
||||||
|
html: '<i class="fa-solid fa-table-cells-large"></i> Download tiled image',
|
||||||
|
on_click: onDownloadTiledImage,
|
||||||
|
filter: (req, img) => req.tiling != "none",
|
||||||
|
})
|
||||||
|
|
||||||
|
var thisImage
|
||||||
|
|
||||||
|
function onDownloadTiledImage(req, img) {
|
||||||
|
document.getElementById("download-tiled-image-dialog").showModal()
|
||||||
|
thisImage = new Image()
|
||||||
|
thisImage.src = img.src
|
||||||
|
thisImage.dataset["prompt"] = img.dataset["prompt"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Add HTML
|
||||||
|
document.getElementById('container').lastElementChild.insertAdjacentHTML("afterend",
|
||||||
|
`<dialog id="download-tiled-image-dialog">
|
||||||
|
<h1>Download tiled image</h1>
|
||||||
|
<div class="download-tiled-image dtim-container">
|
||||||
|
<div class="download-tiled-image-top">
|
||||||
|
<div class="tab-container">
|
||||||
|
<span id="tab-image-tiles" class="tab active">
|
||||||
|
<span>Number of tiles</small></span>
|
||||||
|
</span>
|
||||||
|
<span id="tab-image-size" class="tab">
|
||||||
|
<span>Image dimensions</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div id="tab-content-image-tiles" class="tab-content active">
|
||||||
|
<div class="tab-content-inner">
|
||||||
|
<label for="dtim1-width">Width:</label> <input id="dtim1-width" min="1" max="99" type="number" value="2">
|
||||||
|
<label for="dtim1-height">Height:</label> <input id="dtim1-height" min="1" max="99" type="number" value="2">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="tab-content-image-size" class="tab-content">
|
||||||
|
<div class="tab-content-inner">
|
||||||
|
<div class="method-2-options">
|
||||||
|
<label for="dtim2-width">Width:</label> <input id="dtim2-width" size="3" value="1920">
|
||||||
|
<label for="dtim2-height">Height:</label> <input id="dtim2-height" size="3" value="1080">
|
||||||
|
<select id="dtim2-unit">
|
||||||
|
<option>pixels</option>
|
||||||
|
<option>mm</option>
|
||||||
|
<option>inches</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="method-2-dpi">
|
||||||
|
<label for="dtim2-dpi">DPI:</label> <input id="dtim2-dpi" size="3" value="72">
|
||||||
|
</div>
|
||||||
|
<div class="method-2-paper">
|
||||||
|
<i>Some standard sizes:</i><br>
|
||||||
|
<button id="dtim2-a3p">A3 portrait</button><button id="dtim2-a3l">A3 landscape</button><br>
|
||||||
|
<button id="dtim2-a4p">A4 portrait</button><button id="dtim2-a4l">A4 landscape</button><br>
|
||||||
|
<button id="dtim2-lp">Letter portrait</button><button id="dtim2-ll">Letter landscape</button><br>
|
||||||
|
<button id="dtim2-hd">Full HD</button><button id="dtim2-4k">4K</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="download-tiled-image-placement">
|
||||||
|
<div class="tab-container">
|
||||||
|
<span id="tab-image-placement" class="tab active">
|
||||||
|
<span>Tile placement</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div id="tab-content-image-placement" class="tab-content active">
|
||||||
|
<div class="tab-content-inner">
|
||||||
|
<img id="dtim-1tl" class="active" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA3BAMAAACiFTSCAAAAMFBMVEUCAgKIhobRz89vMJ7s6uo9PDx4d3ewra0bHR1dXV19NrLa2Nj+/f29u7uWlJQuLi7ws27qAAAACXBIWXMAAAsTAAALEwEAmpwYAAABlUlEQVQ4y7VUMU7DQBCckpYCJEpS0ByhcecuUZQUtvIHGku0vICSDtHkA9eltCylOEBKFInCRworXToK3kDJ7jpn2SYmgGESeWyPRuudvTugHTyC72momKDGMMJDLIhmgK+nWmuPXxtlxkhjExszRKqU6uRuTW7TYTwh6HTpR25+JLcngBJ5jL5wIecqu9nFbid3t27N7vhrtypqV2SfP4zc5pfu/Msb3P6U4fru1eXpVg7tcmnDZ1gb0s1ceAEcSPI3uM2B9xLf7Z3YLlfJ/WCppF1QbbqxeW0brlztjXzprBhJrW8nu4HWGlt/xz1qcrervfmT2ma3WxpTjfK5ZUioNg+VsUL+tiXuI8YJLrd8KHyENyaqPWC8QGiwwlJ4LtyvNtb9vFKrqZXXeebkrEiN3ZUNXHJnO3aJkxt2aH2gDRNTLdyzJvee1CZXUTSJrhA55itlfszUdqDrxCQmGIEu9KfFFCRJYnpIgyB4JJlPWM6cY6MjN+UW5MjdM7FKavF/pFbfRD9zv8rjBa6FT5EJn0HoA8lOiD4+8B3mAAAAAElFTkSuQmCC" />
|
||||||
|
<img id="dtim-1tr" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA3BAMAAACiFTSCAAAAMFBMVEUCAgKIhobRz89vMJ7s6uo9PDx4d3ewra0bHR1dXV19NrLa2Nj+/f29u7uWlJQuLi7ws27qAAAACXBIWXMAAAsTAAALEwEAmpwYAAABoUlEQVQ4y61UsU7CUBQ9o6uGmJgwNSQOLS7dOndrGfwEDWnC4tQNB8duxoUfYGN86fZgIWy+iVUnwwYf4Oi9lxa0tFSpB9IDXM6775773gUaYWjbtoO+IrI1VsIKnjt2CYCllJqir7Wt7SlWWmn+m+t53sQbU5hAamtJrxRr/mppUnuZOgszOlgJK7gCUS93YVbzKqx2q9U2q71Mbf1Qbxc/qqadu7y509W7nX8Pt/K6JwwKO+HCGLRNKPy4oA9mkYUnwGeSJM9IBDknOJN+PNV2rEy9XyXLvaGcktuY0FBux9AP5rVYd96SofCsWFje0NJwUd2rUse/UTfLPTspd83iFFZZYY4xbKoRsKlmaypjjoaICA+4ZYrO8SJ8mfEV0PF9P0Tb94U3wj7eheaHJ3VZLKxbcs4P6uartz/nMYlKbFnzYtWe5ze0wtSjDd1Ph7iReheucS0aRYM78pwoiiDPUc6Dpg19S9N0ipYOgiClw5TqgN6I6aGD7S2RkcsbppnKbLPnPHt7VZOpxvN/cq1cHf9BbeFeqIsL4Wt8CN/gC1XPfwv6U6jJAAAAAElFTkSuQmCC" /><br>
|
||||||
|
<img id="dtim-1bl" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA3BAMAAACiFTSCAAAAMFBMVEUCAgKIhobRz89vMJ7s6uo9PDx4d3ewra0bHR1dXV19NrLa2Nj+/f29u7uWlJQuLi7ws27qAAAACXBIWXMAAAsTAAALEwEAmpwYAAABjElEQVQ4y7WUsU7DMBCG/5GVoUiMMLC4ZcmWrVXVDq7yDiyRuvIEjGyIpS/graMVKYMBqVUkhoYOUTc2Bp6BEd+5qdI2SasGLpE/KZc/d76LD/i6JrvFPfMKGfMGDOCTGUMwA/SYA8yL7iEM8w2yzH1AHderh9D1alGuXmmtBaVGchFgQe8J69bOHZnIyCHsYu8AUkZRZLpYSClf0dAm4zCchGOEOWkNW7ggAO0+2QcY/SUS5ozZ+6uqNVHHR9Q8q1Bnm9+B1B17HdGxbDe1zn7sA1V7DskucbfmObOFb0LThrZTsjlGzHcw0iXcU6woQxFv9i3rah5UdSxvSa/+EMn6hp6iroy9+s/YL2mSjlxRE1fUkX2wZNqiPjrDTwmfDnbsjNeH0q9Y9ZRN2diJjeliJ+ksj+2v3W5j3d2N+R5b4T/fcjuvqppMvqfsdbqaxF7VCc3Vho9eUd0pZi6q1cpThemwdYB9NVVK2cy1NsLYmaqNNmZgZ6sQa7VPmWuavQG9ZkkjV+u42QH8BWe+iD71TSARAAAAAElFTkSuQmCC" />
|
||||||
|
<img id="dtim-1br" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA3BAMAAACiFTSCAAAAMFBMVEUCAgKIhobRz89vMJ7s6uo9PDx4d3ewra0bHR1dXV19NrLa2Nj+/f29u7uWlJQuLi7ws27qAAAACXBIWXMAAAsTAAALEwEAmpwYAAABkklEQVQ4y7VULU/DUBQ9EgtZSEimliWIt2Lmnq5rJ/gJkKXJDGquCGQdwewPzE2+PPeGWeaomgVF6tgPmOTe2zWkox8LC6dLT/ZuTs9957UXPQbuhTxcCF/jU/gGYBpgLH/7yIQNYuHXctniS9hhWlU+Wh03qVX1wwt1+eGKyoZXl8iYFbdmlFIj4N1au0THBUFgLTLrAvphSjcXUPk0RLNocodbpiiC3GcFT4C+7/shur4vvBX28SG0+o/UTHNqrZnXe3uVrW3oKtScuVeUvZYTK3lvyq21pBYRHihzxjlehC/3fHXqgQ5SArapAI9C63w1XR3GUuw75neuN6otV++78SOyza9Dv/lAj1Yf5T061XsQrjnUdSpMoYZ5qLSQvgG7JEmekQgOOWk9sV2l6kxqT4V3Nw1zb7IMyVsvBIcb6+w3lpfn1V+Jw1Awr5tMOq/XqzVdf1Mr9tZ7701JzZ+ia1ab352z6mc6cGO52hiapWPnlFM0U51ximbqUGu90KSOabTyyCWi5UyYO5/n6pPwDYr8fwvXgN7jAAAAAElFTkSuQmCC" /> <br>
|
||||||
|
<img id="dtim-1center" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA3BAMAAACiFTSCAAAAMFBMVEUBAQGPjY3Rz89DQ0O0sbHz8vJZJoFwbm6+vLxBHV10MqY6ODifnZ1XV1cdHR3c2trZIbFLAAAACXBIWXMAAAsTAAALEwEAmpwYAAACCElEQVQ4y7VVPWvjQBCVnZXt5JRT1LsQwwnS7YHrgLg6hTBsva4MSeUurX5CqqtTuXCVn6CAf0DgimvvJ4iFredmd2VZcqTYIWSap2V4+/HezMgDSAdgIw0cFhVeMQAPIAuUWfF44jAdOix8k8YsmCNXyEuGynzkQ4u68BE8LbKJsJGFDkvfYe6Lufe5ePi7unywUePY4Suhl4iMCaGlFOWQQGiRhw5Tc3b9MIiZe1Deehhkg3nXu5MirGW5NmnmkNjX9EFs1VKN7djgNg+bovae3a15cpg+ZIfquGP97J2h0viJ5cT6SoZaX+lspYyoX2doFBXjlyiaRtHV+XL5++5u+TiITExXQRR5XGeBQIkoyouNjadQSqm1Tn2pmg8bbe5NelFb0nQMKL25XxO7tsSoxmu/q80XbdXK/eZrs/2iR/OR4a53m1eO8ayPfWDJqHU2VuwywNbVnt6czflbttucVGOkmUbdUI2WSG0g0ZvepuNbiu22IM1NPAZ2uV2x7csnDf3FywFdhQPmttYUT6kkubv5D4+bWlOoFNWa5BRJHiJNDzTDQzUd21fqoaHdPaaO1/kp/d1mwwkdunfsIx2K7Q6lapmDIrVihqAsG41qiZ0tbq7ZFhw6jKsWtHPtz+z128zGT4c3z2cVXs5ujjn2773k9472j5vtf/pkYp2TKe/7E00A/gO7G7pwJRGqtAAAAABJRU5ErkJggg==" />
|
||||||
|
<img id="dtim-4center" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA3BAMAAACiFTSCAAAAMFBMVEUBAQGbmppqLZZ8fHzRz8+LPMZ0MqXs6upTUVE+G1q5ublubm6iRedQInH9/Pze3NzAiv2WAAAACXBIWXMAAAsTAAALEwEAmpwYAAABuUlEQVQ4y6VVvU7CUBSmCEVQao0vQDrcWWcWhiYkDsICc3OS3pmhSbfiI7C6MfgAJo4sPoCDcSdhMGFDBhI24zn3tBjh2DTy3eEj9+P0/Pa05BtMrZQbzG7KJaZFIyLqrS82hqfOnszXnUquLFv3dvLOeiP57uT69teFfHcP5CKJ+QdyN0YsF5Ul8WpUI06SjmM4Ks0Mrk+Zn86Y70+YS8fha0VY2K8GL1XmwDHXnxj54y1GXgbwwNOBrT2lPNWiyFHIEitrhYdkDaB1ay/vsjY6yiiCJJMVykq0pkt+OPoQH44gGX8IskqtFYjWgODQQAwt8y1aAygPdN8GCkHt5LSoaTH75ylnRT0ON5cEtz4nvL81Dc8nlrm+wmEax9t4YQ/0MNRhn1iHYcuJt+PxOMoib5p8uGpySzAfUxbQKqcsSov9VmlRqSPyOHBR6Q9Sx9haKci3lvsNPGtyv8Hogc3c+nkFl3iwasNBOBz0q8yBk8RJvMRXsE3HrT8YTDK2Zs942kc29I6npbZi5ilZjZg/DpaHL++WqNDiypfzt+LfO3VTaO39c6dmsp9nPZJ9Z18i19r8+hJ9A3EAErhB3eXkAAAAAElFTkSuQmCC" /> <br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="dtim-ok">
|
||||||
|
<button class="primaryButton" id="dti-ok">Download</button>
|
||||||
|
</div>
|
||||||
|
<div class="dtim-newtab">
|
||||||
|
<button class="primaryButton" id="dti-newtab">Open in new tab</button>
|
||||||
|
</div>
|
||||||
|
<div class="dtim-cancel">
|
||||||
|
<button class="primaryButton" id="dti-cancel">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</dialog>`)
|
||||||
|
|
||||||
|
let downloadTiledImageDialog = document.getElementById("download-tiled-image-dialog")
|
||||||
|
let dtim1_width = document.getElementById("dtim1-width")
|
||||||
|
let dtim1_height = document.getElementById("dtim1-height")
|
||||||
|
let dtim2_width = document.getElementById("dtim2-width")
|
||||||
|
let dtim2_height = document.getElementById("dtim2-height")
|
||||||
|
let dtim2_unit = document.getElementById("dtim2-unit")
|
||||||
|
let dtim2_dpi = document.getElementById("dtim2-dpi")
|
||||||
|
let tabTiledTilesOptions = document.getElementById("tab-image-tiles")
|
||||||
|
let tabTiledSizeOptions = document.getElementById("tab-image-size")
|
||||||
|
|
||||||
|
linkTabContents(tabTiledTilesOptions)
|
||||||
|
linkTabContents(tabTiledSizeOptions)
|
||||||
|
|
||||||
|
prettifyInputs(downloadTiledImageDialog)
|
||||||
|
|
||||||
|
// ---- Predefined image dimensions
|
||||||
|
PAPERSIZE.forEach( function(p) {
|
||||||
|
document.getElementById("dtim2-" + p.id).addEventListener("click", (e) => {
|
||||||
|
dtim2_unit.value = p.unit
|
||||||
|
dtim2_width.value = p.width
|
||||||
|
dtim2_height.value = p.height
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// ---- Close popup
|
||||||
|
document.getElementById("dti-cancel").addEventListener("click", (e) => downloadTiledImageDialog.close())
|
||||||
|
downloadTiledImageDialog.addEventListener('click', function (event) {
|
||||||
|
var rect = downloadTiledImageDialog.getBoundingClientRect();
|
||||||
|
var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height
|
||||||
|
&& rect.left <= event.clientX && event.clientX <= rect.left + rect.width);
|
||||||
|
if (!isInDialog) {
|
||||||
|
downloadTiledImageDialog.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---- Stylesheet
|
||||||
|
const styleSheet = document.createElement("style")
|
||||||
|
styleSheet.textContent = `
|
||||||
|
dialog {
|
||||||
|
background: var(--background-color2);
|
||||||
|
color: var(--text-color);
|
||||||
|
border-radius: 7px;
|
||||||
|
border: 1px solid var(--background-color3);
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog::backdrop {
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
button[disabled] {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.method-2-dpi {
|
||||||
|
margin-top: 1em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.method-2-paper button {
|
||||||
|
width: 10em;
|
||||||
|
padding: 4px;
|
||||||
|
margin: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.download-tiled-image .tab-content {
|
||||||
|
background: var(--background-color1);
|
||||||
|
border-radius: 3pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dtim-container { display: grid;
|
||||||
|
grid-template-columns: auto auto;
|
||||||
|
grid-template-rows: auto auto;
|
||||||
|
gap: 1em 0px;
|
||||||
|
grid-auto-flow: row;
|
||||||
|
grid-template-areas:
|
||||||
|
"dtim-tab dtim-tab dtim-plc"
|
||||||
|
"dtim-ok dtim-newtab dtim-cancel";
|
||||||
|
}
|
||||||
|
|
||||||
|
.download-tiled-image-top {
|
||||||
|
justify-self: center;
|
||||||
|
grid-area: dtim-tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
.download-tiled-image-placement {
|
||||||
|
justify-self: center;
|
||||||
|
grid-area: dtim-plc;
|
||||||
|
margin-left: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dtim-ok {
|
||||||
|
justify-self: center;
|
||||||
|
align-self: start;
|
||||||
|
grid-area: dtim-ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dtim-newtab {
|
||||||
|
justify-self: center;
|
||||||
|
align-self: start;
|
||||||
|
grid-area: dtim-newtab;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dtim-cancel {
|
||||||
|
justify-self: center;
|
||||||
|
align-self: start;
|
||||||
|
grid-area: dtim-cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tab-content-image-placement img {
|
||||||
|
margin: 4px;
|
||||||
|
opacity: 0.3;
|
||||||
|
border: solid 2px var(--background-color1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#tab-content-image-placement img:hover {
|
||||||
|
margin: 4px;
|
||||||
|
opacity: 1;
|
||||||
|
border: solid 2px var(--accent-color);
|
||||||
|
filter: brightness(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#tab-content-image-placement img.active {
|
||||||
|
margin: 4px;
|
||||||
|
opacity: 1;
|
||||||
|
border: solid 2px var(--background-color1);
|
||||||
|
}
|
||||||
|
|
||||||
|
`
|
||||||
|
document.head.appendChild(styleSheet)
|
||||||
|
|
||||||
|
// ---- Placement widget
|
||||||
|
|
||||||
|
function updatePlacementWidget(event) {
|
||||||
|
document.querySelector("#tab-content-image-placement img.active").classList.remove("active")
|
||||||
|
event.target.classList.add("active")
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll("#tab-content-image-placement img").forEach(
|
||||||
|
(i) => i.addEventListener("click", updatePlacementWidget)
|
||||||
|
)
|
||||||
|
|
||||||
|
function getPlacement() {
|
||||||
|
return document.querySelector("#tab-content-image-placement img.active").id.substr(5)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Make the image
|
||||||
|
function downloadTiledImage(image, width, height, offsetX=0, offsetY=0, new_tab=false) {
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
canvas.width = width
|
||||||
|
canvas.height = height
|
||||||
|
const context = canvas.getContext('2d')
|
||||||
|
|
||||||
|
const w = image.width
|
||||||
|
const h = image.height
|
||||||
|
|
||||||
|
for (var x = offsetX; x < width; x += w) {
|
||||||
|
for (var y = offsetY; y < height; y += h) {
|
||||||
|
context.drawImage(image, x, y, w, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (new_tab) {
|
||||||
|
var newTab = window.open("")
|
||||||
|
newTab.document.write(`<html><head><title>${width}×${height}, "${image.dataset["prompt"]}"</title></head><body><img src="${canvas.toDataURL()}"></body></html>`)
|
||||||
|
} else {
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = canvas.toDataURL()
|
||||||
|
link.download = image.dataset["prompt"].replace(/[^a-zA-Z0-9]+/g, "-").substr(0,22)+crypto.randomUUID()+".png"
|
||||||
|
link.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDownloadTiledImageClick(e, newtab=false) {
|
||||||
|
var width, height, offsetX, offsetY
|
||||||
|
|
||||||
|
if (isTabActive(tabTiledTilesOptions)) {
|
||||||
|
width = thisImage.width * dtim1_width.value
|
||||||
|
height = thisImage.height * dtim1_height.value
|
||||||
|
} else {
|
||||||
|
if ( dtim2_unit.value == "pixels" ) {
|
||||||
|
width = dtim2_width.value
|
||||||
|
height= dtim2_height.value
|
||||||
|
} else if ( dtim2_unit.value == "mm" ) {
|
||||||
|
width = Math.floor( dtim2_width.value * dtim2_dpi.value / 25.4 )
|
||||||
|
height = Math.floor( dtim2_height.value * dtim2_dpi.value / 25.4 )
|
||||||
|
} else { // inch
|
||||||
|
width = Math.floor( dtim2_width.value * dtim2_dpi.value )
|
||||||
|
height = Math.floor( dtim2_height.value * dtim2_dpi.value )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var placement = getPlacement()
|
||||||
|
if (placement == "1tl") {
|
||||||
|
offsetX = 0
|
||||||
|
offsetY = 0
|
||||||
|
} else if (placement == "1tr") {
|
||||||
|
offsetX = width - thisImage.width * Math.ceil( width / thisImage.width )
|
||||||
|
offsetY = 0
|
||||||
|
} else if (placement == "1bl") {
|
||||||
|
offsetX = 0
|
||||||
|
offsetY = height - thisImage.height * Math.ceil( height / thisImage.height )
|
||||||
|
} else if (placement == "1br") {
|
||||||
|
offsetX = width - thisImage.width * Math.ceil( width / thisImage.width )
|
||||||
|
offsetY = height - thisImage.height * Math.ceil( height / thisImage.height )
|
||||||
|
} else if (placement == "4center") {
|
||||||
|
offsetX = width/2 - thisImage.width * Math.ceil( width/2 / thisImage.width )
|
||||||
|
offsetY = height/2 - thisImage.height * Math.ceil( height/2 / thisImage.height )
|
||||||
|
} else if (placement == "1center") {
|
||||||
|
offsetX = width/2 - thisImage.width/2 - thisImage.width * Math.ceil( (width/2 - thisImage.width/2) / thisImage.width )
|
||||||
|
offsetY = height/2 - thisImage.height/2 - thisImage.height * Math.ceil( (height/2 - thisImage.height/2) / thisImage.height )
|
||||||
|
}
|
||||||
|
downloadTiledImage(thisImage, width, height, offsetX, offsetY, newtab)
|
||||||
|
downloadTiledImageDialog.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("dti-ok").addEventListener("click", onDownloadTiledImageClick)
|
||||||
|
document.getElementById("dti-newtab").addEventListener("click", (e) => onDownloadTiledImageClick(e,true))
|
||||||
|
|
||||||
|
})()
|
Loading…
Reference in New Issue
Block a user