Spaces:
Runtime error
Runtime error
Commit
·
52722af
1
Parent(s):
e7953d7
Update inference.py
Browse files- inference.py +30 -1
inference.py
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import numpy
|
| 3 |
from PIL import Image
|
| 4 |
from torchvision import transforms
|
| 5 |
from diffusers import StableDiffusionInpaintPipeline
|
| 6 |
-
from diffusers import DPMSolverMultistepScheduler
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import torch
|
| 3 |
import numpy
|
| 4 |
from PIL import Image
|
| 5 |
from torchvision import transforms
|
| 6 |
from diffusers import StableDiffusionInpaintPipeline
|
| 7 |
+
from diffusers import DPMSolverMultistepScheduler, UniPCMultistepScheduler
|
| 8 |
|
| 9 |
+
@torch.inference_mode()
|
| 10 |
+
@st.experimental_singleton(max_entries=5)
|
| 11 |
+
def get_pipeline():
|
| 12 |
+
pipe = StableDiffusionInpaintPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting",
|
| 13 |
+
torch_dtype=torch.float16)
|
| 14 |
+
pipe.to(device)
|
| 15 |
+
pipe.enable_xformers_memory_efficient_attention()
|
| 16 |
+
pipe.set_progress_bar_config(disable=True)
|
| 17 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 18 |
+
return pipe
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def inpainting(image,
|
| 22 |
+
mask_image,
|
| 23 |
+
prompt,
|
| 24 |
+
negative_prompt,
|
| 25 |
+
num_inference_steps=20,
|
| 26 |
+
guidance_scale=7.5,
|
| 27 |
+
):
|
| 28 |
+
pipe = get_pipeline()
|
| 29 |
+
result = pipe(
|
| 30 |
+
image=image,
|
| 31 |
+
mask_image=mask_image,
|
| 32 |
+
prompt=prompt,
|
| 33 |
+
negative_prompt=negative_prompt,
|
| 34 |
+
num_inference_steps=num_inference_steps,
|
| 35 |
+
guidance_scale=guidance_scale,
|
| 36 |
+
).images[0]
|