Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -53,16 +53,17 @@ regex = re.compile(".*?\((.*?)\)")
|
|
53 |
def draw_polygons(polygons, colors, im_size=(512, 512), b_color="white", fpath=None):
|
54 |
|
55 |
image = Image.new("RGBA", im_size, color="white")
|
56 |
-
draw = aggdraw.Draw(image)
|
|
|
57 |
|
58 |
for poly, color, in zip(polygons, colors):
|
59 |
#get initial polygon coordinates
|
60 |
xy = poly.exterior.xy
|
61 |
coords = np.dstack((xy[1], xy[0])).flatten()
|
62 |
# draw it on canvas, with the appropriate colors
|
63 |
-
brush = aggdraw.Brush((0, 0, 0), opacity=255)
|
64 |
-
draw.polygon(coords, brush)
|
65 |
-
|
66 |
|
67 |
#get inner polygon coordinates
|
68 |
small_poly = poly.buffer(-1, resolution=32, cap_style=2, join_style=2, mitre_limit=5.0)
|
@@ -70,18 +71,21 @@ def draw_polygons(polygons, colors, im_size=(512, 512), b_color="white", fpath=N
|
|
70 |
mycoordslist = [list(x.exterior.coords) for x in small_poly]
|
71 |
for coord in mycoordslist:
|
72 |
coords = np.dstack((np.array(coord)[:,1], np.array(coord)[:, 0])).flatten()
|
73 |
-
brush2 = aggdraw.Brush((0, 0, 0), opacity=255)
|
74 |
-
draw.polygon(coords, brush2)
|
|
|
75 |
elif poly.geom_type == 'Polygon':
|
76 |
#get inner polygon coordinates
|
77 |
xy2 = small_poly.exterior.xy
|
78 |
coords2 = np.dstack((xy2[1], xy2[0])).flatten()
|
79 |
# draw it on canvas, with the appropriate colors
|
80 |
-
brush2 = aggdraw.Brush((color[0], color[1], color[2]), opacity=255)
|
81 |
-
draw.polygon(coords2, brush2)
|
82 |
-
|
83 |
-
image = Image.frombytes("RGBA", im_size, draw.tobytes()).transpose(Image.FLIP_TOP_BOTTOM)
|
84 |
|
|
|
|
|
|
|
85 |
if(fpath):
|
86 |
image.save(fpath, quality=100, subsampling=0)
|
87 |
|
@@ -255,11 +259,12 @@ textbox = gr.inputs.Textbox(placeholder='An apartment with two bedrooms and one
|
|
255 |
generated = gr.outputs.Image(label='Generated Layout')
|
256 |
|
257 |
iface = gr.Interface(fn=prompt_to_layout, inputs=[textbox, creative_slider],
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
|
|
264 |
|
265 |
iface.launch()
|
|
|
53 |
def draw_polygons(polygons, colors, im_size=(512, 512), b_color="white", fpath=None):
|
54 |
|
55 |
image = Image.new("RGBA", im_size, color="white")
|
56 |
+
#draw = aggdraw.Draw(image)
|
57 |
+
draw = ImageDraw.Draw(image)
|
58 |
|
59 |
for poly, color, in zip(polygons, colors):
|
60 |
#get initial polygon coordinates
|
61 |
xy = poly.exterior.xy
|
62 |
coords = np.dstack((xy[1], xy[0])).flatten()
|
63 |
# draw it on canvas, with the appropriate colors
|
64 |
+
#brush = aggdraw.Brush((0, 0, 0), opacity=255)
|
65 |
+
#draw.polygon(coords, brush)
|
66 |
+
draw.polygon(list(coords), fill=(0, 0, 0))
|
67 |
|
68 |
#get inner polygon coordinates
|
69 |
small_poly = poly.buffer(-1, resolution=32, cap_style=2, join_style=2, mitre_limit=5.0)
|
|
|
71 |
mycoordslist = [list(x.exterior.coords) for x in small_poly]
|
72 |
for coord in mycoordslist:
|
73 |
coords = np.dstack((np.array(coord)[:,1], np.array(coord)[:, 0])).flatten()
|
74 |
+
#brush2 = aggdraw.Brush((0, 0, 0), opacity=255)
|
75 |
+
#draw.polygon(coords, brush2)
|
76 |
+
draw.polygon(list(coords), fill=tuple(color))
|
77 |
elif poly.geom_type == 'Polygon':
|
78 |
#get inner polygon coordinates
|
79 |
xy2 = small_poly.exterior.xy
|
80 |
coords2 = np.dstack((xy2[1], xy2[0])).flatten()
|
81 |
# draw it on canvas, with the appropriate colors
|
82 |
+
#brush2 = aggdraw.Brush((color[0], color[1], color[2]), opacity=255)
|
83 |
+
#draw.polygon(coords2, brush2)
|
84 |
+
draw.polygon(list(coords2), fill=tuple(color))
|
|
|
85 |
|
86 |
+
#image = Image.frombytes("RGBA", im_size, draw.tobytes()).transpose(Image.FLIP_TOP_BOTTOM)
|
87 |
+
image = image.transpose(Image.FLIP_TOP_BOTTOM)
|
88 |
+
|
89 |
if(fpath):
|
90 |
image.save(fpath, quality=100, subsampling=0)
|
91 |
|
|
|
259 |
generated = gr.outputs.Image(label='Generated Layout')
|
260 |
|
261 |
iface = gr.Interface(fn=prompt_to_layout, inputs=[textbox, creative_slider],
|
262 |
+
outputs=[generated],
|
263 |
+
css=custom_css,
|
264 |
+
theme="default",
|
265 |
+
allow_flagging=False,
|
266 |
+
allow_screenshot=False,
|
267 |
+
thumbnail="thumbnail_gradio.PNG",
|
268 |
+
enable_queue=True)
|
269 |
|
270 |
iface.launch()
|