Spaces:
Sleeping
Sleeping
Arnold Manzano
commited on
Commit
·
9aed7c0
1
Parent(s):
49dd5a4
remove noise
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionInpaintPipeline, LCMScheduler
|
| 4 |
from PIL import Image
|
| 5 |
-
import numpy as np
|
| 6 |
|
| 7 |
# 1. Load the most compatible inpainting model
|
| 8 |
model_id = "runwayml/stable-diffusion-inpainting"
|
|
@@ -41,27 +40,15 @@ def predict(image_data, prompt):
|
|
| 41 |
base_image = raw_bg.resize((new_w, new_h), Image.LANCZOS)
|
| 42 |
mask_image = raw_mask.resize((new_w, new_h), Image.NEAREST)
|
| 43 |
|
| 44 |
-
# 2. NOISE INJECTION (The Fix)
|
| 45 |
-
# This manually overwrites the masked area with random colors.
|
| 46 |
-
# This forces the AI to stop "respecting" the floor and start "creating" the cat.
|
| 47 |
-
img_array = np.array(base_image)
|
| 48 |
-
mask_array = np.array(mask_image)
|
| 49 |
-
# Create random noise
|
| 50 |
-
noise = np.random.randint(0, 255, img_array.shape, dtype=np.uint8)
|
| 51 |
-
# Where the mask is white (>128), replace original pixels with noise
|
| 52 |
-
img_array[mask_array > 128] = noise[mask_array > 128]
|
| 53 |
-
noised_base = Image.fromarray(img_array)
|
| 54 |
-
|
| 55 |
# return mask_image.resize((orig_w, orig_h), Image.NEAREST)
|
| 56 |
|
| 57 |
# 3. RUN THE MODEL
|
| 58 |
result = pipe(
|
| 59 |
prompt=prompt,
|
| 60 |
-
image=
|
| 61 |
mask_image=mask_image,
|
| 62 |
num_inference_steps=20, # Increased slightly for better detail on CPU
|
| 63 |
guidance_scale=8.0, # Increased to make the "Cat" more likely to appear
|
| 64 |
-
strength=1.0 # Complete replacement
|
| 65 |
).images[0]
|
| 66 |
|
| 67 |
|
|
|
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionInpaintPipeline, LCMScheduler
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
# 1. Load the most compatible inpainting model
|
| 7 |
model_id = "runwayml/stable-diffusion-inpainting"
|
|
|
|
| 40 |
base_image = raw_bg.resize((new_w, new_h), Image.LANCZOS)
|
| 41 |
mask_image = raw_mask.resize((new_w, new_h), Image.NEAREST)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# return mask_image.resize((orig_w, orig_h), Image.NEAREST)
|
| 44 |
|
| 45 |
# 3. RUN THE MODEL
|
| 46 |
result = pipe(
|
| 47 |
prompt=prompt,
|
| 48 |
+
image=base_image, # Use the noised version!
|
| 49 |
mask_image=mask_image,
|
| 50 |
num_inference_steps=20, # Increased slightly for better detail on CPU
|
| 51 |
guidance_scale=8.0, # Increased to make the "Cat" more likely to appear
|
|
|
|
| 52 |
).images[0]
|
| 53 |
|
| 54 |
|