Spaces:
Runtime error
Runtime error
Update flux1_img2img.py
Browse files- flux1_img2img.py +35 -35
flux1_img2img.py
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
-
import torch
|
2 |
-
from diffusers import FluxImg2ImgPipeline
|
3 |
-
|
4 |
-
from PIL import Image
|
5 |
-
import sys
|
6 |
-
import spaces
|
7 |
-
|
8 |
-
# I only test with FLUX.1-schnell
|
9 |
-
|
10 |
-
@spaces.GPU
|
11 |
-
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):
|
12 |
-
print("start process image process_image")
|
13 |
-
if image == None:
|
14 |
-
print("empty input image returned")
|
15 |
-
return None
|
16 |
-
|
17 |
-
pipe = FluxImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.
|
18 |
-
pipe.to("cuda")
|
19 |
-
|
20 |
-
generators = []
|
21 |
-
generator = torch.Generator("cuda").manual_seed(seed)
|
22 |
-
generators.append(generator)
|
23 |
-
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
24 |
-
print(prompt)
|
25 |
-
output = pipe(prompt=prompt, image=image,generator=generator,strength=strength
|
26 |
-
,guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
27 |
-
|
28 |
-
# TODO support mask
|
29 |
-
return output.images[0]
|
30 |
-
|
31 |
-
if __name__ == "__main__":
|
32 |
-
#args input-image input-mask output
|
33 |
-
image = Image.open(sys.argv[1])
|
34 |
-
mask = Image.open(sys.argv[2])
|
35 |
-
output = process_image(image,mask)
|
36 |
output.save(sys.argv[3])
|
|
|
1 |
+
import torch
|
2 |
+
from diffusers import FluxImg2ImgPipeline
|
3 |
+
|
4 |
+
from PIL import Image
|
5 |
+
import sys
|
6 |
+
import spaces
|
7 |
+
|
8 |
+
# I only test with FLUX.1-schnell
|
9 |
+
|
10 |
+
@spaces.GPU
|
11 |
+
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):
|
12 |
+
print("start process image process_image")
|
13 |
+
if image == None:
|
14 |
+
print("empty input image returned")
|
15 |
+
return None
|
16 |
+
|
17 |
+
pipe = FluxImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
18 |
+
pipe.to("cuda")
|
19 |
+
|
20 |
+
generators = []
|
21 |
+
generator = torch.Generator("cuda").manual_seed(seed)
|
22 |
+
generators.append(generator)
|
23 |
+
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
24 |
+
print(prompt)
|
25 |
+
output = pipe(prompt=prompt, image=image,generator=generator,strength=strength
|
26 |
+
,guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
27 |
+
|
28 |
+
# TODO support mask
|
29 |
+
return output.images[0]
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
#args input-image input-mask output
|
33 |
+
image = Image.open(sys.argv[1])
|
34 |
+
mask = Image.open(sys.argv[2])
|
35 |
+
output = process_image(image,mask)
|
36 |
output.save(sys.argv[3])
|