Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionInpaintPipeline
|
| 3 |
+
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import base64
|
| 6 |
+
import io
|
| 7 |
+
|
| 8 |
+
# Load the Qwen Inpainting model
|
| 9 |
+
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 10 |
+
"InstantX/Qwen-Image-ControlNet-Inpainting",
|
| 11 |
+
torch_dtype=torch.float16
|
| 12 |
+
).to("cuda")
|
| 13 |
+
|
| 14 |
+
def edit_image(image, mask, prompt):
|
| 15 |
+
image = image.convert("RGB")
|
| 16 |
+
mask = mask.convert("L") # Black = edit, White = keep
|
| 17 |
+
result = pipe(
|
| 18 |
+
prompt=prompt,
|
| 19 |
+
image=image,
|
| 20 |
+
mask_image=mask,
|
| 21 |
+
num_inference_steps=30
|
| 22 |
+
).images[0]
|
| 23 |
+
return result
|
| 24 |
+
|
| 25 |
+
# Gradio UI
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=edit_image,
|
| 28 |
+
inputs=[
|
| 29 |
+
gr.Image(type="pil", label="Input Image"),
|
| 30 |
+
gr.Image(type="pil", label="Mask Image"),
|
| 31 |
+
gr.Textbox(label="Prompt")
|
| 32 |
+
],
|
| 33 |
+
outputs=gr.Image(type="pil", label="Edited Image"),
|
| 34 |
+
title="Qwen Image Inpainting"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
demo.launch()
|