Unverified Commit ae0fdad6 authored by MalumaDev's avatar MalumaDev Committed by GitHub
Browse files

Merge branch 'master' into test_resolve_conflicts

parents 9324cdaa c57919ea
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -73,8 +73,10 @@ function check_gallery(id_gallery){
            let galleryBtnSelected = gradioApp().querySelector('#'+id_gallery+' .gallery-item.\\!ring-2')
            if (prevSelectedIndex !== -1 && galleryButtons.length>prevSelectedIndex && !galleryBtnSelected) {
                //automatically re-open previously selected index (if exists)
                activeElement = document.activeElement;
                galleryButtons[prevSelectedIndex].click();
                showGalleryImage();
                if(activeElement) activeElement.focus()
            }
        })
        galleryObservers[id_gallery].observe( gallery, { childList:true, subtree:false })
+16 −7
Original line number Diff line number Diff line
@@ -94,6 +94,15 @@ def prepare_enviroment():

    gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379")
    clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1")
    deepdanbooru_package = os.environ.get('DEEPDANBOORU_PACKAGE', "git+https://github.com/KichangKim/DeepDanbooru.git@edf73df4cdaeea2cf00e9ac08bd8a9026b7a7b26")

    xformers_windows_package = os.environ.get('XFORMERS_WINDOWS_PACKAGE', 'https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl')

    stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/CompVis/stable-diffusion.git")
    taming_transformers_repo = os.environ.get('TAMING_REANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git")
    k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://github.com/crowsonkb/k-diffusion.git')
    codeformer_repo = os.environ.get('CODEFORMET_REPO', 'https://github.com/sczhou/CodeFormer.git')
    blip_repo = os.environ.get('BLIP_REPO', 'https://github.com/salesforce/BLIP.git')

    stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc")
    taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6")
@@ -131,23 +140,23 @@ def prepare_enviroment():

    if (not is_installed("xformers") or reinstall_xformers) and xformers and platform.python_version().startswith("3.10"):
        if platform.system() == "Windows":
            run_pip("install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl", "xformers")
            run_pip(f"install -U -I --no-deps {xformers_windows_package}", "xformers")
        elif platform.system() == "Linux":
            run_pip("install xformers", "xformers")

    if not is_installed("deepdanbooru") and deepdanbooru:
        run_pip("install git+https://github.com/KichangKim/DeepDanbooru.git@edf73df4cdaeea2cf00e9ac08bd8a9026b7a7b26#egg=deepdanbooru[tensorflow] tensorflow==2.10.0 tensorflow-io==0.27.0", "deepdanbooru")
        run_pip(f"install {deepdanbooru_package}#egg=deepdanbooru[tensorflow] tensorflow==2.10.0 tensorflow-io==0.27.0", "deepdanbooru")

    if not is_installed("pyngrok") and ngrok:
        run_pip("install pyngrok", "ngrok")

    os.makedirs(dir_repos, exist_ok=True)

    git_clone("https://github.com/CompVis/stable-diffusion.git", repo_dir('stable-diffusion'), "Stable Diffusion", stable_diffusion_commit_hash)
    git_clone("https://github.com/CompVis/taming-transformers.git", repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
    git_clone("https://github.com/crowsonkb/k-diffusion.git", repo_dir('k-diffusion'), "K-diffusion", k_diffusion_commit_hash)
    git_clone("https://github.com/sczhou/CodeFormer.git", repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash)
    git_clone("https://github.com/salesforce/BLIP.git", repo_dir('BLIP'), "BLIP", blip_commit_hash)
    git_clone(stable_diffusion_repo, repo_dir('stable-diffusion'), "Stable Diffusion", stable_diffusion_commit_hash)
    git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
    git_clone(k_diffusion_repo, repo_dir('k-diffusion'), "K-diffusion", k_diffusion_commit_hash)
    git_clone(codeformer_repo, repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash)
    git_clone(blip_repo, repo_dir('BLIP'), "BLIP", blip_commit_hash)

    if not is_installed("lpips"):
        run_pip(f"install -r {os.path.join(repo_dir('CodeFormer'), 'requirements.txt')}", "requirements for CodeFormer")
+20 −5
Original line number Diff line number Diff line
@@ -20,12 +20,13 @@ import gradio as gr
cached_images = {}


def run_extras(extras_mode, resize_mode, image, image_folder, gfpgan_visibility, codeformer_visibility, codeformer_weight, upscaling_resize, upscaling_resize_w, upscaling_resize_h, upscaling_crop, extras_upscaler_1, extras_upscaler_2, extras_upscaler_2_visibility):
def run_extras(extras_mode, resize_mode, image, image_folder, input_dir, output_dir, show_extras_results, gfpgan_visibility, codeformer_visibility, codeformer_weight, upscaling_resize, upscaling_resize_w, upscaling_resize_h, upscaling_crop, extras_upscaler_1, extras_upscaler_2, extras_upscaler_2_visibility):
    devices.torch_gc()

    imageArr = []
    # Also keep track of original file names
    imageNameArr = []
    outputs = []
    
    if extras_mode == 1:
        #convert file to pillow image
@@ -33,13 +34,26 @@ def run_extras(extras_mode, resize_mode, image, image_folder, gfpgan_visibility,
            image = Image.open(img)
            imageArr.append(image)
            imageNameArr.append(os.path.splitext(img.orig_name)[0])
    elif extras_mode == 2:
        assert not shared.cmd_opts.hide_ui_dir_config, '--hide-ui-dir-config option must be disabled'

        if input_dir == '':
            return outputs, "Please select an input directory.", ''
        image_list = [file for file in [os.path.join(input_dir, x) for x in os.listdir(input_dir)] if os.path.isfile(file)]
        for img in image_list:
            image = Image.open(img)
            imageArr.append(image)
            imageNameArr.append(img)
    else:
        imageArr.append(image)
        imageNameArr.append(None)

    if extras_mode == 2 and output_dir != '':
        outpath = output_dir
    else:
        outpath = opts.outdir_samples or opts.outdir_extras_samples

    outputs = []
    
    for image, image_name in zip(imageArr, imageNameArr):
        if image is None:
            return outputs, "Please select an input image.", ''
@@ -112,6 +126,7 @@ def run_extras(extras_mode, resize_mode, image, image_folder, gfpgan_visibility,
            image.info = existing_pnginfo
            image.info["extras"] = info

        if extras_mode != 2 or show_extras_results :
            outputs.append(image)

    devices.torch_gc()
+10 −8
Original line number Diff line number Diff line
import os
import shutil

import sys

def traverse_all_files(output_dir, image_list, curr_dir=None):
    curr_path = output_dir if curr_dir is None else os.path.join(output_dir, curr_dir)
@@ -24,10 +24,14 @@ def traverse_all_files(output_dir, image_list, curr_dir=None):

def get_recent_images(dir_name, page_index, step, image_index, tabname):
    page_index = int(page_index)
    f_list = os.listdir(dir_name)
    image_list = []
    if not os.path.exists(dir_name):
        pass
    elif os.path.isdir(dir_name):
        image_list = traverse_all_files(dir_name, image_list)
        image_list = sorted(image_list, key=lambda file: -os.path.getctime(os.path.join(dir_name, file)))
    else:
        print(f'ERROR: "{dir_name}" is not a directory. Check the path in the settings.', file=sys.stderr)
    num = 48 if tabname != "extras" else 12
    max_page_index = len(image_list) // num + 1
    page_index = max_page_index if page_index == -1 else page_index + step
@@ -105,10 +109,8 @@ def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
        dir_name = opts.outdir_img2img_samples
    elif tabname == "extras":
        dir_name = opts.outdir_extras_samples
    d = dir_name.split("/")
    dir_name = "/" if dir_name.startswith("/") else d[0]
    for p in d[1:]:
        dir_name = os.path.join(dir_name, p)
    else:
        return
    with gr.Row():
        renew_page = gr.Button('Renew Page', elem_id=tabname + "_images_history_renew_page")
        first_page = gr.Button('First Page')
+5 −3
Original line number Diff line number Diff line
from pyngrok import ngrok, conf, exception


def connect(token, port):
def connect(token, port, region):
    if token == None:
        token = 'None'
    conf.get_default().auth_token = token
    config = conf.PyngrokConfig(
        auth_token=token, region=region
    )
    try:
        public_url = ngrok.connect(port).public_url
        public_url = ngrok.connect(port, pyngrok_config=config).public_url
    except exception.PyngrokNgrokError:
        print(f'Invalid ngrok authtoken, ngrok connection aborted.\n'
              f'Your token: {token}, get the right one on https://dashboard.ngrok.com/get-started/your-authtoken')
Loading