Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,12 @@ A value of 0.1 means to repaint wherever the model is certain it's a watermark.
|
|
41 |
|
42 |
def fix_img(img0, threshold=0.5, erosion=2, dilation=6, mask_only=False,
|
43 |
meaningful_diff=150, meaningful_ed=2):
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
45 |
npa = np.array(img)
|
46 |
blue = npa[:, :, 2]
|
47 |
blue_torch = torch.tensor(blue).float().to(device)
|
@@ -70,7 +75,7 @@ def fix_img(img0, threshold=0.5, erosion=2, dilation=6, mask_only=False,
|
|
70 |
fixed_r = np.where(mask, fixed_r, npa[:, :, 0])
|
71 |
fixed_g = np.where(mask, fixed_g, npa[:, :, 1])
|
72 |
fixed_b = np.where(mask, fixed_b, npa[:, :, 2])
|
73 |
-
|
74 |
if meaningful_diff > 0:
|
75 |
diff_r = np.abs(fixed_r - npa[:, :, 0])
|
76 |
diff_g = np.abs(fixed_g - npa[:, :, 1])
|
@@ -103,7 +108,7 @@ with gr.Blocks() as demo:
|
|
103 |
erosion = gr.Slider(minimum=1, maximum=10, value=2, label="Erosion", step=1)
|
104 |
dilation = gr.Slider(minimum=1, maximum=10, value=10, label="Dilation", step=1)
|
105 |
mask_only = gr.Checkbox(value=False, label="Mask Only")
|
106 |
-
meaningful_diff = gr.Slider(minimum=0, maximum=
|
107 |
meaningful_ed = gr.Slider(minimum=1, maximum=10, value=2, label="Meaningful ED", step=1)
|
108 |
|
109 |
# Outputs Section
|
|
|
41 |
|
42 |
def fix_img(img0, threshold=0.5, erosion=2, dilation=6, mask_only=False,
|
43 |
meaningful_diff=150, meaningful_ed=2):
|
44 |
+
sz_max = 2048
|
45 |
+
scale = min(sz_max / img0.size[0], sz_max / img0.size[1])
|
46 |
+
if scale < 0.99:
|
47 |
+
img = img0.convert('RGB').resize((int(img0.size[0] * scale), int(img0.size[1] * scale)))
|
48 |
+
else:
|
49 |
+
img = img0.convert('RGB')
|
50 |
npa = np.array(img)
|
51 |
blue = npa[:, :, 2]
|
52 |
blue_torch = torch.tensor(blue).float().to(device)
|
|
|
75 |
fixed_r = np.where(mask, fixed_r, npa[:, :, 0])
|
76 |
fixed_g = np.where(mask, fixed_g, npa[:, :, 1])
|
77 |
fixed_b = np.where(mask, fixed_b, npa[:, :, 2])
|
78 |
+
|
79 |
if meaningful_diff > 0:
|
80 |
diff_r = np.abs(fixed_r - npa[:, :, 0])
|
81 |
diff_g = np.abs(fixed_g - npa[:, :, 1])
|
|
|
108 |
erosion = gr.Slider(minimum=1, maximum=10, value=2, label="Erosion", step=1)
|
109 |
dilation = gr.Slider(minimum=1, maximum=10, value=10, label="Dilation", step=1)
|
110 |
mask_only = gr.Checkbox(value=False, label="Mask Only")
|
111 |
+
meaningful_diff = gr.Slider(minimum=0, maximum=128, value=50, label="Meaningful Diff", step=1)
|
112 |
meaningful_ed = gr.Slider(minimum=1, maximum=10, value=2, label="Meaningful ED", step=1)
|
113 |
|
114 |
# Outputs Section
|