Spaces:
Runtime error
Runtime error
File size: 1,951 Bytes
d3f11d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
from PIL import Image
import numpy as np
from diffusers import StableDiffusionInpaintPipeline
import torch
from diffusers.utils import load_image
from diffusers.pipelines.stable_diffusion import safety_checker
def sc(self, clip_input, images) :
return images, [False for i in images]
safety_checker.StableDiffusionSafetyChecker.forward = sc
pipe = StableDiffusionInpaintPipeline.from_pretrained(
"runwayml/stable-diffusion-inpainting",
revision="fp16",
torch_dtype=torch.float16,
)
def inpaint_image(image, mask, prompt, negative_prompt):
# Convert PIL images to numpy arrays if needed
# Process your images as required by your inpainting model
n_image = pipe(prompt, image=image, mask_image=mask, guidance_scale=5,height=int(8*round(pil_img.height/8)), width=int(8*round(pil_img.width/8)), num_inference_steps=70,negative_prompt=negative_prompt).images[0]
return n_image
def process_files(image_file, mask_file, prompt, negative_prompt):
image = Image.open(image_file)
mask = Image.open(mask_file)
return inpaint_image(image, mask, prompt, negative_prompt)
with gr.Blocks() as demo:
gr.Markdown("## Inpainting App")
with gr.Row():
with gr.Column():
image_input = gr.File(label="Input Image", type="filepath")
mask_input = gr.File(label="Mask Image", type="filepath")
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
negative_prompt_input = gr.Textbox(label="Negative Prompt", placeholder="Enter your negative prompt here...")
submit_button = gr.Button("Inpaint")
with gr.Column():
output_image = gr.Image(type="pil", label="Inpainted Image")
submit_button.click(
fn=process_files,
inputs=[image_input, mask_input, prompt_input, negative_prompt_input],
outputs=output_image
)
# Launch the interface
demo.launch()
|