Spaces:
Running
on
Zero
Running
on
Zero
Richard Neuschulz
commited on
Commit
•
606515a
1
Parent(s):
c1a6685
anohter small change
Browse files
app.py
CHANGED
@@ -1,3 +1,54 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
gr.load("models/h94/IP-Adapter-FaceID").launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
from insightface.app import FaceAnalysis
|
4 |
+
import torch
|
5 |
+
|
6 |
+
app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
7 |
+
app.prepare(ctx_id=0, det_size=(640, 640))
|
8 |
+
|
9 |
+
image = cv2.imread("person.jpg")
|
10 |
+
faces = app.get(image)
|
11 |
+
|
12 |
+
faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
13 |
+
|
14 |
+
import torch
|
15 |
+
from diffusers import StableDiffusionXLPipeline, DDIMScheduler
|
16 |
+
from PIL import Image
|
17 |
+
|
18 |
+
from ip_adapter.ip_adapter_faceid import IPAdapterFaceIDXL
|
19 |
+
|
20 |
+
base_model_path = "SG161222/RealVisXL_V3.0"
|
21 |
+
ip_ckpt = "ip-adapter-faceid_sdxl.bin"
|
22 |
+
device = "cuda"
|
23 |
+
|
24 |
+
noise_scheduler = DDIMScheduler(
|
25 |
+
num_train_timesteps=1000,
|
26 |
+
beta_start=0.00085,
|
27 |
+
beta_end=0.012,
|
28 |
+
beta_schedule="scaled_linear",
|
29 |
+
clip_sample=False,
|
30 |
+
set_alpha_to_one=False,
|
31 |
+
steps_offset=1,
|
32 |
+
)
|
33 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
34 |
+
base_model_path,
|
35 |
+
torch_dtype=torch.float16,
|
36 |
+
scheduler=noise_scheduler,
|
37 |
+
add_watermarker=False,
|
38 |
+
)
|
39 |
+
|
40 |
+
# load ip-adapter
|
41 |
+
ip_model = IPAdapterFaceIDXL(pipe, ip_ckpt, device)
|
42 |
+
|
43 |
+
# generate image
|
44 |
+
prompt = "A closeup shot of a beautiful Asian teenage girl in a white dress wearing small silver earrings in the garden, under the soft morning light"
|
45 |
+
negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
|
46 |
+
|
47 |
+
images = ip_model.generate(
|
48 |
+
prompt=prompt, negative_prompt=negative_prompt, faceid_embeds=faceid_embeds, num_samples=2,
|
49 |
+
width=1024, height=1024,
|
50 |
+
num_inference_steps=30, guidance_scale=7.5, seed=2023
|
51 |
+
)
|
52 |
+
|
53 |
+
gr.load("models/h94/IP-Adapter-FaceID").launch()
|
54 |
|
|