Spaces:
Runtime error
Runtime error
import torch | |
import spaces | |
import gradio as gr | |
from diffusers import FluxFillPipeline | |
pipe = FluxFillPipeline.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda") | |
def inpaint( | |
image, | |
mask, | |
prompt="", | |
num_inference_steps=28, | |
guidance_scale=50, | |
): | |
background = image.convert("RGB") | |
mask = mask.convert("L") | |
result = pipe( | |
prompt=prompt, | |
height=background.height, | |
width=background.width, | |
image=background, | |
mask_image=mask, | |
num_inference_steps=num_inference_steps, | |
guidance_scale=guidance_scale, | |
).images[0] | |
result = result.convert("RGBA") | |
return result | |
demo = gr.Interface( | |
fn=inpaint, | |
inputs=[ | |
gr.Image(label="image", type="pil"), | |
gr.Image(label="mask", type="pil"), | |
gr.Text(label="prompt"), | |
gr.Number(value=50, label="num_inference_steps"), | |
gr.Number(value=28, label="guidance_scale"), | |
], | |
outputs=["image"], | |
api_name="inpaint", | |
examples=[[3, "./assets/rocket.png", "./assets/Inpainting mask.png"]], | |
cache_examples=False, | |
description="it is recommended that you use https://github.com/la-voliere/react-mask-editor when creating an image mask in JS and then inverse it before sending it to this space", | |
) | |
demo.launch() |