Spaces:
Sleeping
Sleeping
zhiweili
commited on
Commit
·
e800866
1
Parent(s):
7742553
change pipeline to AutoPipelineForInpainting
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import mediapipe as mp
|
|
4 |
import torch
|
5 |
|
6 |
from PIL import Image
|
7 |
-
from diffusers import
|
8 |
from mediapipe.tasks import python
|
9 |
from mediapipe.tasks.python import vision
|
10 |
from scipy.ndimage import binary_dilation
|
@@ -21,14 +21,14 @@ MASK_CATEGORY = segmenter.labels
|
|
21 |
base_model = "SG161222/RealVisXL_V4.0"
|
22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
|
24 |
-
pipeline =
|
25 |
base_model, torch_dtype=torch.float16, use_safetensors=True
|
26 |
)
|
27 |
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
|
28 |
pipeline.to(device)
|
29 |
generator = torch.Generator(device).manual_seed(0)
|
30 |
|
31 |
-
def image_to_image(input_image, mask_image, prompt, negative_prompt,
|
32 |
# Generate the output image
|
33 |
output_image = pipeline(
|
34 |
generator=generator,
|
@@ -42,7 +42,7 @@ def image_to_image(input_image, mask_image, prompt, negative_prompt, category, g
|
|
42 |
|
43 |
return output_image
|
44 |
|
45 |
-
def segment_image(input_image,
|
46 |
image = mp.Image(image_format=mp.ImageFormat.SRGB, data=np.asarray(input_image))
|
47 |
segmentation_result = segmenter.segment(image)
|
48 |
category_mask = segmentation_result.category_mask
|
@@ -80,11 +80,11 @@ with gr.Blocks() as grApp:
|
|
80 |
|
81 |
generate_btn.click(
|
82 |
fn=segment_image,
|
83 |
-
inputs=[input_image,
|
84 |
outputs=[mask_image],
|
85 |
).then(
|
86 |
fn=image_to_image,
|
87 |
-
inputs=[input_image, mask_image, prompt, negative_prompt,
|
88 |
outputs=[output_image],
|
89 |
)
|
90 |
|
|
|
4 |
import torch
|
5 |
|
6 |
from PIL import Image
|
7 |
+
from diffusers import AutoPipelineForInpainting, DPMSolverMultistepScheduler
|
8 |
from mediapipe.tasks import python
|
9 |
from mediapipe.tasks.python import vision
|
10 |
from scipy.ndimage import binary_dilation
|
|
|
21 |
base_model = "SG161222/RealVisXL_V4.0"
|
22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
|
24 |
+
pipeline = AutoPipelineForInpainting.from_pretrained(
|
25 |
base_model, torch_dtype=torch.float16, use_safetensors=True
|
26 |
)
|
27 |
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
|
28 |
pipeline.to(device)
|
29 |
generator = torch.Generator(device).manual_seed(0)
|
30 |
|
31 |
+
def image_to_image(input_image, mask_image, prompt, negative_prompt, guidance_scale, num_inference_steps):
|
32 |
# Generate the output image
|
33 |
output_image = pipeline(
|
34 |
generator=generator,
|
|
|
42 |
|
43 |
return output_image
|
44 |
|
45 |
+
def segment_image(input_image, category):
|
46 |
image = mp.Image(image_format=mp.ImageFormat.SRGB, data=np.asarray(input_image))
|
47 |
segmentation_result = segmenter.segment(image)
|
48 |
category_mask = segmentation_result.category_mask
|
|
|
80 |
|
81 |
generate_btn.click(
|
82 |
fn=segment_image,
|
83 |
+
inputs=[input_image, category],
|
84 |
outputs=[mask_image],
|
85 |
).then(
|
86 |
fn=image_to_image,
|
87 |
+
inputs=[input_image, mask_image, prompt, negative_prompt, guidance_scale, num_inference_steps],
|
88 |
outputs=[output_image],
|
89 |
)
|
90 |
|