Update app.py
Browse files
app.py
CHANGED
@@ -82,49 +82,35 @@ def draw_plot(pred_img, seg):
|
|
82 |
plt.axis('off')
|
83 |
LABEL_NAMES = np.asarray(labels_list)
|
84 |
FULL_LABEL_MAP = np.arange(len(LABEL_NAMES)).reshape(len(LABEL_NAMES), 1)
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
for label, color in enumerate(colormap):
|
114 |
-
color_seg[seg.numpy() == label, :] = color
|
115 |
-
|
116 |
-
# Show image + mask
|
117 |
-
pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
|
118 |
-
pred_img = pred_img.astype(np.uint8)
|
119 |
|
120 |
-
fig = draw_plot(pred_img, seg)
|
121 |
-
return fig
|
122 |
|
123 |
-
demo = gr.Interface(fn=sepia,
|
124 |
-
inputs=gr.Image(shape=(400, 600)),
|
125 |
-
outputs=['plot'],
|
126 |
-
examples=["side-1.jpg", "side-2.jpg", "side-3.jpg", "side-4.jpg"],
|
127 |
-
allow_flagging='never')
|
128 |
|
129 |
|
130 |
-
demo.launch()
|
|
|
82 |
plt.axis('off')
|
83 |
LABEL_NAMES = np.asarray(labels_list)
|
84 |
FULL_LABEL_MAP = np.arange(len(LABEL_NAMES)).reshape(len(LABEL_NAMES), 1)
|
85 |
+
FULL_COLOR
|
86 |
+
|
87 |
+
def get_labels():
|
88 |
+
with open(r'labels.txt', 'r') as fp:
|
89 |
+
labels = []
|
90 |
+
for line in fp:
|
91 |
+
labels.append(line[:-1])
|
92 |
+
return labels
|
93 |
+
|
94 |
+
# 레이블 목록 가져오기
|
95 |
+
labels = get_labels()
|
96 |
+
|
97 |
+
# 버튼 생성
|
98 |
+
buttons = []
|
99 |
+
for label in labels:
|
100 |
+
button = gr.Button(label)
|
101 |
+
def display_seg(label):
|
102 |
+
seg = np.where(seg == labels.index(label), 1, 0)
|
103 |
+
pred_img = np.array(input_img) * 0.5 + seg * 0.5
|
104 |
+
pred_img = pred_img.astype(np.uint8)
|
105 |
+
fig = draw_plot(pred_img, seg)
|
106 |
+
return fig
|
107 |
+
|
108 |
+
button.click(display_seg, label)
|
109 |
+
buttons.append(button)
|
110 |
+
|
111 |
+
demo.components.append(buttons)
|
112 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
|
|
|
|
114 |
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
|
|