Spaces:
Running
Running
Fabrice-TIERCELIN
commited on
Commit
•
b366d01
1
Parent(s):
87a47be
Add an example
Browse files
app.py
CHANGED
@@ -18,6 +18,48 @@ pipe = pipe.to(device)
|
|
18 |
def noise_color(color, noise):
|
19 |
return color + random.randint(- noise, noise)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def predict(
|
22 |
source_img,
|
23 |
enlarge_top,
|
@@ -37,9 +79,6 @@ def predict(
|
|
37 |
start = time.time()
|
38 |
progress(0, desc = "Preparing data...")
|
39 |
|
40 |
-
if source_img is None:
|
41 |
-
raise gr.Error("Please provide an image.")
|
42 |
-
|
43 |
if enlarge_top is None or enlarge_top == "":
|
44 |
enlarge_top = 0
|
45 |
|
@@ -52,15 +91,6 @@ def predict(
|
|
52 |
if enlarge_left is None or enlarge_left == "":
|
53 |
enlarge_left = 0
|
54 |
|
55 |
-
if enlarge_top < 0 or enlarge_right < 0 or enlarge_bottom < 0 or enlarge_left < 0:
|
56 |
-
raise gr.Error("Please only provide positive margins.")
|
57 |
-
|
58 |
-
if enlarge_top == 0 and enlarge_right == 0 and enlarge_bottom == 0 and enlarge_left == 0:
|
59 |
-
raise gr.Error("At least one border must be enlarged.")
|
60 |
-
|
61 |
-
if prompt is None or prompt == "":
|
62 |
-
raise gr.Error("Please provide a prompt input.")
|
63 |
-
|
64 |
if negative_prompt is None:
|
65 |
negative_prompt = ""
|
66 |
|
@@ -238,7 +268,23 @@ with gr.Blocks() as interface:
|
|
238 |
mask_image = gr.Image(label = "Mask image", visible = False)
|
239 |
|
240 |
submit.click(toggle_debug, debug_mode, [original_image, enlarged_image, mask_image], queue = False,
|
241 |
-
show_progress = False).then(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
source_img,
|
243 |
enlarge_top,
|
244 |
enlarge_right,
|
@@ -261,4 +307,49 @@ with gr.Blocks() as interface:
|
|
261 |
mask_image
|
262 |
], scroll_to_output = True)
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
interface.queue().launch()
|
|
|
18 |
def noise_color(color, noise):
|
19 |
return color + random.randint(- noise, noise)
|
20 |
|
21 |
+
def check(
|
22 |
+
source_img,
|
23 |
+
enlarge_top,
|
24 |
+
enlarge_right,
|
25 |
+
enlarge_bottom,
|
26 |
+
enlarge_left,
|
27 |
+
prompt,
|
28 |
+
negative_prompt,
|
29 |
+
smooth_border,
|
30 |
+
denoising_steps,
|
31 |
+
num_inference_steps,
|
32 |
+
guidance_scale,
|
33 |
+
randomize_seed,
|
34 |
+
seed,
|
35 |
+
debug_mode,
|
36 |
+
progress = gr.Progress()):
|
37 |
+
if source_img is None:
|
38 |
+
raise gr.Error("Please provide an image.")
|
39 |
+
|
40 |
+
if prompt is None or prompt == "":
|
41 |
+
raise gr.Error("Please provide a prompt input.")
|
42 |
+
|
43 |
+
if (not (enlarge_top is None)) and enlarge_top < 0:
|
44 |
+
raise gr.Error("Please provide positive top margin.")
|
45 |
+
|
46 |
+
if (not (enlarge_right is None)) and enlarge_right < 0:
|
47 |
+
raise gr.Error("Please provide positive right margin.")
|
48 |
+
|
49 |
+
if (not (enlarge_bottom is None)) and enlarge_bottom < 0:
|
50 |
+
raise gr.Error("Please provide positive bottom margin.")
|
51 |
+
|
52 |
+
if (not (enlarge_left is None)) and enlarge_left < 0:
|
53 |
+
raise gr.Error("Please provide positive left margin.")
|
54 |
+
|
55 |
+
if (
|
56 |
+
(enlarge_top is None or enlarge_top == 0)
|
57 |
+
and (enlarge_right is None or enlarge_right == 0)
|
58 |
+
and (enlarge_bottom is None or enlarge_bottom == 0)
|
59 |
+
and (enlarge_left is None or enlarge_left == 0)
|
60 |
+
):
|
61 |
+
raise gr.Error("At least one border must be enlarged.")
|
62 |
+
|
63 |
def predict(
|
64 |
source_img,
|
65 |
enlarge_top,
|
|
|
79 |
start = time.time()
|
80 |
progress(0, desc = "Preparing data...")
|
81 |
|
|
|
|
|
|
|
82 |
if enlarge_top is None or enlarge_top == "":
|
83 |
enlarge_top = 0
|
84 |
|
|
|
91 |
if enlarge_left is None or enlarge_left == "":
|
92 |
enlarge_left = 0
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
if negative_prompt is None:
|
95 |
negative_prompt = ""
|
96 |
|
|
|
268 |
mask_image = gr.Image(label = "Mask image", visible = False)
|
269 |
|
270 |
submit.click(toggle_debug, debug_mode, [original_image, enlarged_image, mask_image], queue = False,
|
271 |
+
show_progress = False).then(check, inputs = [
|
272 |
+
source_img,
|
273 |
+
enlarge_top,
|
274 |
+
enlarge_right,
|
275 |
+
enlarge_bottom,
|
276 |
+
enlarge_left,
|
277 |
+
prompt,
|
278 |
+
negative_prompt,
|
279 |
+
smooth_border,
|
280 |
+
denoising_steps,
|
281 |
+
num_inference_steps,
|
282 |
+
guidance_scale,
|
283 |
+
randomize_seed,
|
284 |
+
seed,
|
285 |
+
debug_mode
|
286 |
+
], outputs = [], queue = False,
|
287 |
+
show_progress = False).success(predict, inputs = [
|
288 |
source_img,
|
289 |
enlarge_top,
|
290 |
enlarge_right,
|
|
|
307 |
mask_image
|
308 |
], scroll_to_output = True)
|
309 |
|
310 |
+
gr.Examples(
|
311 |
+
inputs = [
|
312 |
+
source_img,
|
313 |
+
enlarge_top,
|
314 |
+
enlarge_right,
|
315 |
+
enlarge_bottom,
|
316 |
+
enlarge_left,
|
317 |
+
prompt,
|
318 |
+
negative_prompt,
|
319 |
+
smooth_border,
|
320 |
+
denoising_steps,
|
321 |
+
num_inference_steps,
|
322 |
+
guidance_scale,
|
323 |
+
randomize_seed,
|
324 |
+
seed,
|
325 |
+
debug_mode
|
326 |
+
],
|
327 |
+
outputs = [
|
328 |
+
uncropped_image,
|
329 |
+
information,
|
330 |
+
original_image,
|
331 |
+
enlarged_image,
|
332 |
+
mask_image
|
333 |
+
],
|
334 |
+
examples = [
|
335 |
+
[
|
336 |
+
"Example1.png",
|
337 |
+
64,
|
338 |
+
64,
|
339 |
+
64,
|
340 |
+
64,
|
341 |
+
"Stone wall, front view, homogene light",
|
342 |
+
"Border, frame, painting, scribbling, smear, noise, blur, watermark",
|
343 |
+
20,
|
344 |
+
1000,
|
345 |
+
20,
|
346 |
+
7,
|
347 |
+
True,
|
348 |
+
42,
|
349 |
+
False
|
350 |
+
],
|
351 |
+
],
|
352 |
+
cache_examples = False,
|
353 |
+
)
|
354 |
+
|
355 |
interface.queue().launch()
|