Spaces:
Sleeping
Sleeping
Commit ·
25ca330
1
Parent(s): dd004ac
Add inpainting app
Browse files- app.py +37 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import AutoPipelineForInpainting
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
|
| 8 |
+
pipe = AutoPipelineForInpainting.from_pretrained(
|
| 9 |
+
"black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.float16
|
| 10 |
+
).to(device)
|
| 11 |
+
pipe.enable_model_cpu_offload()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def inpaint(
|
| 15 |
+
image: Image.Image, mask: Image.Image, prompt: str, negative_prompt: str = ""
|
| 16 |
+
):
|
| 17 |
+
output = pipe(
|
| 18 |
+
prompt=prompt, negative_prompt=negative_prompt, image=image, mask_image=mask
|
| 19 |
+
).images[0]
|
| 20 |
+
return output
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=inpaint,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Image(label="Base Image"),
|
| 27 |
+
gr.Image(label="Mask (white=edit)", tool="sketch", type="pil"),
|
| 28 |
+
gr.Textbox(label="Prompt"),
|
| 29 |
+
gr.Textbox(label="Negative Prompt (optional)"),
|
| 30 |
+
],
|
| 31 |
+
outputs=gr.Image(label="Inpainted Output"),
|
| 32 |
+
title="Flux.1 Fill‑dev Inpaint",
|
| 33 |
+
description="Upload an image and mask, enter prompt, and capture structure-preserving inpaint—all running inside the app.",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diffusers>=0.34.0
|
| 2 |
+
torch
|
| 3 |
+
safetensors
|
| 4 |
+
transformers
|
| 5 |
+
gradio
|