"tests/vscode:/vscode.git/clone" did not exist on "3b5962131093ceab09f0540cb99d84c18c45035f"
Unverified Commit 28750c1d authored by cckuailong's avatar cckuailong Committed by GitHub
Browse files

Web Demo Support running on Mac M1/2 (#17)



* support MPS

* Update README.md

* Make requirements more clearly

* resolve conflict

* Update: support MacOS

---------
Co-authored-by: default avatarZhen Li <zhenli1031@gmail.com>
parent cb553003
......@@ -3,5 +3,6 @@ civitai_models/
gradio_cached_examples/
outputs/
__pycache__/
.idea/
*.bin
*.safetensors
\ No newline at end of file
# How to use GPU on Mac M1/2
1. Install xcode tools
```
xcode-select --install
```
2. Install llvm
```
brew install llvm libomp
```
3. Install torch 2.1.2
```
pip install torch==2.1.2
```
\ No newline at end of file
......@@ -189,6 +189,8 @@ python gradio_demo/app.py
You could customize this script in [this file](gradio_demo/app.py).
If you want to run it on MAC, you should follow [this Instruction](MacGPUEnv.md) and then run the app.py.
## Usage Tips:
- Upload more photos of the person to be customized to improve ID fidelty. If the input is Asian face(s), maybe consider adding 'asian' before the class word, e.g., `asian woman img`
- When stylizing, does the generated face look too realistic? Adjust the Style strength to 30-50, the larger the number, the less ID fidelty, but the stylization ability will be better. You could also try out other base models or LoRAs with good stylization effects.
......
......@@ -2,6 +2,7 @@ import torch
import numpy as np
import random
import os
import sys
from diffusers.utils import load_image
from diffusers import EulerDiscreteScheduler
......@@ -15,7 +16,16 @@ from style_template import styles
# global variable
base_model_path = 'SG161222/RealVisXL_V3.0'
device = "cuda" if torch.cuda.is_available() else "cpu"
try:
if torch.cuda.is_available():
device = "cuda"
elif sys.platform == "darwin" and torch.backends.mps.is_available():
device = "mps"
else:
device = "cpu"
except:
device = "cpu"
MAX_SEED = np.iinfo(np.int32).max
STYLE_NAMES = list(styles.keys())
DEFAULT_STYLE_NAME = "Photographic (Default)"
......@@ -23,9 +33,13 @@ DEFAULT_STYLE_NAME = "Photographic (Default)"
# download PhotoMaker checkpoint to cache
photomaker_ckpt = hf_hub_download(repo_id="TencentARC/PhotoMaker", filename="photomaker-v1.bin", repo_type="model")
if device == "mps":
torch_dtype = torch.float16
else:
torch_dtype = torch.bfloat16
pipe = PhotoMakerStableDiffusionXLPipeline.from_pretrained(
base_model_path,
torch_dtype=torch.bfloat16,
torch_dtype=torch_dtype,
use_safetensors=True,
variant="fp16",
# local_files_only=True,
......@@ -101,7 +115,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
seed = random.randint(0, MAX_SEED)
return seed
def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
def apply_style(style_name: str, positive: str, negative: str = ""):
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
return p.replace("{prompt}", positive), n + ' ' + negative
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment