Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,6 @@ import torch
|
|
2 |
import spaces
|
3 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
|
4 |
from transformers import AutoFeatureExtractor
|
5 |
-
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
6 |
-
from ip_adapter.ip_adapter_faceid import IPAdapterFaceID, IPAdapterFaceIDPlus
|
7 |
from huggingface_hub import hf_hub_download
|
8 |
from insightface.app import FaceAnalysis
|
9 |
from insightface.utils import face_align
|
@@ -16,10 +14,6 @@ image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
|
16 |
ip_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid_sd15.bin", repo_type="model")
|
17 |
ip_plus_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid-plusv2_sd15.bin", repo_type="model")
|
18 |
|
19 |
-
safety_model_id = "CompVis/stable-diffusion-safety-checker"
|
20 |
-
safety_feature_extractor = AutoFeatureExtractor.from_pretrained(safety_model_id)
|
21 |
-
safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id)
|
22 |
-
|
23 |
device = "cuda"
|
24 |
|
25 |
noise_scheduler = DDIMScheduler(
|
@@ -37,13 +31,9 @@ pipe = StableDiffusionPipeline.from_pretrained(
|
|
37 |
torch_dtype=torch.float16,
|
38 |
scheduler=noise_scheduler,
|
39 |
vae=vae,
|
40 |
-
|
41 |
-
safety_checker=safety_checker
|
42 |
).to(device)
|
43 |
|
44 |
-
#pipe.load_lora_weights("h94/IP-Adapter-FaceID", weight_name="ip-adapter-faceid-plusv2_sd15_lora.safetensors")
|
45 |
-
#pipe.fuse_lora()
|
46 |
-
|
47 |
ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
|
48 |
ip_model_plus = IPAdapterFaceIDPlus(pipe, image_encoder_path, ip_plus_ckpt, device)
|
49 |
|
@@ -62,7 +52,7 @@ def generate_image(images, prompt, negative_prompt, preserve_face_structure, fac
|
|
62 |
faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
63 |
faceid_all_embeds.append(faceid_embed)
|
64 |
if(first_iteration and preserve_face_structure):
|
65 |
-
face_image = face_align.norm_crop(face, landmark=faces[0].kps, image_size=224)
|
66 |
first_iteration = False
|
67 |
|
68 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
|
|
2 |
import spaces
|
3 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
|
4 |
from transformers import AutoFeatureExtractor
|
|
|
|
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
from insightface.app import FaceAnalysis
|
7 |
from insightface.utils import face_align
|
|
|
14 |
ip_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid_sd15.bin", repo_type="model")
|
15 |
ip_plus_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid-plusv2_sd15.bin", repo_type="model")
|
16 |
|
|
|
|
|
|
|
|
|
17 |
device = "cuda"
|
18 |
|
19 |
noise_scheduler = DDIMScheduler(
|
|
|
31 |
torch_dtype=torch.float16,
|
32 |
scheduler=noise_scheduler,
|
33 |
vae=vae,
|
34 |
+
safety_checker=None # Disconnected the safety checker
|
|
|
35 |
).to(device)
|
36 |
|
|
|
|
|
|
|
37 |
ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
|
38 |
ip_model_plus = IPAdapterFaceIDPlus(pipe, image_encoder_path, ip_plus_ckpt, device)
|
39 |
|
|
|
52 |
faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
53 |
faceid_all_embeds.append(faceid_embed)
|
54 |
if(first_iteration and preserve_face_structure):
|
55 |
+
face_image = face_align.norm_crop(face, landmark=faces[0].kps, image_size=224)
|
56 |
first_iteration = False
|
57 |
|
58 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|