Spaces:
Running
Running
Do update seed
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
from diffusers import StableDiffusionXLInpaintPipeline
|
|
|
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import time
|
5 |
import math
|
6 |
import random
|
7 |
import imageio
|
8 |
-
from PIL import Image, ImageFilter
|
9 |
import torch
|
10 |
|
11 |
max_64_bit_int = 2**63 - 1
|
@@ -16,6 +17,16 @@ variant = "fp16" if torch.cuda.is_available() else None
|
|
16 |
pipe = StableDiffusionXLInpaintPipeline.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype = floatType, variant = variant)
|
17 |
pipe = pipe.to(device)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def noise_color(color, noise):
|
20 |
return color + random.randint(- noise, noise)
|
21 |
|
@@ -136,7 +147,7 @@ def uncrop(
|
|
136 |
seed = random.randint(0, max_64_bit_int)
|
137 |
|
138 |
random.seed(seed)
|
139 |
-
|
140 |
|
141 |
original_height, original_width, original_channel = np.array(input_image).shape
|
142 |
output_width = enlarge_left + original_width + enlarge_right
|
@@ -253,17 +264,6 @@ def uncrop(
|
|
253 |
mask_image
|
254 |
]
|
255 |
|
256 |
-
def update_seed(is_randomize_seed, seed):
|
257 |
-
if is_randomize_seed:
|
258 |
-
return random.randint(0, max_64_bit_int)
|
259 |
-
return seed
|
260 |
-
|
261 |
-
def toggle_debug(is_debug_mode):
|
262 |
-
if is_debug_mode:
|
263 |
-
return [gr.update(visible = True)] * 3
|
264 |
-
else:
|
265 |
-
return [gr.update(visible = False)] * 3
|
266 |
-
|
267 |
with gr.Blocks() as interface:
|
268 |
gr.Markdown(
|
269 |
"""
|
@@ -322,7 +322,7 @@ with gr.Blocks() as interface:
|
|
322 |
image_guidance_scale = gr.Slider(minimum = 1, value = 1.5, step = 0.1, label = "Image Guidance Scale", info = "lower=image quality, higher=follow the image")
|
323 |
strength = gr.Slider(value = 0.99, minimum = 0.01, maximum = 1.0, step = 0.01, label = "Strength", info = "lower=follow the original area (discouraged), higher=redraw from scratch")
|
324 |
denoising_steps = gr.Number(minimum = 0, value = 1000, step = 1, label = "Denoising", info = "lower=irrelevant result, higher=relevant result")
|
325 |
-
randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed
|
326 |
seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed")
|
327 |
debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
|
328 |
|
@@ -340,7 +340,12 @@ with gr.Blocks() as interface:
|
|
340 |
with gr.Row():
|
341 |
mask_image = gr.Image(label = "Mask image", visible = False)
|
342 |
|
343 |
-
submit.click(
|
|
|
|
|
|
|
|
|
|
|
344 |
original_image,
|
345 |
enlarged_image,
|
346 |
mask_image
|
|
|
1 |
from diffusers import StableDiffusionXLInpaintPipeline
|
2 |
+
from PIL import Image, ImageFilter
|
3 |
+
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
import time
|
7 |
import math
|
8 |
import random
|
9 |
import imageio
|
|
|
10 |
import torch
|
11 |
|
12 |
max_64_bit_int = 2**63 - 1
|
|
|
17 |
pipe = StableDiffusionXLInpaintPipeline.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype = floatType, variant = variant)
|
18 |
pipe = pipe.to(device)
|
19 |
|
20 |
+
def update_seed(is_randomize_seed, seed):
|
21 |
+
if is_randomize_seed:
|
22 |
+
return random.randint(0, max_64_bit_int)
|
23 |
+
return seed
|
24 |
+
|
25 |
+
def toggle_debug(is_debug_mode):
|
26 |
+
if is_debug_mode:
|
27 |
+
return [gr.update(visible = True)] * 3
|
28 |
+
return [gr.update(visible = False)] * 3
|
29 |
+
|
30 |
def noise_color(color, noise):
|
31 |
return color + random.randint(- noise, noise)
|
32 |
|
|
|
147 |
seed = random.randint(0, max_64_bit_int)
|
148 |
|
149 |
random.seed(seed)
|
150 |
+
torch.manual_seed(seed)
|
151 |
|
152 |
original_height, original_width, original_channel = np.array(input_image).shape
|
153 |
output_width = enlarge_left + original_width + enlarge_right
|
|
|
264 |
mask_image
|
265 |
]
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
with gr.Blocks() as interface:
|
268 |
gr.Markdown(
|
269 |
"""
|
|
|
322 |
image_guidance_scale = gr.Slider(minimum = 1, value = 1.5, step = 0.1, label = "Image Guidance Scale", info = "lower=image quality, higher=follow the image")
|
323 |
strength = gr.Slider(value = 0.99, minimum = 0.01, maximum = 1.0, step = 0.01, label = "Strength", info = "lower=follow the original area (discouraged), higher=redraw from scratch")
|
324 |
denoising_steps = gr.Number(minimum = 0, value = 1000, step = 1, label = "Denoising", info = "lower=irrelevant result, higher=relevant result")
|
325 |
+
randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed", value = True, info = "If checked, result is always different")
|
326 |
seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed")
|
327 |
debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
|
328 |
|
|
|
340 |
with gr.Row():
|
341 |
mask_image = gr.Image(label = "Mask image", visible = False)
|
342 |
|
343 |
+
submit.click(fn = update_seed, inputs = [
|
344 |
+
randomize_seed,
|
345 |
+
seed
|
346 |
+
], outputs = [
|
347 |
+
seed
|
348 |
+
], queue = False, show_progress = False).then(toggle_debug, debug_mode, [
|
349 |
original_image,
|
350 |
enlarged_image,
|
351 |
mask_image
|