Update app.py
Browse files
app.py
CHANGED
@@ -91,10 +91,19 @@ def draw_plot(pred_img, seg):
|
|
91 |
plt.xticks([], [])
|
92 |
ax.tick_params(width=0.0, labelsize=25)
|
93 |
return fig
|
94 |
-
|
95 |
def on_mouseover(mouse_info):
|
96 |
x, y = mouse_info["position"]
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
def sepia(input_img):
|
100 |
input_img = Image.fromarray(input_img)
|
@@ -107,6 +116,7 @@ def sepia(input_img):
|
|
107 |
logits = tf.image.resize(
|
108 |
logits, input_img.size[::-1]
|
109 |
) # We reverse the shape of `image` because `image.size` returns width and height.
|
|
|
110 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
111 |
|
112 |
color_seg = np.zeros(
|
@@ -120,7 +130,6 @@ def sepia(input_img):
|
|
120 |
pred_img = pred_img.astype(np.uint8)
|
121 |
|
122 |
fig = draw_plot(pred_img, seg)
|
123 |
-
#filename = input_image.name if hasattr(input_image, "name") else "Unknown filename"
|
124 |
return fig
|
125 |
|
126 |
demo = gr.Interface(fn=sepia,
|
@@ -132,5 +141,4 @@ demo = gr.Interface(fn=sepia,
|
|
132 |
allow_flagging='never',
|
133 |
events=[gr.Mouse(on_mouseover)])
|
134 |
|
135 |
-
|
136 |
demo.launch()
|
|
|
91 |
plt.xticks([], [])
|
92 |
ax.tick_params(width=0.0, labelsize=25)
|
93 |
return fig
|
94 |
+
|
95 |
def on_mouseover(mouse_info):
|
96 |
x, y = mouse_info["position"]
|
97 |
+
|
98 |
+
# ์ฌ์ฉ์ ์ ์ ํจ์๋ฅผ ํธ์ถํ์ฌ ํน์ ์์ญ์ ๊ฐ์กฐ
|
99 |
+
highlight_segmentation(x, y)
|
100 |
+
|
101 |
+
def highlight_segmentation(x, y):
|
102 |
+
# ๋ง์ฐ์ค ์์น์ ๋ํ ์ธ๊ทธ๋ฉํ
์ด์
์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
103 |
+
seg_value = seg.numpy()[y, x]
|
104 |
+
|
105 |
+
# ์ธ๊ทธ๋ฉํ
์ด์
์ ๋ณด ์ถ๋ ฅ
|
106 |
+
print(f"Mouse over position: ({x}, {y}), Segmentation value: {seg_value}")
|
107 |
|
108 |
def sepia(input_img):
|
109 |
input_img = Image.fromarray(input_img)
|
|
|
116 |
logits = tf.image.resize(
|
117 |
logits, input_img.size[::-1]
|
118 |
) # We reverse the shape of `image` because `image.size` returns width and height.
|
119 |
+
global seg
|
120 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
121 |
|
122 |
color_seg = np.zeros(
|
|
|
130 |
pred_img = pred_img.astype(np.uint8)
|
131 |
|
132 |
fig = draw_plot(pred_img, seg)
|
|
|
133 |
return fig
|
134 |
|
135 |
demo = gr.Interface(fn=sepia,
|
|
|
141 |
allow_flagging='never',
|
142 |
events=[gr.Mouse(on_mouseover)])
|
143 |
|
|
|
144 |
demo.launch()
|