Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -46,6 +46,26 @@ class FeatureLoss(nn.Module):
|
|
46 |
def __del__(self): self.hooks.remove()
|
47 |
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
MODEL_URL = "https://www.dropbox.com/s/05ong36r29h51ov/popd.pkl?dl=1"
|
50 |
urllib.request.urlretrieve(MODEL_URL, "popd.pkl")
|
51 |
path = Path(".")
|
@@ -70,4 +90,27 @@ if uploaded_file is not None:
|
|
70 |
white_areas = (red == 0) & (blue == 0) & (green == 0)
|
71 |
data[..., :-1][white_areas.T] = (0,0,0) # Transpose back needed
|
72 |
im2 = Image.fromarray(data)
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
def __del__(self): self.hooks.remove()
|
47 |
|
48 |
|
49 |
+
def getNeighbours(i, j, n, m) :
|
50 |
+
arr = []
|
51 |
+
if i-1 >= 0 and j-1 >= 0 :
|
52 |
+
arr.append((i-1, j-1))
|
53 |
+
if i-1 >= 0 :
|
54 |
+
arr.append((i-1, j))
|
55 |
+
if i-1 >= 0 and j+1 < m :
|
56 |
+
arr.append((i-1, j+1))
|
57 |
+
if j+1 < m :
|
58 |
+
arr.append((i, j+1))
|
59 |
+
if i+1 < n and j+1 < m :
|
60 |
+
arr.append((i+1, j+1))
|
61 |
+
if i+1 < n :
|
62 |
+
arr.append((i+1, j))
|
63 |
+
if i+1 < n and j-1 >= 0 :
|
64 |
+
arr.append((i+1, j-1))
|
65 |
+
if j-1 >= 0 :
|
66 |
+
arr.append((i, j-1))
|
67 |
+
return arr
|
68 |
+
|
69 |
MODEL_URL = "https://www.dropbox.com/s/05ong36r29h51ov/popd.pkl?dl=1"
|
70 |
urllib.request.urlretrieve(MODEL_URL, "popd.pkl")
|
71 |
path = Path(".")
|
|
|
90 |
white_areas = (red == 0) & (blue == 0) & (green == 0)
|
91 |
data[..., :-1][white_areas.T] = (0,0,0) # Transpose back needed
|
92 |
im2 = Image.fromarray(data)
|
93 |
+
membuf = BytesIO()
|
94 |
+
im2.save(membuf, format="png")
|
95 |
+
img = Image.open(membuf)
|
96 |
+
bitmap = img.load()
|
97 |
+
n = img.size[0]
|
98 |
+
m = img.size[1]
|
99 |
+
stateMap = []
|
100 |
+
for i in range(n):
|
101 |
+
stateMap.append([False for j in range(m)])
|
102 |
+
queue = [(0, 0)]
|
103 |
+
while queue:
|
104 |
+
e = queue.pop(0)
|
105 |
+
i = e[0]
|
106 |
+
j = e[1]
|
107 |
+
if not stateMap[i][j]:
|
108 |
+
stateMap[i][j] = True
|
109 |
+
color = int((bitmap[i, j][0] + bitmap[i, j][1] + bitmap[i, j][2])/3)
|
110 |
+
if color > 100:
|
111 |
+
bitmap[i, j] = (0, 0, 0)
|
112 |
+
neigh = getNeighbours(i, j, n, m)
|
113 |
+
for ne in neigh:
|
114 |
+
queue.append(ne)
|
115 |
+
|
116 |
+
st.image(img, caption='PoP ArT')
|