Prgckwb commited on
Commit
aed67d7
1 Parent(s): 4fe0601

:tada: add negative embedding

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -47,12 +47,13 @@ class Input:
47
  guidance_scale: float = 7.5
48
  num_inference_step: int = 28
49
  num_images: int = 4
 
50
 
51
  def to_list(self):
52
  return [
53
  self.prompt, self.model_id, self.negative_prompt,
54
  self.width, self.height, self.guidance_scale,
55
- self.num_inference_step, self.num_images
56
  ]
57
 
58
 
@@ -85,12 +86,14 @@ def inference(
85
  guidance_scale: float = 7.5,
86
  num_inference_steps: int = 50,
87
  num_images: int = 4,
 
88
  progress=gr.Progress(track_tqdm=True),
89
  ) -> Image.Image:
90
  progress(0, "Starting inference...")
91
 
92
  global current_model_id, pipe
93
 
 
94
  if model_id != current_model_id:
95
  try:
96
  # For NOT Diffusers' Models
@@ -106,12 +109,17 @@ def inference(
106
  except Exception as e:
107
  raise gr.Error(str(e))
108
 
 
 
 
 
109
  # Load Textual Inversion
110
  pipe.load_textual_inversion(
111
  "checkpoints/embeddings/BadNegAnatomyV1 neg.pt", token='BadNegAnatomyV1-neg'
112
  )
113
 
114
  # Generation
 
115
  images = pipe(
116
  prompt,
117
  negative_prompt=negative_prompt,
@@ -146,8 +154,9 @@ if __name__ == "__main__":
146
  value="stabilityai/stable-diffusion-3-medium-diffusers",
147
  )
148
 
 
149
  with gr.Accordion("Additional Settings", open=False):
150
- negative_prompt = gr.Text(label="Negative Prompt", value="")
151
 
152
  with gr.Row():
153
  width = gr.Number(label="Width", value=512, step=64, minimum=64, maximum=2048)
@@ -159,6 +168,9 @@ if __name__ == "__main__":
159
  label="Num Inference Steps", value=50, minimum=1, maximum=100, step=2
160
  )
161
 
 
 
 
162
  with gr.Column():
163
  output_image = gr.Image(label="Image", type="pil")
164
 
@@ -171,6 +183,7 @@ if __name__ == "__main__":
171
  guidance_scale,
172
  num_inference_step,
173
  num_images,
 
174
  ]
175
 
176
  btn = gr.Button("Generate")
 
47
  guidance_scale: float = 7.5
48
  num_inference_step: int = 28
49
  num_images: int = 4
50
+ safety_checker: bool = True
51
 
52
  def to_list(self):
53
  return [
54
  self.prompt, self.model_id, self.negative_prompt,
55
  self.width, self.height, self.guidance_scale,
56
+ self.num_inference_step, self.num_images, self.safety_checker
57
  ]
58
 
59
 
 
86
  guidance_scale: float = 7.5,
87
  num_inference_steps: int = 50,
88
  num_images: int = 4,
89
+ safety_checker: bool = True,
90
  progress=gr.Progress(track_tqdm=True),
91
  ) -> Image.Image:
92
  progress(0, "Starting inference...")
93
 
94
  global current_model_id, pipe
95
 
96
+ progress(0.1, 'Loading pipeline...')
97
  if model_id != current_model_id:
98
  try:
99
  # For NOT Diffusers' Models
 
109
  except Exception as e:
110
  raise gr.Error(str(e))
111
 
112
+ if not safety_checker:
113
+ pipe.safety_checker = None
114
+
115
+ progress(0.3, 'Loading Textual Inversion...')
116
  # Load Textual Inversion
117
  pipe.load_textual_inversion(
118
  "checkpoints/embeddings/BadNegAnatomyV1 neg.pt", token='BadNegAnatomyV1-neg'
119
  )
120
 
121
  # Generation
122
+ progress(0.4, 'Generating images...')
123
  images = pipe(
124
  prompt,
125
  negative_prompt=negative_prompt,
 
154
  value="stabilityai/stable-diffusion-3-medium-diffusers",
155
  )
156
 
157
+ # Additional Input Settings
158
  with gr.Accordion("Additional Settings", open=False):
159
+ negative_prompt = gr.Text(label="Negative Prompt", value="", )
160
 
161
  with gr.Row():
162
  width = gr.Number(label="Width", value=512, step=64, minimum=64, maximum=2048)
 
168
  label="Num Inference Steps", value=50, minimum=1, maximum=100, step=2
169
  )
170
 
171
+ with gr.Row():
172
+ safety_checker = gr.Checkbox(value=True, label='Use Safety Checker')
173
+
174
  with gr.Column():
175
  output_image = gr.Image(label="Image", type="pil")
176
 
 
183
  guidance_scale,
184
  num_inference_step,
185
  num_images,
186
+ safety_checker
187
  ]
188
 
189
  btn = gr.Button("Generate")