Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,41 +106,15 @@ def server(input, output, session: Session):
|
|
| 106 |
|
| 107 |
id = "image_" + str(i)
|
| 108 |
opacity = ui.input_slider(id, "Opacity", 0, 1.0, 0.5)
|
| 109 |
-
|
| 110 |
-
@render.plot
|
| 111 |
-
def plot_predicitons():
|
| 112 |
-
fig, ax = plt.subplots()
|
| 113 |
-
|
| 114 |
-
ax = plt.Axes(fig, [0., 0., 1., 1.])
|
| 115 |
-
ax.set_axis_off()
|
| 116 |
-
fig.add_axes(ax)
|
| 117 |
-
|
| 118 |
-
v = Visualizer(r["image"][:, :, ::-1],
|
| 119 |
-
scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
|
| 120 |
-
|
| 121 |
-
colours = []
|
| 122 |
-
for cls in r["instances"].pred_classes:
|
| 123 |
-
if cls == 0:
|
| 124 |
-
colours.append([1,0,0])
|
| 125 |
-
elif cls == 1:
|
| 126 |
-
colours.append([1,1,0])
|
| 127 |
-
elif cls == 2:
|
| 128 |
-
colours.append([0,0,0])
|
| 129 |
-
|
| 130 |
-
out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
|
| 131 |
-
assigned_colors = colours,
|
| 132 |
-
alpha = opacity)
|
| 133 |
-
ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
|
| 134 |
-
|
| 135 |
-
return fig
|
| 136 |
|
| 137 |
-
|
|
|
|
| 138 |
|
| 139 |
output.append(
|
| 140 |
ui.div(
|
| 141 |
ui.row(
|
| 142 |
ui.column(4, ui.img(src=f"data:image/png;base64,{r['image_base64']}")),
|
| 143 |
-
ui.column(4, ui.output_plot(
|
| 144 |
),
|
| 145 |
opacity,
|
| 146 |
ui.h5(r['filename'], style="margin-top: 15px;"),
|
|
@@ -154,7 +128,36 @@ def server(input, output, session: Session):
|
|
| 154 |
class_="card p-3"
|
| 155 |
)
|
| 156 |
)
|
| 157 |
-
return ui.div(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
@session.download()
|
| 160 |
def download():
|
|
|
|
| 106 |
|
| 107 |
id = "image_" + str(i)
|
| 108 |
opacity = ui.input_slider(id, "Opacity", 0, 1.0, 0.5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
plot_name = f"plot_{i}"
|
| 111 |
+
output(create_plot(r), id=plotname)
|
| 112 |
|
| 113 |
output.append(
|
| 114 |
ui.div(
|
| 115 |
ui.row(
|
| 116 |
ui.column(4, ui.img(src=f"data:image/png;base64,{r['image_base64']}")),
|
| 117 |
+
ui.column(4, ui.output_plot(plot_name)),
|
| 118 |
),
|
| 119 |
opacity,
|
| 120 |
ui.h5(r['filename'], style="margin-top: 15px;"),
|
|
|
|
| 128 |
class_="card p-3"
|
| 129 |
)
|
| 130 |
)
|
| 131 |
+
return ui.div(output)
|
| 132 |
+
|
| 133 |
+
def create_plot(r):
|
| 134 |
+
@render.plot
|
| 135 |
+
def plot_predicitons():
|
| 136 |
+
fig, ax = plt.subplots()
|
| 137 |
+
|
| 138 |
+
ax = plt.Axes(fig, [0., 0., 1., 1.])
|
| 139 |
+
ax.set_axis_off()
|
| 140 |
+
fig.add_axes(ax)
|
| 141 |
+
|
| 142 |
+
v = Visualizer(r["image"][:, :, ::-1],
|
| 143 |
+
scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
|
| 144 |
+
|
| 145 |
+
colours = []
|
| 146 |
+
for cls in r["instances"].pred_classes:
|
| 147 |
+
if cls == 0:
|
| 148 |
+
colours.append([1,0,0])
|
| 149 |
+
elif cls == 1:
|
| 150 |
+
colours.append([1,1,0])
|
| 151 |
+
elif cls == 2:
|
| 152 |
+
colours.append([0,0,0])
|
| 153 |
+
|
| 154 |
+
out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
|
| 155 |
+
assigned_colors = colours,
|
| 156 |
+
alpha = opacity)
|
| 157 |
+
ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
|
| 158 |
+
|
| 159 |
+
return fig
|
| 160 |
+
return plot_predicitons
|
| 161 |
|
| 162 |
@session.download()
|
| 163 |
def download():
|