Compare commits
No commits in common. "main" and "v0.7.0" have entirely different histories.
16
API.md
16
API.md
@ -83,19 +83,3 @@ A list of available models can be seen by GET:
|
||||
* http://127.0.0.1:7860/reactor/models
|
||||
* http://127.0.0.1:7860/reactor/upscalers
|
||||
* http://127.0.0.1:7860/reactor/facemodels
|
||||
|
||||
### FaceModel Buid API
|
||||
|
||||
Send POST to http://127.0.0.1:7860/reactor/facemodels with body:
|
||||
|
||||
```
|
||||
{
|
||||
"source_images": ["data:image/png;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/7g...","data:image/png;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/7g...","data:image/png;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/7g..."],
|
||||
"name": "my_super_model",
|
||||
"compute_method": 0
|
||||
}
|
||||
```
|
||||
|
||||
where:<br>
|
||||
"source_images" is a list of base64 encoded images,<br>
|
||||
"compute_method" is: 0 - Mean, 1- Median, 2 - Mode
|
||||
|
||||
11
README.md
11
README.md
@ -2,7 +2,7 @@
|
||||
|
||||
<img src="https://github.com/Gourieff/Assets/raw/main/sd-webui-reactor/ReActor_logo_NEW_EN.png?raw=true" alt="logo" width="180px"/>
|
||||
|
||||

|
||||

