Deadmon commited on
Commit
7f4b639
·
verified ·
1 Parent(s): e92f43d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import torch
2
  import spaces
3
  from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
4
  from transformers import AutoFeatureExtractor
@@ -11,12 +11,11 @@ import gradio as gr
11
  import cv2
12
 
13
  base_model_paths = {
14
- "RealisticVisionV4": "SG161222/Realistic_Vision_V4.0_noVAE",
15
- "RealisticVisionV6": "SG161222/Realistic_Vision_V6.0_B1_noVAE",
16
  "Deliberate": "Yntec/Deliberate",
17
- "DeliberateV2": "Yntec/Deliberate2",
18
- "Dreamshaper8": "Lykon/dreamshaper-8",
19
- "EpicRealism": "emilianJR/epiCRealism"
20
  }
21
 
22
  vae_model_path = "stabilityai/sd-vae-ft-mse"
@@ -61,7 +60,7 @@ app.prepare(ctx_id=0, det_size=(640, 640))
61
  cv2.setNumThreads(1)
62
 
63
  @spaces.GPU(enable_queue=True)
64
- def generate_image(images, prompt, negative_prompt, preserve_face_structure, face_strength, likeness_strength, nfaa_negative_prompt, base_model, progress=gr.Progress(track_tqdm=True)):
65
  global ip_model, ip_model_plus
66
  base_model_path = base_model_paths[base_model]
67
  pipe = load_model(base_model_path)
@@ -87,13 +86,13 @@ def generate_image(images, prompt, negative_prompt, preserve_face_structure, fac
87
  print("Generating normal")
88
  image = ip_model.generate(
89
  prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
90
- scale=likeness_strength, width=512, height=512, num_inference_steps=30
91
  )
92
  else:
93
  print("Generating plus")
94
  image = ip_model_plus.generate(
95
  prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
96
- scale=likeness_strength, face_image=face_image, shortcut=True, s_scale=face_strength, width=512, height=512, num_inference_steps=30
97
  )
98
  print(image)
99
  return image
@@ -138,7 +137,11 @@ with gr.Blocks(css=css) as demo:
138
  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)
139
  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)
140
  likeness_strength = gr.Slider(label="Face Embed strength", value=1.0, step=0.1, minimum=0, maximum=5)
141
- nfaa_negative_prompts = gr.Textbox(label="Appended Negative Prompts", info="Negative prompts to steer generations towards safe for all audiences outputs", value="naked, bikini, skimpy, scanty, bare skin, lingerie, swimsuit, exposed, see-through")
 
 
 
 
142
  with gr.Column():
143
  gallery = gr.Gallery(label="Generated Images")
144
  style.change(fn=change_style,
@@ -147,7 +150,7 @@ with gr.Blocks(css=css) as demo:
147
  files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
148
  remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
149
  submit.click(fn=generate_image,
150
- inputs=[files,prompt,negative_prompt,preserve, face_strength, likeness_strength, nfaa_negative_prompts, base_model],
151
  outputs=gallery)
152
 
153
  gr.Markdown("")
 
1
+ rt torch
2
  import spaces
3
  from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
4
  from transformers import AutoFeatureExtractor
 
11
  import cv2
12
 
13
  base_model_paths = {
14
+ "Realistic_Vision_V4.0_noVAE": "SG161222/Realistic_Vision_V4.0_noVAE",
15
+ "Realistic_Vision_V6.0_B1_noVAE": "SG161222/Realistic_Vision_V6.0_B1_noVAE",
16
  "Deliberate": "Yntec/Deliberate",
17
+ "Deliberate2": "Yntec/Deliberate2",
18
+ "pony-diffusion": "AstraliteHeart/pony-diffusion"
 
19
  }
20
 
21
  vae_model_path = "stabilityai/sd-vae-ft-mse"
 
60
  cv2.setNumThreads(1)
61
 
62
  @spaces.GPU(enable_queue=True)
63
+ def generate_image(images, prompt, negative_prompt, preserve_face_structure, face_strength, likeness_strength, nfaa_negative_prompt, base_model, num_inference_steps, guidance_scale, width, height, progress=gr.Progress(track_tqdm=True)):
64
  global ip_model, ip_model_plus
65
  base_model_path = base_model_paths[base_model]
66
  pipe = load_model(base_model_path)
 
86
  print("Generating normal")
87
  image = ip_model.generate(
88
  prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
89
+ scale=likeness_strength, width=width, height=height, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale
90
  )
91
  else:
92
  print("Generating plus")
93
  image = ip_model_plus.generate(
94
  prompt=prompt, negative_prompt=total_negative_prompt, faceid_embeds=average_embedding,
95
+ scale=likeness_strength, face_image=face_image, shortcut=True, s_scale=face_strength, width=width, height=height, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale
96
  )
97
  print(image)
98
  return image
 
137
  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)
138
  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)
139
  likeness_strength = gr.Slider(label="Face Embed strength", value=1.0, step=0.1, minimum=0, maximum=5)
140
+ nfaa_negative_prompts = gr.Textbox(label="Appended Negative Prompts", info="Negative prompts to steer generations towards safe for all audiences outputs", value="naked, bikini, skimpy, scanty, bare skin, lingerie, swimsuit, exposed, see-through")
141
+ num_inference_steps = gr.Slider(label="Number of Inference Steps", value=30, step=1, minimum=10, maximum=100)
142
+ guidance_scale = gr.Slider(label="Guidance Scale", value=7.5, step=0.1, minimum=1, maximum=20)
143
+ width = gr.Slider(label="Width", value=512, step=64, minimum=256, maximum=1024)
144
+ height = gr.Slider(label="Height", value=512, step=64, minimum=256, maximum=1024)
145
  with gr.Column():
146
  gallery = gr.Gallery(label="Generated Images")
147
  style.change(fn=change_style,
 
150
  files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
151
  remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
152
  submit.click(fn=generate_image,
153
+ inputs=[files,prompt,negative_prompt,preserve, face_strength, likeness_strength, nfaa_negative_prompts, base_model, num_inference_steps, guidance_scale, width, height],
154
  outputs=gallery)
155
 
156
  gr.Markdown("")