Spaces:
Paused
Paused
Delete utils
Browse files- utils/image2image.py +0 -35
- utils/inpaint.py +0 -53
- utils/text2image.py +0 -33
utils/image2image.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
from diffusers import StableDiffusionImg2ImgPipeline, DDIMScheduler
|
| 2 |
-
from PIL import Image
|
| 3 |
-
import torch
|
| 4 |
-
|
| 5 |
-
def stable_diffusion_img2img(
|
| 6 |
-
model_path:str,
|
| 7 |
-
image_path:str,
|
| 8 |
-
prompt:str,
|
| 9 |
-
negative_prompt:str,
|
| 10 |
-
num_samples:int,
|
| 11 |
-
guidance_scale:int,
|
| 12 |
-
num_inference_step:int,
|
| 13 |
-
):
|
| 14 |
-
|
| 15 |
-
image = Image.open(image_path)
|
| 16 |
-
|
| 17 |
-
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 18 |
-
model_path,
|
| 19 |
-
safety_checker=None,
|
| 20 |
-
torch_dtype=torch.float16
|
| 21 |
-
)
|
| 22 |
-
pipe.to("cuda")
|
| 23 |
-
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 24 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 25 |
-
|
| 26 |
-
output = pipe(
|
| 27 |
-
prompt = prompt,
|
| 28 |
-
image = image,
|
| 29 |
-
negative_prompt = negative_prompt,
|
| 30 |
-
num_images_per_prompt = num_samples,
|
| 31 |
-
num_inference_steps = num_inference_step,
|
| 32 |
-
guidance_scale = guidance_scale,
|
| 33 |
-
).images
|
| 34 |
-
|
| 35 |
-
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/inpaint.py
DELETED
|
@@ -1,53 +0,0 @@
|
|
| 1 |
-
from diffusers import DiffusionPipeline, DDIMScheduler
|
| 2 |
-
from PIL import Image
|
| 3 |
-
import imageio
|
| 4 |
-
import torch
|
| 5 |
-
|
| 6 |
-
# https://huggingface.co/spaces/Manjushri/SD-2.0-Inpainting-CPU/blob/main/app.py
|
| 7 |
-
|
| 8 |
-
def resize(height,img):
|
| 9 |
-
baseheight = height
|
| 10 |
-
img = Image.open(img)
|
| 11 |
-
hpercent = (baseheight/float(img.size[1]))
|
| 12 |
-
wsize = int((float(img.size[0])*float(hpercent)))
|
| 13 |
-
img = img.resize((wsize,baseheight), Image.Resampling.LANCZOS)
|
| 14 |
-
return img
|
| 15 |
-
|
| 16 |
-
def img_preprocces(source_img, prompt, negative_prompt):
|
| 17 |
-
imageio.imwrite("data.png", source_img["image"])
|
| 18 |
-
imageio.imwrite("data_mask.png", source_img["mask"])
|
| 19 |
-
src = resize(512, "data.png")
|
| 20 |
-
src.save("src.png")
|
| 21 |
-
mask = resize(512, "data_mask.png")
|
| 22 |
-
mask.save("mask.png")
|
| 23 |
-
return src, mask
|
| 24 |
-
|
| 25 |
-
def stable_diffusion_inpaint(
|
| 26 |
-
image_path:str,
|
| 27 |
-
model_path:str,
|
| 28 |
-
prompt:str,
|
| 29 |
-
negative_prompt:str,
|
| 30 |
-
guidance_scale:int,
|
| 31 |
-
num_inference_step:int,
|
| 32 |
-
):
|
| 33 |
-
|
| 34 |
-
image, mask_image = img_preprocces(image_path, prompt, negative_prompt)
|
| 35 |
-
pipe = DiffusionPipeline.from_pretrained(
|
| 36 |
-
model_path,
|
| 37 |
-
revision="fp16",
|
| 38 |
-
torch_dtype=torch.float16,
|
| 39 |
-
)
|
| 40 |
-
pipe.to('cuda')
|
| 41 |
-
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 42 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 43 |
-
|
| 44 |
-
output = pipe(
|
| 45 |
-
prompt = prompt,
|
| 46 |
-
image = image,
|
| 47 |
-
mask_image=mask_image,
|
| 48 |
-
negative_prompt = negative_prompt,
|
| 49 |
-
num_inference_steps = num_inference_step,
|
| 50 |
-
guidance_scale = guidance_scale,
|
| 51 |
-
).images
|
| 52 |
-
|
| 53 |
-
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/text2image.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
from diffusers import StableDiffusionPipeline, DDIMScheduler
|
| 2 |
-
import torch
|
| 3 |
-
|
| 4 |
-
def stable_diffusion_text2img(
|
| 5 |
-
model_path:str,
|
| 6 |
-
prompt:str,
|
| 7 |
-
negative_prompt:str,
|
| 8 |
-
guidance_scale:int,
|
| 9 |
-
num_inference_step:int,
|
| 10 |
-
height:int,
|
| 11 |
-
width:int,
|
| 12 |
-
):
|
| 13 |
-
|
| 14 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
| 15 |
-
model_path,
|
| 16 |
-
safety_checker=None,
|
| 17 |
-
torch_dtype=torch.float16
|
| 18 |
-
).to("cuda")
|
| 19 |
-
|
| 20 |
-
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 21 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 22 |
-
|
| 23 |
-
images = pipe(
|
| 24 |
-
prompt,
|
| 25 |
-
height=height,
|
| 26 |
-
width=width,
|
| 27 |
-
negative_prompt=negative_prompt,
|
| 28 |
-
num_images_per_prompt=1,
|
| 29 |
-
num_inference_steps=num_inference_step,
|
| 30 |
-
guidance_scale=guidance_scale,
|
| 31 |
-
).images
|
| 32 |
-
|
| 33 |
-
return images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|