Spaces:
Running
on
Zero
Running
on
Zero
Richard Neuschulz
commited on
Commit
•
0c49d71
1
Parent(s):
3a2c3f9
trying to implement sdxl
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
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
|
@@ -11,15 +11,8 @@ import gradio as gr
|
|
11 |
import cv2
|
12 |
|
13 |
base_model_path = "SG161222/RealVisXL_V3.0"
|
14 |
-
# vae_model_path = "stabilityai/sd-vae-ft-mse"
|
15 |
image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
16 |
-
ip_ckpt =
|
17 |
-
ip_plus_ckpt = hf_hub_download(repo_id="h94/ip-adapter-faceid_sdxl.bin", 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(
|
@@ -32,10 +25,11 @@ noise_scheduler = DDIMScheduler(
|
|
32 |
steps_offset=1,
|
33 |
)
|
34 |
# vae = AutoencoderKL.from_pretrained(vae_model_path).to(dtype=torch.float16)
|
35 |
-
pipe =
|
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=safety_checker
|
@@ -44,8 +38,7 @@ pipe = StableDiffusionPipeline.from_pretrained(
|
|
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 =
|
48 |
-
ip_model_plus = IPAdapterFaceIDPlus(pipe, image_encoder_path, ip_plus_ckpt, device)
|
49 |
|
50 |
@spaces.GPU(enable_queue=True)
|
51 |
def generate_image(images, prompt, negative_prompt, preserve_face_structure, face_strength, likeness_strength, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
|
@@ -74,12 +67,7 @@ def generate_image(images, prompt, negative_prompt, preserve_face_structure, fac
|
|
74 |
prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
|
75 |
scale=likeness_strength, width=512, height=512, num_inference_steps=30
|
76 |
)
|
77 |
-
|
78 |
-
print("Generating plus")
|
79 |
-
image = ip_model_plus.generate(
|
80 |
-
prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
|
81 |
-
scale=likeness_strength, face_image=face_image, shortcut=True, s_scale=face_strength, width=512, height=512, num_inference_steps=30
|
82 |
-
)
|
83 |
print(image)
|
84 |
return image
|
85 |
|
@@ -98,8 +86,8 @@ css = '''
|
|
98 |
h1{margin-bottom: 0 !important}
|
99 |
'''
|
100 |
with gr.Blocks(css=css) as demo:
|
101 |
-
gr.Markdown("# IP-Adapter-FaceID
|
102 |
-
gr.Markdown("Demo for the [h94/IP-Adapter-FaceID model](https://huggingface.co/h94/IP-Adapter-FaceID) - Non-commercial license")
|
103 |
with gr.Row():
|
104 |
with gr.Column():
|
105 |
files = gr.Files(
|
|
|
1 |
import torch
|
2 |
import spaces
|
3 |
+
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL, StableDiffusionXLPipeline
|
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, IPAdapterFaceIDXL
|
7 |
from huggingface_hub import hf_hub_download
|
8 |
from insightface.app import FaceAnalysis
|
9 |
from insightface.utils import face_align
|
|
|
11 |
import cv2
|
12 |
|
13 |
base_model_path = "SG161222/RealVisXL_V3.0"
|
|
|
14 |
image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
15 |
+
ip_ckpt = "ip-adapter-faceid_sdxl.bin"
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
device = "cuda"
|
17 |
|
18 |
noise_scheduler = DDIMScheduler(
|
|
|
25 |
steps_offset=1,
|
26 |
)
|
27 |
# vae = AutoencoderKL.from_pretrained(vae_model_path).to(dtype=torch.float16)
|
28 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
29 |
base_model_path,
|
30 |
torch_dtype=torch.float16,
|
31 |
scheduler=noise_scheduler,
|
32 |
+
add_watermarker=False
|
33 |
# vae=vae,
|
34 |
#feature_extractor=safety_feature_extractor,
|
35 |
#safety_checker=safety_checker
|
|
|
38 |
#pipe.load_lora_weights("h94/IP-Adapter-FaceID", weight_name="ip-adapter-faceid-plusv2_sd15_lora.safetensors")
|
39 |
#pipe.fuse_lora()
|
40 |
|
41 |
+
ip_model = IPAdapterFaceIDXL(pipe, ip_ckpt, device)
|
|
|
42 |
|
43 |
@spaces.GPU(enable_queue=True)
|
44 |
def generate_image(images, prompt, negative_prompt, preserve_face_structure, face_strength, likeness_strength, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
|
|
|
67 |
prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
|
68 |
scale=likeness_strength, width=512, height=512, num_inference_steps=30
|
69 |
)
|
70 |
+
|
|
|
|
|
|
|
|
|
|
|
71 |
print(image)
|
72 |
return image
|
73 |
|
|
|
86 |
h1{margin-bottom: 0 !important}
|
87 |
'''
|
88 |
with gr.Blocks(css=css) as demo:
|
89 |
+
gr.Markdown("# IP-Adapter-FaceID SDXL demo")
|
90 |
+
gr.Markdown("Demo for the [h94/IP-Adapter-FaceID SDXL model](https://huggingface.co/h94/IP-Adapter-FaceID) - Non-commercial license")
|
91 |
with gr.Row():
|
92 |
with gr.Column():
|
93 |
files = gr.Files(
|