Update app.py
Browse files
app.py
CHANGED
|
@@ -38,19 +38,35 @@ def resize(value,img):
|
|
| 38 |
|
| 39 |
def infer(source_img, prompt, guide, steps, seed, strength):
|
| 40 |
generator = torch.Generator('cpu').manual_seed(seed)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
images = []
|
| 47 |
-
safe_image = Image.open(r"unsafe.png")
|
| 48 |
-
|
| 49 |
for i, image in enumerate(images_list["images"]):
|
| 50 |
-
if(
|
| 51 |
-
|
|
|
|
| 52 |
else:
|
| 53 |
-
images.append(image)
|
| 54 |
return images
|
| 55 |
|
| 56 |
print("Great sylvain ! Everything is working fine !")
|
|
|
|
| 38 |
|
| 39 |
def infer(source_img, prompt, guide, steps, seed, strength):
|
| 40 |
generator = torch.Generator('cpu').manual_seed(seed)
|
| 41 |
+
|
| 42 |
+
# Ensure source_img is a valid path and load image properly
|
| 43 |
+
if isinstance(source_img, str):
|
| 44 |
+
source_image = Image.open(source_img).convert("RGB")
|
| 45 |
+
elif isinstance(source_img, Image.Image):
|
| 46 |
+
source_image = source_img.convert("RGB")
|
| 47 |
+
else:
|
| 48 |
+
raise ValueError("Unsupported input type for source_img")
|
| 49 |
+
|
| 50 |
+
# Resize image
|
| 51 |
+
source_image = source_image.resize((512, 512), Image.Resampling.LANCZOS)
|
| 52 |
+
|
| 53 |
+
# Inference
|
| 54 |
+
images_list = img_pipe(
|
| 55 |
+
[prompt],
|
| 56 |
+
init_image=source_image,
|
| 57 |
+
strength=strength,
|
| 58 |
+
guidance_scale=guide,
|
| 59 |
+
num_inference_steps=steps,
|
| 60 |
+
generator=generator
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
images = []
|
|
|
|
|
|
|
| 64 |
for i, image in enumerate(images_list["images"]):
|
| 65 |
+
# if NSFW detected, show safe_image (optional)
|
| 66 |
+
if images_list["nsfw_content_detected"][i]:
|
| 67 |
+
images.append(image) # or append `safe_image`
|
| 68 |
else:
|
| 69 |
+
images.append(image)
|
| 70 |
return images
|
| 71 |
|
| 72 |
print("Great sylvain ! Everything is working fine !")
|