haritsahm commited on
Commit
3f1c719
·
1 Parent(s): e661c00

recompute embedding if missing or state change

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -20,6 +20,11 @@ def process_box(predictor_model, show_mask, radius_width):
20
  scale = container_width/width
21
  scaled_hw = (container_width, int(height * scale))
22
 
 
 
 
 
 
23
  if 'result_image' not in st.session_state:
24
  st.session_state.result_image = bg_image.resize(scaled_hw)
25
 
@@ -94,6 +99,11 @@ def process_click(predictor_model, show_mask, radius_width):
94
  scale = container_width/width
95
  scaled_hw = (container_width, int(height * scale))
96
 
 
 
 
 
 
97
  if 'result_image' not in st.session_state:
98
  st.session_state.result_image = bg_image.resize(scaled_hw)
99
 
@@ -218,6 +228,10 @@ def image_preprocess_callback(predictor_model, option):
218
  np_image = np.asanyarray(image)
219
  with st.spinner(text="Extracing embeddings.."):
220
  predictor_model.set_image(np_image)
 
 
 
 
221
  st.session_state.image = image
222
  else:
223
  with st.spinner(text="Cleaning up!"):
 
20
  scale = container_width/width
21
  scaled_hw = (container_width, int(height * scale))
22
 
23
+ if not predictor_model.set_image:
24
+ np_image = np.asanyarray(bg_image)
25
+ with st.spinner(text="Extracing embeddings.."):
26
+ predictor_model.set_image(np_image)
27
+
28
  if 'result_image' not in st.session_state:
29
  st.session_state.result_image = bg_image.resize(scaled_hw)
30
 
 
99
  scale = container_width/width
100
  scaled_hw = (container_width, int(height * scale))
101
 
102
+ if not predictor_model.set_image:
103
+ np_image = np.asanyarray(bg_image)
104
+ with st.spinner(text="Extracing embeddings.."):
105
+ predictor_model.set_image(np_image)
106
+
107
  if 'result_image' not in st.session_state:
108
  st.session_state.result_image = bg_image.resize(scaled_hw)
109
 
 
228
  np_image = np.asanyarray(image)
229
  with st.spinner(text="Extracing embeddings.."):
230
  predictor_model.set_image(np_image)
231
+ else:
232
+ if predictor_model:
233
+ predictor_model.reset_image()
234
+
235
  st.session_state.image = image
236
  else:
237
  with st.spinner(text="Cleaning up!"):