Manjushri commited on
Commit
4ad7d0b
·
1 Parent(s): f9458e0

Update app.py

Browse files

Naw, that didn't work none too good, I reckon

Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from diffusers import DiffusionPipeline
2
  import gradio as gr
3
  import numpy as np
4
  import imageio
@@ -7,7 +7,7 @@ import torch
7
  import modin.pandas as pd
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0") #StableDiffusionInpaintPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting", safety_checker=None)
11
  pipe = pipe.to(device)
12
 
13
  def resize(value,img):
@@ -18,13 +18,13 @@ def resize(value,img):
18
  def predict(source_img, prompt, negative_prompt):
19
  imageio.imwrite("data.png", source_img["image"])
20
  imageio.imwrite("data_mask.png", source_img["mask"])
21
- src = resize(512, "data.png")
22
  src.save("src.png")
23
- mask = resize(512, "data_mask.png")
24
  mask.save("mask.png")
25
  image = pipe(prompt=prompt, negative_prompt=negative_prompt, image=mask, num_inference_steps=20).images[0]
26
  return image
27
 
28
  title="Stable Diffusion 2.0 Inpainting CPU"
29
  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>"
30
- gr.Interface(fn=predict, inputs=[gr.Image(source="canvas", type="numpy", tool="sketch", elem_id="source_container"), gr.Textbox(label='What you want the AI to Generate, 77 Token limit'), gr.Textbox(label='What you Do Not want the AI to generate')], outputs='image', title=title, description=description, article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(max_threads=True, debug=True)
 
1
+ from diffusers import StableDiffusionInpaintPipeline
2
  import gradio as gr
3
  import numpy as np
4
  import imageio
 
7
  import modin.pandas as pd
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ pipe = StableDiffusionInpaintPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting", safety_checker=None)
11
  pipe = pipe.to(device)
12
 
13
  def resize(value,img):
 
18
  def predict(source_img, prompt, negative_prompt):
19
  imageio.imwrite("data.png", source_img["image"])
20
  imageio.imwrite("data_mask.png", source_img["mask"])
21
+ src = resize(768, "data.png")
22
  src.save("src.png")
23
+ mask = resize(768, "data_mask.png")
24
  mask.save("mask.png")
25
  image = pipe(prompt=prompt, negative_prompt=negative_prompt, image=mask, num_inference_steps=20).images[0]
26
  return image
27
 
28
  title="Stable Diffusion 2.0 Inpainting CPU"
29
  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>"
30
+ gr.Interface(fn=predict, inputs=[gr.Image(source="upload", type="numpy", tool="sketch", elem_id="source_container"), gr.Textbox(label='What you want the AI to Generate, 77 Token limit'), gr.Textbox(label='What you Do Not want the AI to generate')], outputs='image', title=title, description=description, article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(max_threads=True, debug=True)