Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,013 Bytes
7a3d678 397db89 7a3d678 546800a 397db89 7a3d678 397db89 7a3d678 397db89 7a3d678 397db89 22ce6bb 7a3d678 397db89 7a3d678 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import torch
from diffusers import FluxInpaintPipeline
from PIL import Image
import sys
import spaces
# I only test with FLUX.1-schnell
#@spaces.GPU
def process_image(image,mask_image,prompt="a person",model_id="black-forest-labs/FLUX.1-schnell",strength=0.75,seed=0,num_inference_steps=4):
if image == None:
return None
pipe = FluxInpaintPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
pipe.to("cuda")
generators = []
generator = torch.Generator("cuda").manual_seed(seed)
generators.append(generator)
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
output = pipe(prompt=prompt, image=image, mask_image=mask_image,generator=generator,strength=strength)
return output.images[0]
if __name__ == "__main__":
#args input-image input-mask output
image = Image.open(sys.argv[1])
mask = Image.open(sys.argv[2])
output = process_image(image,mask)
output.save(sys.argv[3]) |