patrickvonplaten
commited on
Commit
•
3c77757
1
Parent(s):
1ee3bf0
Update app.py
Browse files
app.py
CHANGED
@@ -12,11 +12,12 @@ from torch import autocast
|
|
12 |
import cv2
|
13 |
from matplotlib import pyplot as plt
|
14 |
from torchvision import transforms
|
15 |
-
from diffusers import DiffusionPipeline
|
16 |
|
17 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
def read_content(file_path: str) -> str:
|
22 |
"""read the content of target file
|
@@ -26,10 +27,13 @@ def read_content(file_path: str) -> str:
|
|
26 |
|
27 |
return content
|
28 |
|
29 |
-
def predict(dict, prompt=""):
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
33 |
return output.images[0], gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
34 |
|
35 |
|
@@ -82,6 +86,10 @@ with image_blocks as demo:
|
|
82 |
image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload").style(height=400)
|
83 |
with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
|
84 |
prompt = gr.Textbox(placeholder = 'Your prompt (what you want in place of what is erased)', show_label=False, elem_id="input-text")
|
|
|
|
|
|
|
|
|
85 |
btn = gr.Button("Inpaint!").style(
|
86 |
margin=False,
|
87 |
rounded=(False, True, True, False),
|
@@ -95,7 +103,7 @@ with image_blocks as demo:
|
|
95 |
share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
|
96 |
|
97 |
|
98 |
-
btn.click(fn=predict, inputs=[image, prompt], outputs=[image_out, community_icon, loading_icon, share_button])
|
99 |
share_button.click(None, [], [], _js=share_js)
|
100 |
|
101 |
|
|
|
12 |
import cv2
|
13 |
from matplotlib import pyplot as plt
|
14 |
from torchvision import transforms
|
15 |
+
from diffusers import DiffusionPipeline, UNet2DModel
|
16 |
|
17 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
18 |
|
19 |
+
unet = UNet2DModel.from_pretrained("valhalla/sdxl-inpaint-ema")
|
20 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
21 |
|
22 |
def read_content(file_path: str) -> str:
|
23 |
"""read the content of target file
|
|
|
27 |
|
28 |
return content
|
29 |
|
30 |
+
def predict(dict, prompt="", guidance_scale, steps, strength):
|
31 |
+
|
32 |
+
init_image = dict["image"].convert("RGB").resize((1024, 1024))
|
33 |
+
mask = dict["mask"].convert("RGB").resize((1024, 1024))
|
34 |
+
|
35 |
+
output = pipe(prompt = prompt, image=init_image, mask_image=mask, guidance_scale=guidance_scale, steps=int(steps), strength=strength)
|
36 |
+
|
37 |
return output.images[0], gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
38 |
|
39 |
|
|
|
86 |
image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil", label="Upload").style(height=400)
|
87 |
with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
|
88 |
prompt = gr.Textbox(placeholder = 'Your prompt (what you want in place of what is erased)', show_label=False, elem_id="input-text")
|
89 |
+
guidance_scale = gradio.Number(value=7.5, minimum=1.0, maximum=20.0)
|
90 |
+
steps = gradio.Number(value=20, minimum=10, maximum=50)
|
91 |
+
strength = gradio.Number(value=0.0, minimum=0.0, maximum=0.0)
|
92 |
+
|
93 |
btn = gr.Button("Inpaint!").style(
|
94 |
margin=False,
|
95 |
rounded=(False, True, True, False),
|
|
|
103 |
share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
|
104 |
|
105 |
|
106 |
+
btn.click(fn=predict, inputs=[image, prompt, guidance_scale, steps, strength], outputs=[image_out, community_icon, loading_icon, share_button])
|
107 |
share_button.click(None, [], [], _js=share_js)
|
108 |
|
109 |
|