Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import torch
|
|
| 2 |
import spaces
|
| 3 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL, DiffusionPipeline
|
| 4 |
from transformers import AutoFeatureExtractor
|
|
|
|
| 5 |
from ip_adapter.ip_adapter_faceid import IPAdapterFaceID, IPAdapterFaceIDPlus
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
from insightface.app import FaceAnalysis
|
|
@@ -9,12 +10,17 @@ from insightface.utils import face_align
|
|
| 9 |
import gradio as gr
|
| 10 |
import cv2
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 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 |
device = "cuda"
|
| 17 |
-
|
| 18 |
noise_scheduler = DDIMScheduler(
|
| 19 |
num_train_timesteps=1000,
|
| 20 |
beta_start=0.00085,
|
|
@@ -24,11 +30,7 @@ noise_scheduler = DDIMScheduler(
|
|
| 24 |
set_alpha_to_one=False,
|
| 25 |
steps_offset=1,
|
| 26 |
)
|
| 27 |
-
|
| 28 |
vae = AutoencoderKL.from_pretrained(vae_model_path).to(dtype=torch.float16)
|
| 29 |
-
|
| 30 |
-
pipeline = DiffusionPipeline.from_pretrained("fluently/Fluently-XL-v2")
|
| 31 |
-
pipeline.load_lora_weights("ehristoforu/dalle-3-xl-v2")
|
| 32 |
pipe = pipeline.to(device)
|
| 33 |
|
| 34 |
ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
|
|
@@ -49,6 +51,7 @@ def generate_image(images, prompt, negative_prompt, preserve_face_structure, fac
|
|
| 49 |
faceid_all_embeds.append(faceid_embed)
|
| 50 |
if(first_iteration and preserve_face_structure):
|
| 51 |
face_image = face_align.norm_crop(face, landmark=faces[0].kps, image_size=224)
|
|
|
|
| 52 |
first_iteration = False
|
| 53 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
| 54 |
total_negative_prompt = f"{negative_prompt} {nfaa_negative_prompt}"
|
|
|
|
| 2 |
import spaces
|
| 3 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL, DiffusionPipeline
|
| 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
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
import cv2
|
| 12 |
|
| 13 |
+
pipeline = DiffusionPipeline.from_pretrained("fluently/Fluently-XL-v2")
|
| 14 |
+
pipeline.load_lora_weights("ehristoforu/dalle-3-xl-v2")
|
| 15 |
+
|
| 16 |
vae_model_path = "stabilityai/sd-vae-ft-mse"
|
| 17 |
image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
| 18 |
ip_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid_sd15.bin", repo_type="model")
|
| 19 |
ip_plus_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid-plusv2_sd15.bin", repo_type="model")
|
| 20 |
+
safety_model_id = "CompVis/stable-diffusion-safety-checker"
|
| 21 |
+
safety_feature_extractor = AutoFeatureExtractor.from_pretrained(safety_model_id)
|
| 22 |
+
safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id)
|
| 23 |
device = "cuda"
|
|
|
|
| 24 |
noise_scheduler = DDIMScheduler(
|
| 25 |
num_train_timesteps=1000,
|
| 26 |
beta_start=0.00085,
|
|
|
|
| 30 |
set_alpha_to_one=False,
|
| 31 |
steps_offset=1,
|
| 32 |
)
|
|
|
|
| 33 |
vae = AutoencoderKL.from_pretrained(vae_model_path).to(dtype=torch.float16)
|
|
|
|
|
|
|
|
|
|
| 34 |
pipe = pipeline.to(device)
|
| 35 |
|
| 36 |
ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
|
|
|
|
| 51 |
faceid_all_embeds.append(faceid_embed)
|
| 52 |
if(first_iteration and preserve_face_structure):
|
| 53 |
face_image = face_align.norm_crop(face, landmark=faces[0].kps, image_size=224)
|
| 54 |
+
# you can also segment the face
|
| 55 |
first_iteration = False
|
| 56 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
| 57 |
total_negative_prompt = f"{negative_prompt} {nfaa_negative_prompt}"
|