Spaces:
Running
on
Zero
Running
on
Zero
initial app
Browse files- app.py +50 -0
- assets/Inpainting mask.png +0 -0
- assets/rocket.png +0 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import spaces
|
3 |
+
import gradio as gr
|
4 |
+
from diffusers import FluxFillPipeline
|
5 |
+
|
6 |
+
pipe = FluxFillPipeline.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda")
|
7 |
+
|
8 |
+
@spaces.GPU()
|
9 |
+
def inpaint(
|
10 |
+
image,
|
11 |
+
mask,
|
12 |
+
prompt="",
|
13 |
+
num_inference_steps=28,
|
14 |
+
guidance_scale=50,
|
15 |
+
):
|
16 |
+
background = image.convert("RGB")
|
17 |
+
mask = mask.convert("L")
|
18 |
+
|
19 |
+
result = pipe(
|
20 |
+
prompt=prompt,
|
21 |
+
height=background.height,
|
22 |
+
width=background.width,
|
23 |
+
image=background,
|
24 |
+
mask_image=mask,
|
25 |
+
num_inference_steps=num_inference_steps,
|
26 |
+
guidance_scale=guidance_scale,
|
27 |
+
).images[0]
|
28 |
+
|
29 |
+
result = result.convert("RGBA")
|
30 |
+
|
31 |
+
return result
|
32 |
+
|
33 |
+
|
34 |
+
demo = gr.Interface(
|
35 |
+
fn=inpaint,
|
36 |
+
inputs=[
|
37 |
+
gr.Image(label="image", type="pil"),
|
38 |
+
gr.Image(label="mask", type="pil"),
|
39 |
+
gr.Text(label="prompt"),
|
40 |
+
gr.Number(value=50, label="num_inference_steps"),
|
41 |
+
gr.Number(value=28, label="guidance_scale"),
|
42 |
+
],
|
43 |
+
outputs=["image"],
|
44 |
+
api_name="inpaint",
|
45 |
+
examples=[[3, "./assets/rocket.png", "./assets/Inpainting mask.png"]],
|
46 |
+
cache_examples=False,
|
47 |
+
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",
|
48 |
+
)
|
49 |
+
|
50 |
+
demo.launch()
|
assets/Inpainting mask.png
ADDED
![]() |
assets/rocket.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
diffusers
|
2 |
+
spaces
|