File size: 1,725 Bytes
69205f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a91639
69205f8
641ec8a
69205f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4de503a
69205f8
 
 
 
 
 
 
3a91639
69205f8
 
 
 
 
 
 
3a91639
8a7f5de
69205f8
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
54
55
import os
from PIL import Image, ImageDraw
import numpy as np

import torch
from torch import autocast
from torch.nn import functional as F
from diffusers import StableDiffusionPipeline, AutoencoderKL
from diffusers import UNet2DConditionModel, PNDMScheduler, LMSDiscreteScheduler
from diffusers.schedulers.scheduling_ddim import DDIMScheduler
from transformers import CLIPTextModel, CLIPTokenizer
from tqdm.auto import tqdm
import gradio as gr

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

from diffusers import StableDiffusionInpaintPipeline
pipe = StableDiffusionInpaintPipeline.from_pretrained(
    "ShreeKanade07/Real-Image-pipeline", torch_dtype=torch.float16
)
#pipe = pipe.to("cuda")




# Define the predict function
def predict(image,mask,prompt):

    prompt = prompt
    image = Image.fromarray(image)
    image=image.convert("RGB").resize((512, 512))
    mask_image = Image.fromarray(mask)
    mask_image=mask_image.convert("RGB").resize((512, 512))
    strength=0.9
    generator = torch.manual_seed(32)
    negative_prompt="zoomed in, blurry, oversaturated, warped,artifacts,flickers"
    images = pipe(prompt=prompt, image=image, mask_image=mask_image, strength=strength, negative_prompt=negative_prompt, generator=generator,num_inference_steps=20).images
    return images[0]



# Create the Gradio interface
gr.Interface(
    predict,
    title='Stable Diffusion Sketch In-Painting',
    inputs=[
        gr.Image(label='Image'),
        gr.Image(label='Mask'),
        gr.Textbox(label='Prompt')
    ],
    outputs=[
        gr.Image(label='Output Image')
    ],
    examples=[["IMG1.png", "IMG1_Mask.png",'Make it real one']], cache_examples=True
).launch(debug=True, share=True)