IzumiSatoshi commited on
Commit
a11d2e7
·
1 Parent(s): 8cdf719

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -1,19 +1,20 @@
1
  import gradio as gr
2
- from Sketch2ImgPipeline import Sketch2ImgPipeline
3
  import numpy as np
 
 
4
 
5
- pipe = Sketch2ImgPipeline.from_pretrained("IzumiSatoshi/sketch2img-FashionMNIST")
 
 
6
 
7
 
8
- def greet(input_img):
9
- sketches = np.expand_dims(input_img, (0, 1))
10
- sketches[sketches < 250] = 0
11
- sketches[sketches >= 250] = 255
12
- print(sketches.shape)
13
- samples = pipe(sketches, num_inference_step=10)
14
- out = samples[0][0]
15
- print(out.shape)
16
- return sketches[0][0], out
17
 
18
 
19
  inp = gr.inputs.Image(
@@ -23,5 +24,5 @@ inp = gr.inputs.Image(
23
  invert_colors=True,
24
  tool="select",
25
  )
26
- demo = gr.Interface(fn=greet, inputs=inp, outputs=["image", "image"])
27
  demo.launch()
 
1
  import gradio as gr
2
+ from pipeline_ddpm_sketch2img import DDPMSketch2ImgPipeline
3
  import numpy as np
4
+ from diffusers import DDPMScheduler, DPMSolverMultistepScheduler, DDIMScheduler
5
+ from PIL import Image
6
 
7
+ model_path = "IzumiSatoshi/sketch2img-FashionMNIST"
8
+ pipe = DDPMSketch2ImgPipeline.from_pretrained(model_path).to("cpu")
9
+ pipe.scheduler = DDIMScheduler.from_pretrained(model_path, subfolder="scheduler")
10
 
11
 
12
+ def draw(sketch):
13
+ sketch[sketch < 250] = 0
14
+ sketch[sketch >= 250] = 255
15
+ sketch = Image.fromarray(sketch)
16
+ image = pipe(sketch, num_inference_step=50)
17
+ return sketch, image
 
 
 
18
 
19
 
20
  inp = gr.inputs.Image(
 
24
  invert_colors=True,
25
  tool="select",
26
  )
27
+ demo = gr.Interface(fn=draw, inputs=inp, outputs=["image", "image"])
28
  demo.launch()