File size: 809 Bytes
840c036
a11d2e7
9fdc17b
a11d2e7
 
9fdc17b
a11d2e7
 
 
840c036
 
a11d2e7
 
 
 
 
 
840c036
 
 
9fdc17b
 
 
 
 
840c036
a11d2e7
840c036
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
import gradio as gr
from pipeline_ddpm_sketch2img import DDPMSketch2ImgPipeline
import numpy as np
from diffusers import DDPMScheduler, DPMSolverMultistepScheduler, DDIMScheduler
from PIL import Image

model_path = "IzumiSatoshi/sketch2img-FashionMNIST"
pipe = DDPMSketch2ImgPipeline.from_pretrained(model_path).to("cpu")
pipe.scheduler = DDIMScheduler.from_pretrained(model_path, subfolder="scheduler")


def draw(sketch):
    sketch[sketch < 250] = 0
    sketch[sketch >= 250] = 255
    sketch = Image.fromarray(sketch)
    image = pipe(sketch, num_inference_step=50)
    return sketch, image


inp = gr.inputs.Image(
    image_mode="L",
    source="canvas",
    shape=(28, 28),
    invert_colors=True,
    tool="select",
)
demo = gr.Interface(fn=draw, inputs=inp, outputs=["image", "image"])
demo.launch()