|
||||
|
||||
<a href="https://boosty.to/artgourieff" target="_blank">
|
||||
<img src="https://lovemet.ru/www/boosty.jpg" width="108" alt="Support Me on Boosty"/>
|
||||
@ -40,15 +40,8 @@
|
||||
|
||||
## What's new in the latest updates
|
||||
|
||||
### 0.7.1 <sub><sup>BETA1
|
||||
|
||||
- Allow spaces for face indexes (e.g.: 0, 1, 2)
|
||||
- Sorting of face models list alphabetically
|
||||
- [FaceModels Build API](./API.md#facemodel-build-api)
|
||||
- Fixes and improvements
|
||||
|
||||
<details>
|
||||
<summary><a>Click to expand more</a></summary>
|
||||
<summary><a>Click to expand</a></summary>
|
||||
|
||||
### 0.7.0 <sub><sup>BETA2
|
||||
|
||||
|
||||
11
README_RU.md
11
README_RU.md
@ -2,7 +2,7 @@
|
||||
|
||||
<img src="https://github.com/Gourieff/Assets/raw/main/sd-webui-reactor/ReActor_logo_NEW_RU.png?raw=true" alt="logo" width="180px"/>
|
||||
|
||||

|
||||

|
||||
|
||||
<a href="https://boosty.to/artgourieff" target="_blank">
|
||||
<img src="https://lovemet.ru/www/boosty.jpg" width="108" alt="Поддержать проект на Boosty"/>
|
||||
@ -39,15 +39,8 @@
|
||||
|
||||
## Что нового в последних обновлениях
|
||||
|
||||
### 0.7.1 <sub><sup>BETA1
|
||||
|
||||
- Использование пробелов в индексах лиц (пример: 0, 1, 2)
|
||||
- Список моделей лиц теперь отсортирован по алфавиту
|
||||
- [API для создания моделей лиц](./API.md#facemodel-build-api)
|
||||
- Правки и улучшения
|
||||
|
||||
<details>
|
||||
<summary><a>Нажмите, чтобы посмотреть больше</a></summary>
|
||||
<summary><a>Нажмите, чтобы посмотреть</a></summary>
|
||||
|
||||
### 0.7.0 <sub><sup>BETA2
|
||||
|
||||
|
||||
27
install.py
27
install.py
@ -21,6 +21,20 @@ req_file = os.path.join(BASE_PATH, "requirements.txt")
|
||||
|
||||
models_dir = os.path.join(models_path, "insightface")
|
||||
|
||||
# DEPRECATED:
|
||||
# models_dir_old = os.path.join(models_path, "roop")
|
||||
# if os.path.exists(models_dir_old):
|
||||
# if not os.listdir(models_dir_old) and (not os.listdir(models_dir) or not os.path.exists(models_dir)):
|
||||
# os.rename(models_dir_old, models_dir)
|
||||
# else:
|
||||
# import shutil
|
||||
# for file in os.listdir(models_dir_old):
|
||||
# shutil.move(os.path.join(models_dir_old, file), os.path.join(models_dir, file))
|
||||
# try:
|
||||
# os.rmdir(models_dir_old)
|
||||
# except Exception as e:
|
||||
# print(f"OSError: {e}")
|
||||
|
||||
model_url = "https://huggingface.co/datasets/Gourieff/ReActor/resolve/main/models/inswapper_128.onnx"
|
||||
model_name = os.path.basename(model_url)
|
||||
model_path = os.path.join(models_dir, model_name)
|
||||
@ -103,17 +117,12 @@ with open(req_file) as file:
|
||||
last_device = "CPU"
|
||||
with open(os.path.join(BASE_PATH, "last_device.txt"), "w") as txt:
|
||||
txt.write(last_device)
|
||||
if cuda_version is not None:
|
||||
if float(cuda_version)>=12: # CU12.x
|
||||
extra_index_url = "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/"
|
||||
else: # CU11.8
|
||||
extra_index_url = "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-11/pypi/simple"
|
||||
if not is_installed(ort,"1.17.1",True):
|
||||
if cuda_version is not None and float(cuda_version)>=12: # CU12
|
||||
if not is_installed(ort,"1.17.1",False):
|
||||
install_count += 1
|
||||
ort = "onnxruntime-gpu==1.17.1"
|
||||
pip_uninstall("onnxruntime", "onnxruntime-gpu")
|
||||
pip_install(ort,"--extra-index-url",extra_index_url)
|
||||
elif not is_installed(ort,"1.18.1",False):
|
||||
pip_install(ort,"--extra-index-url","https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/")
|
||||
elif not is_installed(ort,"1.16.1",False):
|
||||
install_count += 1
|
||||
pip_install(ort, "-U")
|
||||
except Exception as e:
|
||||
|
||||
@ -11,14 +11,9 @@ from modules import shared
|
||||
# SAVE_ORIGINAL: bool = False
|
||||
|
||||
def update_fm_list(selected: str):
|
||||
try: # GR3.x
|
||||
return gr.Dropdown.update(
|
||||
value=selected, choices=get_model_names(get_facemodels)
|
||||
)
|
||||
except: # GR4.x
|
||||
return gr.Dropdown(
|
||||
value=selected, choices=get_model_names(get_facemodels)
|
||||
)
|
||||
return gr.Dropdown.update(
|
||||
value=selected, choices=get_model_names(get_facemodels)
|
||||
)
|
||||
|
||||
# TAB MAIN
|
||||
def show(is_img2img: bool, show_br: bool = True, **msgs):
|
||||
@ -29,56 +24,29 @@ def show(is_img2img: bool, show_br: bool = True, **msgs):
|
||||
if evt.index == 2:
|
||||
# if SAVE_ORIGINAL != selected:
|
||||
# SAVE_ORIGINAL = selected
|
||||
try: # GR3.x
|
||||
return {
|
||||
control_col_1: gr.Column.update(visible=False),
|
||||
control_col_2: gr.Column.update(visible=False),
|
||||
control_col_3: gr.Column.update(visible=True),
|
||||
# save_original: gr.Checkbox.update(value=False,visible=False),
|
||||
imgs_hash_clear: gr.Button.update(visible=True)
|
||||
}
|
||||
except: # GR4.x
|
||||
return {
|
||||
control_col_1: gr.Column(visible=False),
|
||||
control_col_2: gr.Column(visible=False),
|
||||
control_col_3: gr.Column(visible=True),
|
||||
# save_original: gr.Checkbox.update(value=False,visible=False),
|
||||
imgs_hash_clear: gr.Button(visible=True)
|
||||
}
|
||||
return {
|
||||
control_col_1: gr.Column.update(visible=False),
|
||||
control_col_2: gr.Column.update(visible=False),
|
||||
control_col_3: gr.Column.update(visible=True),
|
||||
# save_original: gr.Checkbox.update(value=False,visible=False),
|
||||
imgs_hash_clear: gr.Button.update(visible=True)
|
||||
}
|
||||
if evt.index == 0:
|
||||
try: # GR3.x
|
||||
return {
|
||||
control_col_1: gr.Column.update(visible=True),
|
||||
control_col_2: gr.Column.update(visible=False),
|
||||
control_col_3: gr.Column.update(visible=False),
|
||||
# save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
|
||||
imgs_hash_clear: gr.Button.update(visible=False)
|
||||
}
|
||||
except: # GR4.x
|
||||
return {
|
||||
control_col_1: gr.Column(visible=True),
|
||||
control_col_2: gr.Column(visible=False),
|
||||
control_col_3: gr.Column(visible=False),
|
||||
# save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
|
||||
imgs_hash_clear: gr.Button(visible=False)
|
||||
}
|
||||
return {
|
||||
control_col_1: gr.Column.update(visible=True),
|
||||
control_col_2: gr.Column.update(visible=False),
|
||||
control_col_3: gr.Column.update(visible=False),
|
||||
# save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
|
||||
imgs_hash_clear: gr.Button.update(visible=False)
|
||||
}
|
||||
if evt.index == 1:
|
||||
try: # GR3.x
|
||||
return {
|
||||
control_col_1: gr.Column.update(visible=False),
|
||||
control_col_2: gr.Column.update(visible=True),
|
||||
control_col_3: gr.Column.update(visible=False),
|
||||
# save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
|
||||
imgs_hash_clear: gr.Button.update(visible=False)
|
||||
}
|
||||
except: # GR4.x
|
||||
return {
|
||||
control_col_1: gr.Column(visible=False),
|
||||
control_col_2: gr.Column(visible=True),
|
||||
control_col_3: gr.Column(visible=False),
|
||||
# save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
|
||||
imgs_hash_clear: gr.Button(visible=False)
|
||||
}
|
||||
return {
|
||||
control_col_1: gr.Column.update(visible=False),
|
||||
control_col_2: gr.Column.update(visible=True),
|
||||
control_col_3: gr.Column.update(visible=False),
|
||||
# save_original: gr.Checkbox.update(value=SAVE_ORIGINAL,visible=show_br),
|
||||
imgs_hash_clear: gr.Button.update(visible=False)
|
||||
}
|
||||
|
||||
progressbar_area = gr.Markdown("")
|
||||
with gr.Tab("Main"):
|
||||
@ -117,21 +85,16 @@ def show(is_img2img: bool, show_br: bool = True, **msgs):
|
||||
imgs_hash_clear.click(clear_faces_list,None,[progressbar_area])
|
||||
gr.Markdown("<br>", visible=show_br)
|
||||
with gr.Column(visible=True) as control_col_1:
|
||||
gr.Markdown("<center>🔽🔽🔽 Single Image has priority when both Areas in use 🔽🔽🔽</center>")
|
||||
with gr.Row():
|
||||
selected_tab = gr.Textbox('tab_single', visible=False)
|
||||
with gr.Tabs() as tab_single:
|
||||
with gr.Tab('Single'):
|
||||
img = gr.Image(
|
||||
type="pil",
|
||||
label="Single Source Image",
|
||||
)
|
||||
with gr.Tab('Multiple') as tab_multiple:
|
||||
imgs = gr.Files(
|
||||
label=f"Multiple Source Images{msgs['extra_multiple_source']}",
|
||||
file_types=["image"],
|
||||
)
|
||||
tab_single.select(fn=lambda: 'tab_single', inputs=[], outputs=[selected_tab])
|
||||
tab_multiple.select(fn=lambda: 'tab_multiple', inputs=[], outputs=[selected_tab])
|
||||
img = gr.Image(
|
||||
type="pil",
|
||||
label="Single Source Image",
|
||||
)
|
||||
imgs = gr.Files(
|
||||
label=f"Multiple Source Images{msgs['extra_multiple_source']}",
|
||||
file_types=["image"],
|
||||
)
|
||||
with gr.Column(visible=False) as control_col_3:
|
||||
gr.Markdown("<span style='display:block;text-align:right;padding-right:3px;margin: -15px 0;font-size:1.1em'><sup>Clear Hash if you see the previous face was swapped instead of the new one</sup></span>")
|
||||
with gr.Row():
|
||||
@ -226,4 +189,4 @@ def show(is_img2img: bool, show_br: bool = True, **msgs):
|
||||
# select_source.select(on_select_source,[save_original],[control_col_1,control_col_2,control_col_3,save_original,imgs_hash_clear],show_progress=False)
|
||||
select_source.select(on_select_source,None,[control_col_1,control_col_2,control_col_3,imgs_hash_clear],show_progress=False)
|
||||
|
||||
return img, imgs, selected_tab, select_source, face_model, source_folder, save_original, mask_face, source_faces_index, gender_source, faces_index, gender_target, face_restorer_name, face_restorer_visibility, codeformer_weight, swap_in_source, swap_in_generated, random_image
|
||||
return img, imgs, select_source, face_model, source_folder, save_original, mask_face, source_faces_index, gender_source, faces_index, gender_target, face_restorer_name, face_restorer_visibility, codeformer_weight, swap_in_source, swap_in_generated, random_image
|
||||
|
||||
@ -39,7 +39,7 @@ def show():
|
||||
value="Mean",
|
||||
label="Compute Method",
|
||||
type="index",
|
||||
info="Mean (recommended) - Average value (best result 👍); Median* - Mid-point value (may be funny 😅); Mode - Most common value (may be scary 😨); *Mean and Median will be similar if you load two images"
|
||||
info="Mean (recommended) - Average value (best result 👍); Median* - Mid-point value (may be funny 😅); Mode - Most common value (may be scary 😨); *Mean and Median will be simillar if you load two images"
|
||||
)
|
||||
shape_check = gr.Checkbox(
|
||||
False,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
albumentations==1.4.3
|
||||
insightface==0.7.3
|
||||
onnx==1.16.1
|
||||
onnx>=1.14.0
|
||||
opencv-python>=4.7.0.72
|
||||
|
||||
@ -2,7 +2,7 @@ import os.path as osp
|
||||
import glob
|
||||
import logging
|
||||
import insightface
|
||||
from insightface.model_zoo.model_zoo import ModelRouter, PickableInferenceSession, get_default_providers
|
||||
from insightface.model_zoo.model_zoo import ModelRouter, PickableInferenceSession
|
||||
from insightface.model_zoo.retinaface import RetinaFace
|
||||
from insightface.model_zoo.landmark import Landmark
|
||||
from insightface.model_zoo.attribute import Attribute
|
||||
@ -97,20 +97,15 @@ def patched_inswapper_init(self, model_file=None, session=None):
|
||||
self.input_size = tuple(input_shape[2:4][::-1])
|
||||
|
||||
|
||||
def patched_get_default_providers():
|
||||
return ['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider']
|
||||
|
||||
|
||||
def patch_insightface(get_default_providers, get_model, faceanalysis_init, faceanalysis_prepare, inswapper_init):
|
||||
insightface.model_zoo.model_zoo.get_default_providers = get_default_providers
|
||||
def patch_insightface(get_model, faceanalysis_init, faceanalysis_prepare, inswapper_init):
|
||||
insightface.model_zoo.model_zoo.ModelRouter.get_model = get_model
|
||||
insightface.app.FaceAnalysis.__init__ = faceanalysis_init
|
||||
insightface.app.FaceAnalysis.prepare = faceanalysis_prepare
|
||||
insightface.model_zoo.inswapper.INSwapper.__init__ = inswapper_init
|
||||
|
||||
|
||||
original_functions = [patched_get_default_providers, ModelRouter.get_model, FaceAnalysis.__init__, FaceAnalysis.prepare, INSwapper.__init__]
|
||||
patched_functions = [patched_get_default_providers, patched_get_model, patched_faceanalysis_init, patched_faceanalysis_prepare, patched_inswapper_init]
|
||||
original_functions = [ModelRouter.get_model, FaceAnalysis.__init__, FaceAnalysis.prepare, INSwapper.__init__]
|
||||
patched_functions = [patched_get_model, patched_faceanalysis_init, patched_faceanalysis_prepare, patched_inswapper_init]
|
||||
|
||||
|
||||
def apply_logging_patch(console_logging_level):
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'''
|
||||
Thanks SpenserCai for the original version of the roop api script
|
||||
-----------------------------------
|
||||
--- ReActor External API v1.0.8a ---
|
||||
--- ReActor External API v1.0.7 ---
|
||||
-----------------------------------
|
||||
'''
|
||||
import os, glob
|
||||
@ -13,11 +13,6 @@ from fastapi import FastAPI, Body
|
||||
# import base64
|
||||
# import numpy as np
|
||||
# import cv2
|
||||
import asyncio
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
# from concurrent.futures.process import ProcessPoolExecutor
|
||||
# from contextlib import asynccontextmanager
|
||||
# import multiprocessing
|
||||
|
||||
# from modules.api.models import *
|
||||
from modules import scripts, shared
|
||||
@ -25,32 +20,18 @@ from modules.api import api
|
||||
|
||||
import gradio as gr
|
||||
|
||||
from scripts.reactor_swapper import EnhancementOptions, blend_faces, swap_face, DetectionOptions
|
||||
from scripts.reactor_swapper import EnhancementOptions, swap_face, DetectionOptions
|
||||
from scripts.reactor_logger import logger
|
||||
from scripts.reactor_helpers import get_facemodels
|
||||
|
||||
|
||||
# @asynccontextmanager
|
||||
# async def lifespan(app: FastAPI):
|
||||
# app.state.executor = ProcessPoolExecutor(max_workers=4)
|
||||
# yield
|
||||
# app.state.executor.shutdown()
|
||||
|
||||
# app = FastAPI(lifespan=lifespan)
|
||||
|
||||
# def run_app(a: FastAPI):
|
||||
# global app
|
||||
# a = app
|
||||
# return a
|
||||
|
||||
# _executor_tp = ThreadPoolExecutor(max_workers=8)
|
||||
# def entry_point():
|
||||
# _executor_pp = ProcessPoolExecutor(max_workers=8)
|
||||
# pool = multiprocessing.Pool(4)
|
||||
|
||||
async def run_event(app, fn, *args):
|
||||
loop = asyncio.get_event_loop()
|
||||
return await loop.run_in_executor(app.state.executor, fn, *args)
|
||||
# XYZ init:
|
||||
from scripts.reactor_xyz import run
|
||||
try:
|
||||
import modules.script_callbacks as script_callbacks
|
||||
script_callbacks.on_before_ui(run)
|
||||
# script_callbacks.on_app_started(reactor_api)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def default_file_path():
|
||||
@ -101,7 +82,6 @@ def get_full_model(model_name):
|
||||
# raise HTTPException(status_code=500, detail="Invalid encoded image") from e
|
||||
|
||||
def reactor_api(_: gr.Blocks, app: FastAPI):
|
||||
app.state.executor = ThreadPoolExecutor(max_workers=8)
|
||||
@app.post("/reactor/image")
|
||||
async def reactor_image(
|
||||
source_image: str = Body("",title="Source Face Image"),
|
||||
@ -151,26 +131,22 @@ def reactor_api(_: gr.Blocks, app: FastAPI):
|
||||
use_model = get_full_model(model)
|
||||
if use_model is None:
|
||||
Exception("Model not found")
|
||||
|
||||
args = [s_image, t_image, use_model, sf_index, f_index, up_options, gender_s, gender_t, True, True, device, mask_face, select_source, face_model, source_folder, None, random_image,det_options]
|
||||
# result,_,_ = pool.map(swap_face, *args)
|
||||
result,_,_ = await run_event(app,swap_face,*args)
|
||||
# result,_,_ = swap_face(s_image, t_image, use_model, sf_index, f_index, up_options, gender_s, gender_t, True, True, device, mask_face, select_source, face_model, source_folder, None, random_image,det_options)
|
||||
result = swap_face(s_image, t_image, use_model, sf_index, f_index, up_options, gender_s, gender_t, True, True, device, mask_face, select_source, face_model, source_folder, None, random_image,det_options)
|
||||
result_img = result[0]
|
||||
|
||||
if alpha is not None:
|
||||
result = result.convert("RGBA")
|
||||
result.putalpha(alpha)
|
||||
result_img = result_img.convert("RGBA")
|
||||
result_img.putalpha(alpha)
|
||||
|
||||
if save_to_file == 1:
|
||||
if result_file_path == "":
|
||||
result_file_path = default_file_path()
|
||||
try:
|
||||
file_format = os.path.split(result_file_path)[1].split(".")[1]
|
||||
result.save(result_file_path, format=file_format)
|
||||
result_img.save(result_file_path, format='PNG')
|
||||
logger.status("Result has been saved to: %s", result_file_path)
|
||||
except Exception as e:
|
||||
logger.error("Error while saving result: %s",e)
|
||||
return {"image": api.encode_pil_to_base64(result)}
|
||||
return {"image": api.encode_pil_to_base64(result_img)}
|
||||
|
||||
@app.get("/reactor/models")
|
||||
async def reactor_models():
|
||||
@ -187,18 +163,9 @@ def reactor_api(_: gr.Blocks, app: FastAPI):
|
||||
facemodels = [os.path.split(model)[1].split(".")[0] for model in get_facemodels()]
|
||||
return {"facemodels": facemodels}
|
||||
|
||||
@app.post("/reactor/facemodels")
|
||||
async def reactor_facemodels_build(
|
||||
source_images: list[str] = Body([""],title="Source Face Image List"),
|
||||
name: str = Body("",title="Face Model Name"),
|
||||
compute_method: int = Body(0,title="Compute Method (Mean, Median, Mode)"),
|
||||
):
|
||||
images = [api.decode_base64_to_image(img) for img in source_images]
|
||||
blend_faces(images, name, compute_method, False, is_api=True)
|
||||
return {"facemodels": [os.path.split(model)[1].split(".")[0] for model in get_facemodels()]}
|
||||
|
||||
try:
|
||||
import modules.script_callbacks as script_callbacks
|
||||
|
||||
script_callbacks.on_app_started(reactor_api)
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -6,7 +6,7 @@ from typing import List
|
||||
|
||||
import modules.scripts as scripts
|
||||
from modules.upscaler import Upscaler, UpscalerData
|
||||
from modules import scripts, shared, images, scripts_postprocessing
|
||||
from modules import scripts, shared, images, scripts_postprocessing, ui_components
|
||||
from modules.processing import (
|
||||
Processed,
|
||||
StableDiffusionProcessing,
|
||||
@ -39,20 +39,6 @@ from scripts.reactor_helpers import (
|
||||
)
|
||||
from scripts.reactor_globals import SWAPPER_MODELS_PATH #, DEVICE, DEVICE_LIST
|
||||
|
||||
def IA_cap(cond: bool, label: str=""):
|
||||
return None
|
||||
|
||||
try:
|
||||
from modules.ui_components import InputAccordion
|
||||
NO_IA = False
|
||||
except:
|
||||
NO_IA = True
|
||||
InputAccordion = IA_cap
|
||||
|
||||
|
||||
def check_old_webui():
|
||||
return NO_IA
|
||||
|
||||
|
||||
class FaceSwapScript(scripts.Script):
|
||||
def title(self):
|
||||
@ -62,12 +48,19 @@ class FaceSwapScript(scripts.Script):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
with (
|
||||
gr.Accordion(f"{app_title}", open=False) if check_old_webui() else InputAccordion(False, label=f"{app_title}") as enable
|
||||
):
|
||||
with ui_components.InputAccordion(False, label=f"{app_title}") as enable:
|
||||
# with gr.Accordion(f"{app_title}", open=False):
|
||||
|
||||
# SD.Next or A1111 1.52:
|
||||
if get_SDNEXT() or check_old_webui():
|
||||
# def on_files_upload_uncheck_so(selected: bool):
|
||||
# global SAVE_ORIGINAL
|
||||
# SAVE_ORIGINAL = selected
|
||||
# return gr.Checkbox.update(value=False,visible=False)
|
||||
# def on_files_clear():
|
||||
# clear_faces_list()
|
||||
# return gr.Checkbox.update(value=SAVE_ORIGINAL,visible=True)
|
||||
|
||||
# SD.Next fix
|
||||
if get_SDNEXT():
|
||||
enable = gr.Checkbox(False, label="Enable")
|
||||
|
||||
# enable = gr.Checkbox(False, label="Enable", info=f"The Fast and Simple FaceSwap Extension - {version_flag}")
|
||||
@ -77,7 +70,7 @@ class FaceSwapScript(scripts.Script):
|
||||
msgs: dict = {
|
||||
"extra_multiple_source": "",
|
||||
}
|
||||
img, imgs, selected_tab, select_source, face_model, source_folder, save_original, mask_face, source_faces_index, gender_source, faces_index, gender_target, face_restorer_name, face_restorer_visibility, codeformer_weight, swap_in_source, swap_in_generated, random_image = ui_main.show(is_img2img=is_img2img, **msgs)
|
||||
img, imgs, select_source, face_model, source_folder, save_original, mask_face, source_faces_index, gender_source, faces_index, gender_target, face_restorer_name, face_restorer_visibility, codeformer_weight, swap_in_source, swap_in_generated, random_image = ui_main.show(is_img2img=is_img2img, **msgs)
|
||||
|
||||
# TAB DETECTION
|
||||
det_thresh, det_maxnum = ui_detection.show()
|
||||
@ -123,8 +116,7 @@ class FaceSwapScript(scripts.Script):
|
||||
random_image,
|
||||
upscale_force,
|
||||
det_thresh,
|
||||
det_maxnum,
|
||||
selected_tab,
|
||||
det_maxnum
|
||||
]
|
||||
|
||||
|
||||
@ -194,8 +186,7 @@ class FaceSwapScript(scripts.Script):
|
||||
random_image,
|
||||
upscale_force,
|
||||
det_thresh,
|
||||
det_maxnum,
|
||||
selected_tab,
|
||||
det_maxnum
|
||||
):
|
||||
self.enable = enable
|
||||
if self.enable:
|
||||
@ -207,10 +198,7 @@ class FaceSwapScript(scripts.Script):
|
||||
return
|
||||
|
||||
global SWAPPER_MODELS_PATH
|
||||
if selected_tab == "tab_single":
|
||||
self.source = img
|
||||
else:
|
||||
self.source = None
|
||||
self.source = img
|
||||
self.face_restorer_name = face_restorer_name
|
||||
self.upscaler_scale = upscaler_scale
|
||||
self.upscaler_visibility = upscaler_visibility
|
||||
@ -232,10 +220,7 @@ class FaceSwapScript(scripts.Script):
|
||||
self.select_source = select_source
|
||||
self.face_model = face_model
|
||||
self.source_folder = source_folder
|
||||
if selected_tab == "tab_single":
|
||||
self.source_imgs = None
|
||||
else:
|
||||
self.source_imgs = imgs
|
||||
self.source_imgs = imgs
|
||||
self.random_image = random_image
|
||||
self.upscale_force = upscale_force
|
||||
self.det_thresh=det_thresh
|
||||
@ -245,10 +230,10 @@ class FaceSwapScript(scripts.Script):
|
||||
if self.gender_target is None or self.gender_target == "No":
|
||||
self.gender_target = 0
|
||||
self.source_faces_index = [
|
||||
int(x) for x in source_faces_index.strip().replace(" ", "").strip(",").split(",") if x.isnumeric()
|
||||
int(x) for x in source_faces_index.strip(",").split(",") if x.isnumeric()
|
||||
]
|
||||
self.faces_index = [
|
||||
int(x) for x in faces_index.strip().replace(" ", "").strip(",").split(",") if x.isnumeric()
|
||||
int(x) for x in faces_index.strip(",").split(",") if x.isnumeric()
|
||||
]
|
||||
if len(self.source_faces_index) == 0:
|
||||
self.source_faces_index = [0]
|
||||
@ -503,14 +488,11 @@ class FaceSwapScriptExtras(scripts_postprocessing.ScriptPostprocessing):
|
||||
order = 20000
|
||||
|
||||
def ui(self):
|
||||
with (
|
||||
gr.Accordion(f"{app_title}", open=False) if check_old_webui() else InputAccordion(False, label=f"{app_title}") as enable
|
||||
):
|
||||
# with ui_components.InputAccordion(False, label=f"{app_title}") as enable:
|
||||
with ui_components.InputAccordion(False, label=f"{app_title}") as enable:
|
||||
# with gr.Accordion(f"{app_title}", open=False):
|
||||
|
||||
# SD.Next or A1111 1.52:
|
||||
if get_SDNEXT() or check_old_webui():
|
||||
# SD.Next fix
|
||||
if get_SDNEXT():
|
||||
enable = gr.Checkbox(False, label="Enable")
|
||||
|
||||
# enable = gr.Checkbox(False, label="Enable", info=f"The Fast and Simple FaceSwap Extension - {version_flag}")
|
||||
@ -518,9 +500,9 @@ class FaceSwapScriptExtras(scripts_postprocessing.ScriptPostprocessing):
|
||||
|
||||
# TAB MAIN
|
||||
msgs: dict = {
|
||||
"extra_multiple_source": "",
|
||||
"extra_multiple_source": " | Сomparison grid as a result",
|
||||
}
|
||||
img, imgs, selected_tab, select_source, face_model, source_folder, save_original, mask_face, source_faces_index, gender_source, faces_index, gender_target, face_restorer_name, face_restorer_visibility, codeformer_weight, swap_in_source, swap_in_generated, random_image = ui_main.show(is_img2img=False, show_br=False, **msgs)
|
||||
img, imgs, select_source, face_model, source_folder, save_original, mask_face, source_faces_index, gender_source, faces_index, gender_target, face_restorer_name, face_restorer_visibility, codeformer_weight, swap_in_source, swap_in_generated, random_image = ui_main.show(is_img2img=False, show_br=False, **msgs)
|
||||
|
||||
# TAB DETECTION
|
||||
det_thresh, det_maxnum = ui_detection.show()
|
||||
@ -562,7 +544,6 @@ class FaceSwapScriptExtras(scripts_postprocessing.ScriptPostprocessing):
|
||||
'upscale_force': upscale_force,
|
||||
'det_thresh': det_thresh,
|
||||
'det_maxnum': det_maxnum,
|
||||
'selected_tab': selected_tab,
|
||||
}
|
||||
return args
|
||||
|
||||
@ -607,10 +588,7 @@ class FaceSwapScriptExtras(scripts_postprocessing.ScriptPostprocessing):
|
||||
return
|
||||
|
||||
global SWAPPER_MODELS_PATH
|
||||
if args['selected_tab'] == "tab_single":
|
||||
self.source = args['img']
|
||||
else:
|
||||
self.source = None
|
||||
self.source = args['img']
|
||||
self.face_restorer_name = args['face_restorer_name']
|
||||
self.upscaler_scale = args['upscaler_scale']
|
||||
self.upscaler_visibility = args['upscaler_visibility']
|
||||
@ -627,10 +605,7 @@ class FaceSwapScriptExtras(scripts_postprocessing.ScriptPostprocessing):
|
||||
self.select_source = args['select_source']
|
||||
self.face_model = args['face_model']
|
||||
self.source_folder = args['source_folder']
|
||||
if args['selected_tab'] == "tab_single":
|
||||
self.source_imgs = None
|
||||
else:
|
||||
self.source_imgs = args['imgs']
|
||||
self.source_imgs = args['imgs']
|
||||
self.random_image = args['random_image']
|
||||
self.upscale_force = args['upscale_force']
|
||||
self.det_thresh = args['det_thresh']
|
||||
@ -709,13 +684,9 @@ class FaceSwapScriptExtras(scripts_postprocessing.ScriptPostprocessing):
|
||||
if len(result) > 0 and swapped > 0:
|
||||
image = result[0]
|
||||
if len(result) > 1:
|
||||
if hasattr(pp, 'extra_images'):
|
||||
image = result[0]
|
||||
pp.extra_images.extend(result[1:])
|
||||
else:
|
||||
grid = make_grid(result)
|
||||
result.insert(0, grid)
|
||||
image = grid
|
||||
grid = make_grid(result)
|
||||
result.insert(0, grid)
|
||||
image = grid
|
||||
pp.info["ReActor"] = True
|
||||
pp.image = image
|
||||
logger.status("---Done!---")
|
||||
|
||||
@ -203,12 +203,9 @@ def get_facemodels():
|
||||
|
||||
def get_model_names(get_models):
|
||||
models = get_models()
|
||||
names = []
|
||||
names = ["None"]
|
||||
for x in models:
|
||||
names.append(os.path.basename(x))
|
||||
# Sort ignoring case during sort but retain in output
|
||||
names.sort(key=str.lower)
|
||||
names.insert(0, "None")
|
||||
return names
|
||||
|
||||
def get_images_from_folder(path: str):
|
||||
|
||||
@ -661,19 +661,13 @@ def build_face_model(image: Image.Image, name: str, save_model: bool = True, det
|
||||
logger.error(no_face_msg)
|
||||
return no_face_msg
|
||||
|
||||
def blend_faces(images_list: List, name: str, compute_method: int = 0, shape_check: bool = False, is_api: bool = False):
|
||||
def blend_faces(images_list: List, name: str, compute_method: int = 0, shape_check: bool = False):
|
||||
faces = []
|
||||
embeddings = []
|
||||
images: List[Image.Image] = []
|
||||
if not is_api:
|
||||
images, images_names = get_images_from_list(images_list)
|
||||
else:
|
||||
images = images_list
|
||||
images, images_names = get_images_from_list(images_list)
|
||||
for i,image in enumerate(images):
|
||||
if not is_api:
|
||||
logger.status(f"Building Face Model for {images_names[i]}...")
|
||||
else:
|
||||
logger.status(f"Building Face Model for Image {i+1}...")
|
||||
logger.status(f"Building Face Model for {images_names[i]}...")
|
||||
face = build_face_model(image,str(i),save_model=False)
|
||||
if isinstance(face, str):
|
||||
# logger.error(f"No faces found in {images_names[i]}, skipping")
|
||||
@ -682,10 +676,7 @@ def blend_faces(images_list: List, name: str, compute_method: int = 0, shape_che
|
||||
if i == 0:
|
||||
embedding_shape = face.embedding.shape
|
||||
elif face.embedding.shape != embedding_shape:
|
||||
if not is_api:
|
||||
logger.error(f"Embedding Shape Mismatch for {images_names[i]}, skipping")
|
||||
else:
|
||||
logger.error(f"Embedding Shape Mismatch for Image {i+1}, skipping")
|
||||
logger.error(f"Embedding Shape Mismatch for {images_names[i]}, skipping")
|
||||
continue
|
||||
faces.append(face)
|
||||
embeddings.append(face.embedding)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
app_title = "ReActor"
|
||||
version_flag = "v0.7.1-b2"
|
||||
version_flag = "v0.7.0"
|
||||
|
||||
from scripts.reactor_logger import logger, get_Run, set_Run
|
||||
from scripts.reactor_globals import DEVICE
|
||||
|
||||
@ -10,7 +10,6 @@ from scripts.reactor_helpers import (
|
||||
get_facemodels
|
||||
)
|
||||
|
||||
|
||||
# xyz_grid = [x for x in scripts.scripts_data if x.script_class.__module__ == "xyz_grid.py"][0].module
|
||||
|
||||
def find_module(module_names):
|
||||
@ -85,10 +84,3 @@ def run():
|
||||
xyz_grid = find_module("xyz_grid.py, xy_grid.py")
|
||||
if xyz_grid:
|
||||
add_axis_options(xyz_grid)
|
||||
|
||||
# XYZ init:
|
||||
try:
|
||||
import modules.script_callbacks as script_callbacks
|
||||
script_callbacks.on_before_ui(run)
|
||||
except:
|
||||
pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user