Skip to content

Commit

Permalink
UPDATE: models paths, old path check
Browse files Browse the repository at this point in the history
- "models/roop" folder renamed to "models/insightface";
- buffalo models go to "models/insightface" (no need to keep them in the user's profile directory); thanks @h3rmit-git for the idea
- VersionUP (beta passed)
  • Loading branch information
Gourieff committed Aug 28, 2023
1 parent 0a6fe99 commit e4eecb9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<div align="center">

<img src="example/ReActor_logo_red.png" alt="logo" width="180px"/>
<img src="example/ReActor_logo_red.png" alt="logo" width="180px" style="margin-bottom:-33px"/>

[![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/t/Gourieff/sd-webui-reactor/main)](https://github.com/Gourieff/sd-webui-reactor/commits/main)
![Last commit](https://img.shields.io/github/last-commit/Gourieff/sd-webui-reactor/main)
[![Opened issues](https://img.shields.io/github/issues/Gourieff/sd-webui-reactor?color=red)](https://github.com/Gourieff/sd-webui-reactor/issues)
[![Closed issues](https://img.shields.io/github/issues-closed/Gourieff/sd-webui-reactor?color=green)](https://github.com/Gourieff/sd-webui-reactor/issues?q=is%3Aissue+is%3Aclosed)
![GitHub](https://img.shields.io/github/license/Gourieff/sd-webui-reactor)
# ![Version](https://img.shields.io/badge/version-0.4.0-brightgreen?style=for-the-badge&labelColor=darkgreen)
[![Commit activity](https://img.shields.io/github/commit-activity/t/Gourieff/sd-webui-reactor/main?cacheSeconds=0)](https://github.com/Gourieff/sd-webui-reactor/commits/main)
![Last commit](https://img.shields.io/github/last-commit/Gourieff/sd-webui-reactor/main?cacheSeconds=0)
[![Opened issues](https://img.shields.io/github/issues/Gourieff/sd-webui-reactor?color=red)](https://github.com/Gourieff/sd-webui-reactor/issues?cacheSeconds=0)
[![Closed issues](https://img.shields.io/github/issues-closed/Gourieff/sd-webui-reactor?color=green&cacheSeconds=0)](https://github.com/Gourieff/sd-webui-reactor/issues?q=is%3Aissue+is%3Aclosed)
![License](https://img.shields.io/github/license/Gourieff/sd-webui-reactor)

English | [Русский](/README_RU.md)

# ReActor for StableDiffusion

</div>

# <div align="center">ReActor 0.4.0b for StableDiffusion</div>
### The Fast and Simple "[roop-based](https://github.com/s0md3v/sd-webui-roop)" FaceSwap Extension with a lot of improvements and without NSFW filter (uncensored, use it on your own [responsibility](#disclaimer))

> Ex "Roop-GE" (GE - Gourieff Edition, aka "NSFW-Roop"), the extension was renamed with the version 0.3.0<br>
Expand Down
17 changes: 9 additions & 8 deletions README_RU.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<div align="center">

<img src="example/ReActor_logo_red.png" alt="logo" width="180px"/>

[![Commit activity](https://img.shields.io/github/commit-activity/t/Gourieff/sd-webui-reactor/main)](https://github.com/Gourieff/sd-webui-reactor/commits/main)
![Last commit](https://img.shields.io/github/last-commit/Gourieff/sd-webui-reactor/main)
[![Opened issues](https://img.shields.io/github/issues/Gourieff/sd-webui-reactor?color=red)](https://github.com/Gourieff/sd-webui-reactor/issues)
[![Closed issues](https://img.shields.io/github/issues-closed/Gourieff/sd-webui-reactor?color=green)](https://github.com/Gourieff/sd-webui-reactor/issues?q=is%3Aissue+is%3Aclosed)
![GitHub](https://img.shields.io/github/license/Gourieff/sd-webui-reactor)
<img src="example/ReActor_logo_red.png" alt="logo" width="180px" style="margin-bottom:-33px"/>

# ![Version](https://img.shields.io/badge/версия-0.4.0-brightgreen?style=for-the-badge&labelColor=darkgreen)
[![Commit activity](https://img.shields.io/github/commit-activity/t/Gourieff/sd-webui-reactor/main?cacheSeconds=0)](https://github.com/Gourieff/sd-webui-reactor/commits/main)
![Last commit](https://img.shields.io/github/last-commit/Gourieff/sd-webui-reactor/main?cacheSeconds=0)
[![Opened issues](https://img.shields.io/github/issues/Gourieff/sd-webui-reactor?color=red)](https://github.com/Gourieff/sd-webui-reactor/issues?cacheSeconds=0)
[![Closed issues](https://img.shields.io/github/issues-closed/Gourieff/sd-webui-reactor?color=green&cacheSeconds=0)](https://github.com/Gourieff/sd-webui-reactor/issues?q=is%3Aissue+is%3Aclosed)
![License](https://img.shields.io/github/license/Gourieff/sd-webui-reactor)

[English](/README.md) | Русский

# ReActor 0.4.0b для StableDiffusion
# ReActor для StableDiffusion
### Расширение для быстрой и простой замены лиц на любых изображениях. Без фильтра цензуры, 18+, используйте под вашу собственную [ответственность](#disclaimer)

</div>
Expand Down
8 changes: 6 additions & 2 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import urllib.request
from packaging import version as pv

req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt")
from modules.paths_internal import models_path

models_dir = os.path.abspath("models/roop")
req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt")

models_dir_old = os.path.join(models_path, "roop")
models_dir = os.path.join(models_path, "insightface")
if os.path.exists(models_dir_old):
os.rename(models_dir_old, models_dir)
model_url = "https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx"
model_name = os.path.basename(model_url)
model_path = os.path.join(models_dir, model_name)
Expand Down
12 changes: 7 additions & 5 deletions scripts/faceswap.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import os, glob
import gradio as gr
from PIL import Image

import modules.scripts as scripts
from modules.upscaler import Upscaler, UpscalerData
from modules import scripts, shared, images, scripts_postprocessing
from modules.processing import (
StableDiffusionProcessing,
StableDiffusionProcessingImg2Img,
)
from PIL import Image
import glob
from modules.face_restoration import FaceRestoration
from modules.paths_internal import models_path

from scripts.logger import logger
from scripts.swapper import UpscaleOptions, swap_face, check_process_halt, reset_messaged
from scripts.version import version_flag, app_title
from scripts.console_log_patch import apply_logging_patch
import os


MODELS_PATH = None

def get_models():
global MODELS_PATH
models_path = os.path.join(scripts.basedir(), "models/roop/*")
models = glob.glob(models_path)
models_path_init = os.path.join(models_path, "insightface/*")
models = glob.glob(models_path_init)
models = [x for x in models if x.endswith(".onnx") or x.endswith(".pth")]
models_names = []
for model in models:
Expand Down
9 changes: 7 additions & 2 deletions scripts/swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from modules.face_restoration import FaceRestoration
from modules.upscaler import UpscalerData
from modules.shared import state
from modules.paths_internal import models_path
from scripts.logger import logger

import warnings
Expand Down Expand Up @@ -86,7 +87,7 @@ def getAnalysisModel():
global ANALYSIS_MODEL
if ANALYSIS_MODEL is None:
ANALYSIS_MODEL = insightface.app.FaceAnalysis(
name="buffalo_l", providers=providers # note: allowed_modules=['detection', 'genderage']
name="buffalo_l", providers=providers, root=os.path.join(models_path, "insightface") # note: allowed_modules=['detection', 'genderage']
)
return ANALYSIS_MODEL

Expand Down Expand Up @@ -193,6 +194,10 @@ def get_face_single(img_data: np.ndarray, face_index=0, det_size=(640, 640), gen
face_analyser.prepare(ctx_id=0, det_size=det_size)
face = face_analyser.get(img_data)

buffalo_path = os.path.join(models_path, "insightface/models/buffalo_l.zip")
if os.path.exists(buffalo_path):
os.remove(buffalo_path)

if gender_source != 0:
if len(face) == 0 and det_size[0] > 320 and det_size[1] > 320:
return reget_face_single(img_data, det_size, face_index)
Expand Down Expand Up @@ -252,7 +257,7 @@ def swap_face(
elif source_face is not None:

result = target_img
model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), model)
model_path = os.path.join(models_path, "insightface", model)
face_swapper = getFaceSwapModel(model_path)

source_face_idx = 0
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
app_title = "ReActor"
version_flag = "v0.4.0b"
version_flag = "v0.4.0"

from scripts.logger import logger, get_Run, set_Run

Expand Down

1 comment on commit e4eecb9

@eadnams22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we specify the model location ourselves? It seems to get increasingly confused when we aren't using the standard model locations.

Please sign in to comment.