Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,24 @@ import torch
|
|
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
|
8 |
import gradio as gr
|
9 |
import cv2
|
10 |
|
11 |
-
base_model_path = "SG161222/
|
12 |
vae_model_path = "stabilityai/sd-vae-ft-mse"
|
13 |
image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
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(
|
@@ -30,14 +36,17 @@ pipe = StableDiffusionPipeline.from_pretrained(
|
|
30 |
base_model_path,
|
31 |
torch_dtype=torch.float16,
|
32 |
scheduler=noise_scheduler,
|
33 |
-
vae=vae
|
|
|
|
|
34 |
).to(device)
|
35 |
|
36 |
-
#
|
|
|
|
|
37 |
ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
|
38 |
ip_model_plus = IPAdapterFaceIDPlus(pipe, image_encoder_path, ip_plus_ckpt, device)
|
39 |
|
40 |
-
# Initialize the FaceAnalysis application
|
41 |
app = FaceAnalysis(name="buffalo_l", providers=['CPUExecutionProvider'])
|
42 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
43 |
|
|
|
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
|
10 |
import gradio as gr
|
11 |
import cv2
|
12 |
|
13 |
+
base_model_path = "SG161222/Realistic_Vision_V4.0_noVAE"
|
14 |
vae_model_path = "stabilityai/sd-vae-ft-mse"
|
15 |
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(
|
|
|
36 |
base_model_path,
|
37 |
torch_dtype=torch.float16,
|
38 |
scheduler=noise_scheduler,
|
39 |
+
vae=vae,
|
40 |
+
feature_extractor=safety_feature_extractor,
|
41 |
+
safety_checker=None # <--- Disable 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 |
|
|
|
50 |
app = FaceAnalysis(name="buffalo_l", providers=['CPUExecutionProvider'])
|
51 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
52 |
|