Manjushri commited on
Commit
5d95b7b
·
1 Parent(s): c9bcc25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -9
app.py CHANGED
@@ -6,12 +6,9 @@ from PIL import Image
6
  import torch
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
-
10
  pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting")
11
  pipe.to(device)
12
 
13
- source_img = gr.Image(source="upload", type="numpy", tool="sketch", elem_id="source_container");
14
-
15
  def resize(height,img):
16
  baseheight = height
17
  img = Image.open(img)
@@ -23,17 +20,13 @@ def resize(height,img):
23
  def predict(source_img, prompt):
24
  imageio.imwrite("data.png", source_img["image"])
25
  imageio.imwrite("data_mask.png", source_img["mask"])
26
-
27
  src = resize(512, "data.png")
28
  src.save("src.png")
29
  mask = resize(512, "data_mask.png")
30
  mask.save("mask.png")
31
-
32
- image = pipe(prompt, image=src, mask_image=mask, strength=0.75, num_inference_steps=10).images[0]
33
-
34
  return image
35
 
36
-
37
  title="Stable Diffusion 2.0 Inpainting CPU"
38
  description="Inpainting with Stable Diffusion 2.0 <br />Warning: Slow process... ~10 min inference time.<br> <b>Please use 512x512 or 768x768 square .png image as input to avoid memory error!!!</b>"
39
- gr.Interface(fn=predict, inputs=[source_img, "text"], outputs='image', title=title, description=description, article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(max_threads=True, debug=True)
 
6
  import torch
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
9
  pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting")
10
  pipe.to(device)
11
 
 
 
12
  def resize(height,img):
13
  baseheight = height
14
  img = Image.open(img)
 
20
  def predict(source_img, prompt):
21
  imageio.imwrite("data.png", source_img["image"])
22
  imageio.imwrite("data_mask.png", source_img["mask"])
 
23
  src = resize(512, "data.png")
24
  src.save("src.png")
25
  mask = resize(512, "data_mask.png")
26
  mask.save("mask.png")
27
+ image = pipe(prompt, image=src, mask_image=mask, strength=0.75, num_inference_steps=10).images[0]
 
 
28
  return image
29
 
 
30
  title="Stable Diffusion 2.0 Inpainting CPU"
31
  description="Inpainting with Stable Diffusion 2.0 <br />Warning: Slow process... ~10 min inference time.<br> <b>Please use 512x512 or 768x768 square .png image as input to avoid memory error!!!</b>"
32
+ gr.Interface(fn=predict, inputs=[gr.Image(source="upload", type="numpy", tool="sketch", elem_id="source_container"), "text"], outputs='image', title=title, description=description, article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(max_threads=True, debug=True)