Spaces:
Build error
Build error
updated app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import torch
|
| 2 |
-
from diffusers import
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
|
@@ -9,10 +9,17 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 9 |
|
| 10 |
def load_model():
|
| 11 |
"""Load ControlNet Inpainting model."""
|
| 12 |
-
|
| 13 |
"lllyasviel/control_v11p_sd15_inpaint",
|
| 14 |
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
).to(device)
|
|
|
|
| 16 |
return pipe
|
| 17 |
|
| 18 |
pipe = load_model()
|
|
@@ -36,7 +43,7 @@ def inpaint(image_editor_output, prompt):
|
|
| 36 |
mask = mask.resize(image.size, Image.LANCZOS)
|
| 37 |
|
| 38 |
# Perform inpainting
|
| 39 |
-
result = pipe(prompt=prompt, image=image,
|
| 40 |
return result
|
| 41 |
|
| 42 |
# Gradio UI with ImageEditor for inpainting
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
|
|
|
| 9 |
|
| 10 |
def load_model():
|
| 11 |
"""Load ControlNet Inpainting model."""
|
| 12 |
+
controlnet = ControlNetModel.from_pretrained(
|
| 13 |
"lllyasviel/control_v11p_sd15_inpaint",
|
| 14 |
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
| 18 |
+
"runwayml/stable-diffusion-v1-5",
|
| 19 |
+
controlnet=controlnet,
|
| 20 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 21 |
).to(device)
|
| 22 |
+
|
| 23 |
return pipe
|
| 24 |
|
| 25 |
pipe = load_model()
|
|
|
|
| 43 |
mask = mask.resize(image.size, Image.LANCZOS)
|
| 44 |
|
| 45 |
# Perform inpainting
|
| 46 |
+
result = pipe(prompt=prompt, image=image, control_image=mask).images[0]
|
| 47 |
return result
|
| 48 |
|
| 49 |
# Gradio UI with ImageEditor for inpainting
|