Skip to content

Commit

Permalink
IP-Adapter face id (#2434)
Browse files Browse the repository at this point in the history
* faceid

* remove unused file

* Update To_KV

* faceid_plus

* Remove unncessary dep

* Change download path

* Add install script

* nit

* nits

* Fixes controlmode visibility
  • Loading branch information
huchenlei authored Jan 10, 2024
1 parent a52e607 commit a846376
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 33 deletions.
73 changes: 69 additions & 4 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import git # git is part of A1111 dependency.
import pkg_resources
import os
import sys
import platform
import requests
import tempfile
import subprocess
from pathlib import Path
from typing import Tuple, Optional

Expand All @@ -19,8 +24,10 @@ def sync_submodules():
repo.submodule_update()
except Exception as e:
print(e)
print("Warning: ControlNet failed to sync submodules. Please try run "
"`git submodule init` and `git submodule update` manually.")
print(
"Warning: ControlNet failed to sync submodules. Please try run "
"`git submodule init` and `git submodule update` manually."
)


def comparable_version(version: str) -> Tuple:
Expand All @@ -35,9 +42,9 @@ def get_installed_version(package: str) -> Optional[str]:


def extract_base_package(package_string: str) -> str:
""" trimesh[easy] -> trimesh """
"""trimesh[easy] -> trimesh"""
# Split the string on '[' and take the first part
base_package = package_string.split('[')[0]
base_package = package_string.split("[")[0]
return base_package


Expand Down Expand Up @@ -76,7 +83,65 @@ def install_requirements(req_file):
)


def try_install_insight_face():
"""Attempt to install insightface library. The library is necessary to use ip-adapter faceid.
Note: Building insightface library from source requires compiling C++ code, which should be avoided
in principle. Here the solution is to download a precompiled wheel. """
if get_installed_version("insightface") is not None:
return

def download_file(url, temp_dir):
""" Download a file from a given URL to a temporary directory """
local_filename = url.split('/')[-1]
response = requests.get(url, stream=True)
response.raise_for_status()

filepath = f"{temp_dir}/{local_filename}"
with open(filepath, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
return filepath

def install_wheel(wheel_path):
"""Install the wheel using pip"""
subprocess.run(["pip", "install", wheel_path], check=True)

wheel_url = "https://github.com/Gourieff/Assets/raw/main/Insightface/insightface-0.7.3-cp310-cp310-win_amd64.whl"

system = platform.system().lower()
architecture = platform.machine().lower()
python_version = sys.version_info
if (
system == "windows"
and "amd64" in architecture
and python_version.major == 3
and python_version.minor == 10
):
try:
with tempfile.TemporaryDirectory() as temp_dir:
print(
"Downloading the prebuilt wheel for Windows amd64 to a temporary directory..."
)
wheel_path = download_file(wheel_url, temp_dir)
print(f"Download complete. File saved to {wheel_path}")

print("Installing the wheel...")
install_wheel(wheel_path)
print("Installation complete.")
except Exception as e:
print(
"ControlNet init warning: Unable to install insightface automatically. " + e
)
else:
print(
"ControlNet init warning: Unable to install insightface automatically. "
"Please try run `pip install insightface` manually."
)


sync_submodules()
install_requirements(main_req_file)
if os.path.exists(hand_refiner_req_file):
install_requirements(hand_refiner_req_file)
try_install_insight_face()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mediapipe
svglib
fvcore
onnxruntime
opencv-python>=4.8.0
Loading

0 comments on commit a846376

Please sign in to comment.