Spaces:
Runtime error
Runtime error
emirhanbilgic
commited on
Commit
•
f43f7c7
1
Parent(s):
c97a8b1
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,9 @@ from diffusers import StableDiffusionPipeline, StableDiffusionControlNetInpaintP
|
|
14 |
from PIL import Image
|
15 |
from compel import Compel
|
16 |
|
|
|
|
|
|
|
17 |
# Constants for colors
|
18 |
BG_COLOR = (0, 0, 0, 255) # gray with full opacity
|
19 |
MASK_COLOR = (255, 255, 255, 255) # white with full opacity
|
@@ -27,13 +30,13 @@ options = vision.ImageSegmenterOptions(base_options=base_options,
|
|
27 |
controlnet = ControlNetModel.from_pretrained(
|
28 |
'lllyasviel/control_v11p_sd15_inpaint',
|
29 |
torch_dtype=torch.float16,
|
30 |
-
).to(
|
31 |
|
32 |
pipe = StableDiffusionControlNetInpaintPipeline.from_pretrained(
|
33 |
'runwayml/stable-diffusion-v1-5',
|
34 |
controlnet=controlnet,
|
35 |
torch_dtype=torch.float16,
|
36 |
-
).to(
|
37 |
|
38 |
# Function to segment hair and generate mask
|
39 |
def segment_hair(image):
|
@@ -74,7 +77,7 @@ def inpaint_hair(image, prompt):
|
|
74 |
image_np = np.array(image_pil).astype(np.float32) / 255.0
|
75 |
mask_np = np.array(mask_pil.convert("L")).astype(np.float32) / 255.0
|
76 |
image_np[mask_np > 0.5] = -1.0 # Set as masked pixel
|
77 |
-
inpaint_condition = torch.from_numpy(np.expand_dims(image_np, 0).transpose(0, 3, 1, 2)).to(
|
78 |
|
79 |
# Generate inpainted image
|
80 |
generator = torch.Generator("cuda").manual_seed(42)
|
|
|
14 |
from PIL import Image
|
15 |
from compel import Compel
|
16 |
|
17 |
+
# Device configuration
|
18 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
19 |
+
|
20 |
# Constants for colors
|
21 |
BG_COLOR = (0, 0, 0, 255) # gray with full opacity
|
22 |
MASK_COLOR = (255, 255, 255, 255) # white with full opacity
|
|
|
30 |
controlnet = ControlNetModel.from_pretrained(
|
31 |
'lllyasviel/control_v11p_sd15_inpaint',
|
32 |
torch_dtype=torch.float16,
|
33 |
+
).to(device)
|
34 |
|
35 |
pipe = StableDiffusionControlNetInpaintPipeline.from_pretrained(
|
36 |
'runwayml/stable-diffusion-v1-5',
|
37 |
controlnet=controlnet,
|
38 |
torch_dtype=torch.float16,
|
39 |
+
).to(device)
|
40 |
|
41 |
# Function to segment hair and generate mask
|
42 |
def segment_hair(image):
|
|
|
77 |
image_np = np.array(image_pil).astype(np.float32) / 255.0
|
78 |
mask_np = np.array(mask_pil.convert("L")).astype(np.float32) / 255.0
|
79 |
image_np[mask_np > 0.5] = -1.0 # Set as masked pixel
|
80 |
+
inpaint_condition = torch.from_numpy(np.expand_dims(image_np, 0).transpose(0, 3, 1, 2)).to(device)
|
81 |
|
82 |
# Generate inpainted image
|
83 |
generator = torch.Generator("cuda").manual_seed(42)
|