waveydaveygravy commited on
Commit
248a303
1 Parent(s): 21aa66d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import torch
 
2
  import spaces
3
  from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
4
  from transformers import AutoFeatureExtractor
@@ -10,15 +11,15 @@ 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
 
@@ -48,11 +49,12 @@ ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
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, num_samples, seed, guidance_scale, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
 
52
  pipe.to(device)
53
- app = FaceAnalysis(name="buffalo_l", providers=['CPUExecutionProvider'])
54
  app.prepare(ctx_id=0, det_size=(640, 640))
55
-
56
  faceid_all_embeds = []
57
  first_iteration = True
58
  for image in images:
@@ -78,8 +80,10 @@ def generate_image(images, prompt, negative_prompt, preserve_face_structure, fac
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, num_samples=num_samples, seed=seed, guidance_scale=guidance_scale, width=512, height=512, num_inference_steps=30
82
  )
 
 
83
  print(image)
84
  return image
85
 
@@ -119,7 +123,7 @@ with gr.Blocks(css=css) as demo:
119
  preserve = gr.Checkbox(label="Preserve Face Structure", info="Higher quality, less versatility (the face structure of your first photo will be preserved). Unchecking this will use the v1 model.", value=True)
120
  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)
121
  likeness_strength = gr.Slider(label="Face Embed strength", value=1.0, step=0.1, minimum=0, maximum=5)
122
- seed = gr.Slider(label="seed", value=1000, step=100, minimum=100, maximum=2000)
123
  guidance_scale = gr.Slider(label="CFG", value=1.0, step=0.5, minimum=0, maximum=20)
124
  num_samples = gr.Slider(label="samples", info="Only applied if preserve face structure is checked", value=1, step=1, minimum=1, maximum=16)
125
  nfaa_negative_prompts = gr.Textbox(label="Appended Negative Prompts 4 realistic vision model", info="Negative prompts to steer generations towards safe for all audiences outputs", value="deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck")
@@ -131,9 +135,10 @@ with gr.Blocks(css=css) as demo:
131
  files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
132
  remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
133
  submit.click(fn=generate_image,
134
- inputs=[files,prompt,negative_prompt,preserve, face_strength, likeness_strength, seed, guidance_scale, num_samples, nfaa_negative_prompts],
135
  outputs=gallery)
136
 
137
- gr.Markdown("safety filter is on")
138
-
139
  demo.launch(share=True)
 
 
1
  import torch
2
+ from torch import cuda
3
  import spaces
4
  from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
5
  from transformers import AutoFeatureExtractor
 
11
  import gradio as gr
12
  import cv2
13
 
14
+ base_model_path = "stablediffusionapi/samaritan-3d-cartoon"
15
  vae_model_path = "stabilityai/sd-vae-ft-mse"
16
  image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
17
  ip_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid_sd15.bin", repo_type="model")
18
  ip_plus_ckpt = hf_hub_download(repo_id="h94/IP-Adapter-FaceID", filename="ip-adapter-faceid-plusv2_sd15.bin", repo_type="model")
19
 
20
+ safety_model_id = None
21
+ safety_feature_extractor = None
22
+ safety_checker = None
23
 
24
  device = "cuda"
25
 
 
49
  ip_model_plus = IPAdapterFaceIDPlus(pipe, image_encoder_path, ip_plus_ckpt, device)
50
 
51
  @spaces.GPU(enable_queue=True)
52
+ def generate_image(images, prompt, negative_prompt, preserve_face_structure, face_strength, likeness_strength, num_samples, guidance_scale, nfaa_negative_prompt, progress=gr.Progress(track_tqdm=True)):
53
+ print(cuda.memory_summary())
54
  pipe.to(device)
55
+ app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider','CPUExecutionProvider'])
56
  app.prepare(ctx_id=0, det_size=(640, 640))
57
+ print(cuda.memory_summary())
58
  faceid_all_embeds = []
59
  first_iteration = True
60
  for image in images:
 
80
  print("Generating plus")
81
  image = ip_model_plus.generate(
82
  prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
83
+ scale=likeness_strength, face_image=face_image, shortcut=True, s_scale=face_strength, num_samples=num_samples, guidance_scale=guidance_scale, width=512, height=512, num_inference_steps=30
84
  )
85
+
86
+ print(cuda.memory_summary())
87
  print(image)
88
  return image
89
 
 
123
  preserve = gr.Checkbox(label="Preserve Face Structure", info="Higher quality, less versatility (the face structure of your first photo will be preserved). Unchecking this will use the v1 model.", value=True)
124
  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)
125
  likeness_strength = gr.Slider(label="Face Embed strength", value=1.0, step=0.1, minimum=0, maximum=5)
126
+ #seed = gr.Slider(label="seed", value=1000, step=100, minimum=100, maximum=2000)
127
  guidance_scale = gr.Slider(label="CFG", value=1.0, step=0.5, minimum=0, maximum=20)
128
  num_samples = gr.Slider(label="samples", info="Only applied if preserve face structure is checked", value=1, step=1, minimum=1, maximum=16)
129
  nfaa_negative_prompts = gr.Textbox(label="Appended Negative Prompts 4 realistic vision model", info="Negative prompts to steer generations towards safe for all audiences outputs", value="deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck")
 
135
  files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
136
  remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
137
  submit.click(fn=generate_image,
138
+ inputs=[files,prompt,negative_prompt,preserve, face_strength, likeness_strength, num_samples, guidance_scale, nfaa_negative_prompts],
139
  outputs=gallery)
140
 
141
+ gr.Markdown("safety filter is off, enable in lines 20-23")
142
+ print(cuda.memory_summary())
143
  demo.launch(share=True)
144
+