Skip to content

Commit b189357

Browse files
authored
Improved exception handling for LangSAM GUI (#130)
1 parent b344e66 commit b189357

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

samgeo/common.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,18 +2496,22 @@ def segment_button_click(change):
24962496
filename = os.path.join(
24972497
out_dir, f"{layer_name}_{random_string()}.tif"
24982498
)
2499-
sam.predict(
2500-
sam.source,
2501-
text_prompt.value,
2502-
box_slider.value,
2503-
text_slider.value,
2504-
output=filename,
2505-
)
2506-
sam.output = filename
2507-
if m.find_layer(layer_name) is not None:
2508-
m.remove_layer(m.find_layer(layer_name))
2509-
if m.find_layer(f"{layer_name}_rect") is not None:
2510-
m.remove_layer(m.find_layer(f"{layer_name} Regularized"))
2499+
try:
2500+
sam.predict(
2501+
sam.source,
2502+
text_prompt.value,
2503+
box_slider.value,
2504+
text_slider.value,
2505+
output=filename,
2506+
)
2507+
sam.output = filename
2508+
if m.find_layer(layer_name) is not None:
2509+
m.remove_layer(m.find_layer(layer_name))
2510+
if m.find_layer(f"{layer_name}_rect") is not None:
2511+
m.remove_layer(m.find_layer(f"{layer_name} Regularized"))
2512+
except Exception as e:
2513+
output.clear_output()
2514+
print(e)
25112515
if os.path.exists(filename):
25122516
try:
25132517
m.add_raster(

0 commit comments

Comments
 (0)