Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,7 +48,40 @@ app_ui = ui.page_fluid(
|
|
| 48 |
)
|
| 49 |
)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
def server(input, output, session: Session):
|
| 54 |
analysis_results = reactive.Value([])
|
|
@@ -93,38 +126,6 @@ def server(input, output, session: Session):
|
|
| 93 |
# Update reactive value
|
| 94 |
analysis_results.set(results)
|
| 95 |
|
| 96 |
-
@render.plot
|
| 97 |
-
def create_plot(i, r, opacity):
|
| 98 |
-
@output(id="plot_" + str(i))
|
| 99 |
-
@render.plot
|
| 100 |
-
def plot_prediction():
|
| 101 |
-
fig, ax = plt.subplots()
|
| 102 |
-
|
| 103 |
-
# ax = plt.Axes(fig, [0., 0., 1., 1.])
|
| 104 |
-
# ax.set_axis_off()
|
| 105 |
-
# fig.add_axes(ax)
|
| 106 |
-
|
| 107 |
-
v = Visualizer(r["image"][:, :, ::-1],
|
| 108 |
-
scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
|
| 109 |
-
|
| 110 |
-
colours = []
|
| 111 |
-
for cls in r["instances"].pred_classes:
|
| 112 |
-
if cls == 0:
|
| 113 |
-
colours.append([1,0,0])
|
| 114 |
-
elif cls == 1:
|
| 115 |
-
colours.append([1,1,0])
|
| 116 |
-
elif cls == 2:
|
| 117 |
-
colours.append([0,0,0])
|
| 118 |
-
|
| 119 |
-
out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
|
| 120 |
-
assigned_colors = colours,
|
| 121 |
-
alpha = opacity)
|
| 122 |
-
|
| 123 |
-
ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
|
| 124 |
-
|
| 125 |
-
return fig
|
| 126 |
-
return plot_prediction
|
| 127 |
-
|
| 128 |
@output
|
| 129 |
@render.ui
|
| 130 |
def results_container():
|
|
@@ -139,13 +140,13 @@ def server(input, output, session: Session):
|
|
| 139 |
id = "image_" + str(i)
|
| 140 |
opacity = ui.input_slider(id, "Opacity", 0, 1.0, 0.5)
|
| 141 |
|
| 142 |
-
|
| 143 |
|
| 144 |
ui_output.append(
|
| 145 |
ui.div(
|
| 146 |
ui.row(
|
| 147 |
ui.column(4, ui.img(src=f"data:image/png;base64,{r['image_base64']}")),
|
| 148 |
-
|
| 149 |
),
|
| 150 |
opacity,
|
| 151 |
ui.h5(r['filename'], style="margin-top: 15px;"),
|
|
|
|
| 48 |
)
|
| 49 |
)
|
| 50 |
|
| 51 |
+
@module.ui
|
| 52 |
+
def plot_ui():
|
| 53 |
+
return ui.card(ui.column(4, ui.output_plot("plot_prediction")))
|
| 54 |
|
| 55 |
+
@module.server
|
| 56 |
+
def plot_server(input, output, session, r, opacity):
|
| 57 |
+
@output
|
| 58 |
+
@render.plot
|
| 59 |
+
def plot_prediction():
|
| 60 |
+
fig, ax = plt.subplots()
|
| 61 |
+
|
| 62 |
+
# ax = plt.Axes(fig, [0., 0., 1., 1.])
|
| 63 |
+
# ax.set_axis_off()
|
| 64 |
+
# fig.add_axes(ax)
|
| 65 |
+
|
| 66 |
+
v = Visualizer(r["image"][:, :, ::-1],
|
| 67 |
+
scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
|
| 68 |
+
|
| 69 |
+
colours = []
|
| 70 |
+
for cls in r["instances"].pred_classes:
|
| 71 |
+
if cls == 0:
|
| 72 |
+
colours.append([1,0,0])
|
| 73 |
+
elif cls == 1:
|
| 74 |
+
colours.append([1,1,0])
|
| 75 |
+
elif cls == 2:
|
| 76 |
+
colours.append([0,0,0])
|
| 77 |
+
|
| 78 |
+
out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
|
| 79 |
+
assigned_colors = colours,
|
| 80 |
+
alpha = opacity)
|
| 81 |
+
|
| 82 |
+
ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
|
| 83 |
+
|
| 84 |
+
return fig
|
| 85 |
|
| 86 |
def server(input, output, session: Session):
|
| 87 |
analysis_results = reactive.Value([])
|
|
|
|
| 126 |
# Update reactive value
|
| 127 |
analysis_results.set(results)
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
@output
|
| 130 |
@render.ui
|
| 131 |
def results_container():
|
|
|
|
| 140 |
id = "image_" + str(i)
|
| 141 |
opacity = ui.input_slider(id, "Opacity", 0, 1.0, 0.5)
|
| 142 |
|
| 143 |
+
plot_server(f"plot_{i}")
|
| 144 |
|
| 145 |
ui_output.append(
|
| 146 |
ui.div(
|
| 147 |
ui.row(
|
| 148 |
ui.column(4, ui.img(src=f"data:image/png;base64,{r['image_base64']}")),
|
| 149 |
+
plot_ui(f"plot_{i}"),
|
| 150 |
),
|
| 151 |
opacity,
|
| 152 |
ui.h5(r['filename'], style="margin-top: 15px;"),
|