Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from diffusers import StableDiffusionInpaintPipeline | |
| import torch | |
| pipeline = StableDiffusionInpaintPipeline.from_pretrained( | |
| "runwayml/stable-diffusion-inpainting", | |
| torch_dtype=torch.float16, | |
| use_safetensors=True, | |
| variant="fp16" | |
| ) | |
| pipeline = pipeline.to("cuda") | |
| def predict(mask_img): | |
| prompt = "a green frog, highly detailed, natural lighting" | |
| # get size of the input image | |
| size = mask_img["image"].size | |
| image = pipeline(prompt=prompt, | |
| num_inference_steps=35, | |
| image=mask_img["image"].convert("RGB"), | |
| mask_image=mask_img["mask"].convert("RGB"), | |
| guidance_scale=9 | |
| ).images[0] | |
| return image.resize(size) | |
| # def mirror(img): | |
| # print(img['mask']) | |
| # print(img['image']) | |
| # return img['image'].rotate(45) | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(tool = 'sketch', type='pil'), | |
| outputs=gr.Image() | |
| ) | |
| demo.launch() |