danu9327 commited on
Commit
1a7158c
โ€ข
1 Parent(s): 91602d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
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
- print(f"Mouse over position: ({x}, {y})")
 
 
 
 
 
 
 
 
 
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()