Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -74,6 +74,11 @@ def draw_plot(pred_img, seg):
|
|
74 |
ax.tick_params(width=0.0, labelsize=25)
|
75 |
return fig
|
76 |
|
|
|
|
|
|
|
|
|
|
|
77 |
def sepia(input_img):
|
78 |
input_img = Image.fromarray(input_img)
|
79 |
|
@@ -93,13 +98,17 @@ def sepia(input_img):
|
|
93 |
for label, color in enumerate(colormap):
|
94 |
color_seg[seg.numpy() == label, :] = color
|
95 |
|
|
|
|
|
96 |
# Show image + mask
|
97 |
pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
|
98 |
pred_img = pred_img.astype(np.uint8)
|
99 |
|
100 |
fig = draw_plot(pred_img, seg)
|
|
|
101 |
return fig
|
102 |
|
|
|
103 |
demo = gr.Interface(fn=sepia,
|
104 |
inputs=gr.Image(shape=(400, 600)),
|
105 |
outputs=['plot'],
|
|
|
74 |
ax.tick_params(width=0.0, labelsize=25)
|
75 |
return fig
|
76 |
|
77 |
+
def segmentation_to_text(seg):
|
78 |
+
seg = seg.numpy()
|
79 |
+
labels_text = [labels_list[label] for label in np.unique(seg)]
|
80 |
+
return ", ".join(labels_text)
|
81 |
+
|
82 |
def sepia(input_img):
|
83 |
input_img = Image.fromarray(input_img)
|
84 |
|
|
|
98 |
for label, color in enumerate(colormap):
|
99 |
color_seg[seg.numpy() == label, :] = color
|
100 |
|
101 |
+
seg_text = segmentation_to_text(seg)
|
102 |
+
|
103 |
# Show image + mask
|
104 |
pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
|
105 |
pred_img = pred_img.astype(np.uint8)
|
106 |
|
107 |
fig = draw_plot(pred_img, seg)
|
108 |
+
plt.text(0, -20, seg_text, fontsize=12, color='black', ha='left', va='top', backgroundcolor='gray', wrap=True)
|
109 |
return fig
|
110 |
|
111 |
+
|
112 |
demo = gr.Interface(fn=sepia,
|
113 |
inputs=gr.Image(shape=(400, 600)),
|
114 |
outputs=['plot'],
|