Update README.md
Browse files
README.md
CHANGED
@@ -89,15 +89,16 @@ import os
|
|
89 |
import random
|
90 |
import gradio as gr
|
91 |
|
92 |
-
|
93 |
import cv2
|
94 |
import torch
|
95 |
import numpy as np
|
96 |
from PIL import Image
|
97 |
|
98 |
from transformers import CLIPVisionModelWithProjection
|
99 |
-
from diffusers.utils import load_image
|
100 |
from diffusers.models import ControlNetModel
|
|
|
|
|
|
|
101 |
from insightface.app import FaceAnalysis
|
102 |
|
103 |
import io
|
@@ -108,8 +109,8 @@ from pipeline_stable_diffusion_xl_instantid import StableDiffusionXLInstantIDPip
|
|
108 |
import pandas as pd
|
109 |
import json
|
110 |
import requests
|
111 |
-
from PIL import Image
|
112 |
from io import BytesIO
|
|
|
113 |
|
114 |
|
115 |
def resize_img(input_image, max_side=1280, min_side=1024, size=None,
|
@@ -152,33 +153,50 @@ def make_canny_condition(image, min_val=100, max_val=200, w_bilateral=True):
|
|
152 |
|
153 |
default_negative_prompt = "Logo,Watermark,Text,Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate,Mutilated,Mutilated hands,Poorly drawn face,Deformed,Bad anatomy,Cloned face,Malformed limbs,Missing legs,Too many fingers"
|
154 |
|
155 |
-
#
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
158 |
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
-
face_adapter = f"./ip-adapter.bin"
|
162 |
-
controlnet_path = f"./controlnet"
|
163 |
|
|
|
164 |
|
|
|
|
|
|
|
165 |
base_model_path = f'briaai/BRIA-2.3'
|
166 |
resolution = 1024
|
167 |
|
|
|
168 |
controlnet_lnmks = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
|
169 |
-
|
170 |
controlnet_canny = ControlNetModel.from_pretrained("briaai/BRIA-2.3-ControlNet-Canny",
|
171 |
-
|
172 |
-
|
173 |
controlnet = [controlnet_lnmks, controlnet_canny]
|
174 |
|
175 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
176 |
|
177 |
image_encoder = CLIPVisionModelWithProjection.from_pretrained(
|
178 |
f"./checkpoints/image_encoder",
|
179 |
torch_dtype=torch.float16,
|
180 |
)
|
181 |
-
|
182 |
pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
|
183 |
base_model_path,
|
184 |
controlnet=controlnet,
|
|
|
89 |
import random
|
90 |
import gradio as gr
|
91 |
|
|
|
92 |
import cv2
|
93 |
import torch
|
94 |
import numpy as np
|
95 |
from PIL import Image
|
96 |
|
97 |
from transformers import CLIPVisionModelWithProjection
|
|
|
98 |
from diffusers.models import ControlNetModel
|
99 |
+
|
100 |
+
from huggingface_hub import snapshot_download
|
101 |
+
|
102 |
from insightface.app import FaceAnalysis
|
103 |
|
104 |
import io
|
|
|
109 |
import pandas as pd
|
110 |
import json
|
111 |
import requests
|
|
|
112 |
from io import BytesIO
|
113 |
+
from huggingface_hub import hf_hub_download, HfApi
|
114 |
|
115 |
|
116 |
def resize_img(input_image, max_side=1280, min_side=1024, size=None,
|
|
|
153 |
|
154 |
default_negative_prompt = "Logo,Watermark,Text,Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate,Mutilated,Mutilated hands,Poorly drawn face,Deformed,Bad anatomy,Cloned face,Malformed limbs,Missing legs,Too many fingers"
|
155 |
|
156 |
+
# Download face encoder
|
157 |
+
snapshot_download(
|
158 |
+
"fal/AuraFace-v1",
|
159 |
+
local_dir="models/auraface",
|
160 |
+
)
|
161 |
+
|
162 |
+
app = FaceAnalysis(
|
163 |
+
name="auraface",
|
164 |
+
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
|
165 |
+
root=".",
|
166 |
+
)
|
167 |
+
|
168 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
169 |
|
170 |
|
171 |
+
# download checkpoints
|
172 |
+
print("Downloading checkpoints")
|
173 |
+
hf_hub_download(repo_id="briaai/ID_preservation_2.3_auraFaceEnc", filename="checkpoint_105000/controlnet/config.json", local_dir="./checkpoints")
|
174 |
+
hf_hub_download(repo_id="briaai/ID_preservation_2.3_auraFaceEnc", filename="checkpoint_105000/controlnet/diffusion_pytorch_model.safetensors", local_dir="./checkpoints")
|
175 |
+
hf_hub_download(repo_id="briaai/ID_preservation_2.3_auraFaceEnc", filename="checkpoint_105000/ip-adapter.bin", local_dir="./checkpoints")
|
176 |
+
hf_hub_download(repo_id="briaai/ID_preservation_2.3_auraFaceEnc", filename="image_encoder/pytorch_model.bin", local_dir="./checkpoints")
|
177 |
+
hf_hub_download(repo_id="briaai/ID_preservation_2.3_auraFaceEnc", filename="image_encoder/config.json", local_dir="./checkpoints")
|
178 |
|
|
|
|
|
179 |
|
180 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
181 |
|
182 |
+
# ckpts paths
|
183 |
+
face_adapter = f"./checkpoints/checkpoint_105000/ip-adapter.bin"
|
184 |
+
controlnet_path = f"./checkpoints/checkpoint_105000/controlnet"
|
185 |
base_model_path = f'briaai/BRIA-2.3'
|
186 |
resolution = 1024
|
187 |
|
188 |
+
# Load ControlNet models
|
189 |
controlnet_lnmks = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
|
|
|
190 |
controlnet_canny = ControlNetModel.from_pretrained("briaai/BRIA-2.3-ControlNet-Canny",
|
191 |
+
torch_dtype=torch.float16)
|
192 |
+
|
193 |
controlnet = [controlnet_lnmks, controlnet_canny]
|
194 |
|
|
|
195 |
|
196 |
image_encoder = CLIPVisionModelWithProjection.from_pretrained(
|
197 |
f"./checkpoints/image_encoder",
|
198 |
torch_dtype=torch.float16,
|
199 |
)
|
|
|
200 |
pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
|
201 |
base_model_path,
|
202 |
controlnet=controlnet,
|