Spaces:
Running
on
Zero
Running
on
Zero
Richard Neuschulz
commited on
Commit
·
0f20da3
1
Parent(s):
62becae
changed UI a bit
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
40 |
ip_model = ipown.IPAdapterFaceIDXL(pipe, ip_ckpt, device)
|
41 |
|
42 |
@spaces.GPU(enable_queue=True)
|
43 |
-
def generate_image(images, prompt, negative_prompt, preserve_face_structure, face_strength, likeness_strength,
|
44 |
pipe.to(device)
|
45 |
app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
46 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
@@ -52,29 +52,20 @@ def generate_image(images, prompt, negative_prompt, preserve_face_structure, fac
|
|
52 |
faces = app.get(face)
|
53 |
faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
54 |
faceid_all_embeds.append(faceid_embed)
|
55 |
-
|
56 |
-
face_image = face_align.norm_crop(face, landmark=faces[0].kps, image_size=640) # you can also segment the face
|
57 |
-
first_iteration = False
|
58 |
-
|
59 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
60 |
|
61 |
-
total_negative_prompt =
|
62 |
|
63 |
-
print("Generating
|
64 |
image = ip_model.generate(
|
65 |
prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
|
66 |
-
scale=likeness_strength, width=1024, height=1024, guidance_scale=
|
67 |
)
|
68 |
|
69 |
print(image)
|
70 |
return image
|
71 |
|
72 |
-
def change_style(style):
|
73 |
-
if style == "Photorealistic":
|
74 |
-
return(gr.update(value=True), gr.update(value=1.3), gr.update(value=1.0))
|
75 |
-
else:
|
76 |
-
return(gr.update(value=True), gr.update(value=0.1), gr.update(value=0.8))
|
77 |
-
|
78 |
def swap_to_gallery(images):
|
79 |
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
80 |
|
@@ -85,7 +76,7 @@ h1{margin-bottom: 0 !important}
|
|
85 |
'''
|
86 |
with gr.Blocks(css=css) as demo:
|
87 |
gr.Markdown("# IP-Adapter-FaceID SDXL demo")
|
88 |
-
gr.Markdown("Demo for the [h94/IP-Adapter-FaceID SDXL model](https://huggingface.co/h94/IP-Adapter-FaceID)
|
89 |
with gr.Row():
|
90 |
with gr.Column():
|
91 |
files = gr.Files(
|
@@ -99,18 +90,15 @@ with gr.Blocks(css=css) as demo:
|
|
99 |
info="Try something like 'a photo of a man/woman/person'",
|
100 |
placeholder="A photo of a [man/woman/person]...")
|
101 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality")
|
102 |
-
style =
|
103 |
submit = gr.Button("Submit")
|
104 |
-
with gr.Accordion(open=
|
105 |
-
preserve =
|
106 |
face_strength = gr.Slider(label="Face Structure strength", info="Only applied if preserve face structure is checked", value=1.3, step=0.1, minimum=0, maximum=3)
|
107 |
likeness_strength = gr.Slider(label="Face Embed strength", value=1.0, step=0.1, minimum=0, maximum=5)
|
108 |
nfaa_negative_prompts = gr.Textbox(label="Appended Negative Prompts", info="Negative prompts to steer generations towards safe for all audiences outputs", value="low quality, worst quality")
|
109 |
with gr.Column():
|
110 |
gallery = gr.Gallery(label="Generated Images")
|
111 |
-
style.change(fn=change_style,
|
112 |
-
inputs=style,
|
113 |
-
outputs=[preserve, face_strength, likeness_strength])
|
114 |
files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
|
115 |
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
|
116 |
submit.click(fn=generate_image,
|
|
|
40 |
ip_model = ipown.IPAdapterFaceIDXL(pipe, ip_ckpt, device)
|
41 |
|
42 |
@spaces.GPU(enable_queue=True)
|
43 |
+
def generate_image(images, prompt, negative_prompt, preserve_face_structure, face_strength, likeness_strength, progress=gr.Progress(track_tqdm=True)):
|
44 |
pipe.to(device)
|
45 |
app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
46 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
|
|
52 |
faces = app.get(face)
|
53 |
faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
54 |
faceid_all_embeds.append(faceid_embed)
|
55 |
+
|
|
|
|
|
|
|
56 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
57 |
|
58 |
+
total_negative_prompt = negative_prompt
|
59 |
|
60 |
+
print("Generating SDXL")
|
61 |
image = ip_model.generate(
|
62 |
prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
|
63 |
+
scale=likeness_strength, width=1024, height=1024, guidance_scale=face_strength, num_inference_steps=30
|
64 |
)
|
65 |
|
66 |
print(image)
|
67 |
return image
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
def swap_to_gallery(images):
|
70 |
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
71 |
|
|
|
76 |
'''
|
77 |
with gr.Blocks(css=css) as demo:
|
78 |
gr.Markdown("# IP-Adapter-FaceID SDXL demo")
|
79 |
+
gr.Markdown("My own Demo for the [h94/IP-Adapter-FaceID SDXL model](https://huggingface.co/h94/IP-Adapter-FaceID).")
|
80 |
with gr.Row():
|
81 |
with gr.Column():
|
82 |
files = gr.Files(
|
|
|
90 |
info="Try something like 'a photo of a man/woman/person'",
|
91 |
placeholder="A photo of a [man/woman/person]...")
|
92 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality")
|
93 |
+
style = "Photorealistic"
|
94 |
submit = gr.Button("Submit")
|
95 |
+
with gr.Accordion(open=True, label="Advanced Options"):
|
96 |
+
preserve = False
|
97 |
face_strength = gr.Slider(label="Face Structure strength", info="Only applied if preserve face structure is checked", value=1.3, step=0.1, minimum=0, maximum=3)
|
98 |
likeness_strength = gr.Slider(label="Face Embed strength", value=1.0, step=0.1, minimum=0, maximum=5)
|
99 |
nfaa_negative_prompts = gr.Textbox(label="Appended Negative Prompts", info="Negative prompts to steer generations towards safe for all audiences outputs", value="low quality, worst quality")
|
100 |
with gr.Column():
|
101 |
gallery = gr.Gallery(label="Generated Images")
|
|
|
|
|
|
|
102 |
files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
|
103 |
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
|
104 |
submit.click(fn=generate_image,
|