Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,28 +5,33 @@ from diffusers import StableDiffusionInpaintPipeline
|
|
5 |
import torch
|
6 |
from diffusers.utils import load_image
|
7 |
from diffusers.pipelines.stable_diffusion import safety_checker
|
8 |
-
|
9 |
-
|
|
|
10 |
safety_checker.StableDiffusionSafetyChecker.forward = sc
|
11 |
|
12 |
-
|
13 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
14 |
"runwayml/stable-diffusion-inpainting",
|
15 |
-
|
16 |
torch_dtype=torch.float16,
|
17 |
)
|
18 |
pipe.to('cpu')
|
19 |
|
|
|
20 |
def inpaint_image(image, mask, prompt, negative_prompt):
|
21 |
-
|
22 |
-
|
|
|
23 |
return n_image
|
24 |
|
|
|
25 |
def process_files(image_file, mask_file, prompt, negative_prompt):
|
26 |
image = Image.open(image_file)
|
27 |
mask = Image.open(mask_file)
|
28 |
return inpaint_image(image, mask, prompt, negative_prompt)
|
29 |
|
|
|
30 |
with gr.Blocks() as demo:
|
31 |
gr.Markdown("## Inpainting App")
|
32 |
|
@@ -49,4 +54,4 @@ with gr.Blocks() as demo:
|
|
49 |
)
|
50 |
|
51 |
# Launch the interface
|
52 |
-
demo.launch(show_error=True)
|
|
|
5 |
import torch
|
6 |
from diffusers.utils import load_image
|
7 |
from diffusers.pipelines.stable_diffusion import safety_checker
|
8 |
+
# Bypass the safety checker
|
9 |
+
def sc(self, clip_input, images):
|
10 |
+
return images, [False for _ in images]
|
11 |
safety_checker.StableDiffusionSafetyChecker.forward = sc
|
12 |
|
13 |
+
# Initialize the inpainting pipeline
|
14 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
15 |
"runwayml/stable-diffusion-inpainting",
|
16 |
+
variant="fp16",
|
17 |
torch_dtype=torch.float16,
|
18 |
)
|
19 |
pipe.to('cpu')
|
20 |
|
21 |
+
# Inpainting function
|
22 |
def inpaint_image(image, mask, prompt, negative_prompt):
|
23 |
+
n_image = pipe(prompt, image=image, mask_image=mask, guidance_scale=5,
|
24 |
+
height=int(8*round(image.height/8)), width=int(8*round(image.width/8)),
|
25 |
+
num_inference_steps=70, negative_prompt=negative_prompt).images[0]
|
26 |
return n_image
|
27 |
|
28 |
+
# Processing uploaded files
|
29 |
def process_files(image_file, mask_file, prompt, negative_prompt):
|
30 |
image = Image.open(image_file)
|
31 |
mask = Image.open(mask_file)
|
32 |
return inpaint_image(image, mask, prompt, negative_prompt)
|
33 |
|
34 |
+
# Gradio UI
|
35 |
with gr.Blocks() as demo:
|
36 |
gr.Markdown("## Inpainting App")
|
37 |
|
|
|
54 |
)
|
55 |
|
56 |
# Launch the interface
|
57 |
+
demo.launch(show_error=True)
|