Spaces:
Build error
Build error
Commit
·
cc7ee18
1
Parent(s):
bdcf68c
Update app.py
Browse files
app.py
CHANGED
@@ -184,6 +184,8 @@ def txt_to_img(model_path, prompt, n_images, neg_prompt, guidance, steps, width,
|
|
184 |
|
185 |
# update_state(f"Done. Seed: {seed}")
|
186 |
|
|
|
|
|
187 |
def img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance, steps, width, height, generator, seed):
|
188 |
|
189 |
print(f"{datetime.datetime.now()} img_to_img, model: {model_path}")
|
@@ -234,6 +236,23 @@ def img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance
|
|
234 |
callback=pipe_callback)
|
235 |
|
236 |
# update_state(f"Done. Seed: {seed}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
|
239 |
# css = """.finetuned-diffusion-div div{display:inline-flex;align-items:center;gap:.8rem;font-size:1.75rem}.finetuned-diffusion-div div h1{font-weight:900;margin-bottom:7px}.finetuned-diffusion-div p{margin-bottom:10px;font-size:94%}a{text-decoration:underline}.tabs{margin-top:0;margin-bottom:0}#gallery{min-height:20rem}
|
|
|
184 |
|
185 |
# update_state(f"Done. Seed: {seed}")
|
186 |
|
187 |
+
return replace_nsfw_images(result)
|
188 |
+
|
189 |
def img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance, steps, width, height, generator, seed):
|
190 |
|
191 |
print(f"{datetime.datetime.now()} img_to_img, model: {model_path}")
|
|
|
236 |
callback=pipe_callback)
|
237 |
|
238 |
# update_state(f"Done. Seed: {seed}")
|
239 |
+
|
240 |
+
return replace_nsfw_images(result)
|
241 |
+
|
242 |
+
def replace_nsfw_images(results):
|
243 |
+
|
244 |
+
if is_colab:
|
245 |
+
return results.images
|
246 |
+
|
247 |
+
for i in range(len(results.images)):
|
248 |
+
if results.nsfw_content_detected[i]:
|
249 |
+
orig_img = results.images[i]
|
250 |
+
results.images[i] = Image.open("nsfw.png")
|
251 |
+
nsfw_label = f"NSFW: {results.nsfw_content_prob[i]:.2f}"
|
252 |
+
img_array = np.concatenate([np.array(orig_img), np.array(results.images[i])], axis=1)
|
253 |
+
display(Image.fromarray(img_array), caption=nsfw_label)
|
254 |
+
|
255 |
+
return results.images
|
256 |
|
257 |
|
258 |
# css = """.finetuned-diffusion-div div{display:inline-flex;align-items:center;gap:.8rem;font-size:1.75rem}.finetuned-diffusion-div div h1{font-weight:900;margin-bottom:7px}.finetuned-diffusion-div p{margin-bottom:10px;font-size:94%}a{text-decoration:underline}.tabs{margin-top:0;margin-bottom:0}#gallery{min-height:20rem}
|