Spaces:
Runtime error
Runtime error
Commit
·
f7e2b79
1
Parent(s):
2b50844
update
Browse files
app.py
CHANGED
@@ -275,6 +275,13 @@ def clear_image_gallery():
|
|
275 |
validate_dir(st.session_state['dir_uploaded_images'])
|
276 |
validate_dir(st.session_state['dir_uploaded_images_small'])
|
277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
def main():
|
279 |
_, R_coverage, R_plot_area_cm2, R_save = st.columns([5,2,2,2])
|
280 |
img_gallery, img_main, img_seg, img_green, img_warp = st.columns([1,4,2,2,2])
|
@@ -309,8 +316,7 @@ def main():
|
|
309 |
st.info(f"Processing **{n_images}** images from {st.session_state['dir_input']}")
|
310 |
|
311 |
if st.session_state['dir_input'] is None:
|
312 |
-
|
313 |
-
st.session_state['input_list'] = [os.path.join(st.session_state['dir_input'], fname) for fname in os.listdir(st.session_state['dir_input']) if fname.endswith(('.jpg', '.jpeg', '.png'))]
|
314 |
|
315 |
# dir_input = st.text_input("Input directory for images:", value=os.path.join(st.session_state['dir_home'],"demo"))
|
316 |
dir_output = os.path.join(st.session_state['dir_home'],"demo_out") # st.text_input("Output directory:", value=os.path.join(st.session_state['dir_home'],"demo_out"))
|
@@ -322,15 +328,18 @@ def main():
|
|
322 |
file_name = os.path.join(directory_manager.data, f"{run_name}.csv")
|
323 |
headers = ['image',"plant_coverage_uncorrected_percen", "plant_coverage_corrected_percent", "plant_area_corrected_cm2"]
|
324 |
file_exists = os.path.isfile(file_name)
|
325 |
-
|
326 |
|
327 |
|
328 |
if len(st.session_state['input_list']) == 0 or st.session_state['input_list'] is None:
|
329 |
st.balloons()
|
|
|
|
|
330 |
else:
|
331 |
with img_gallery:
|
332 |
selected_img = image_select("Select an image", st.session_state['input_list'], use_container_width=False)
|
333 |
base_name = os.path.basename(selected_img)
|
|
|
334 |
|
335 |
if selected_img:
|
336 |
|
@@ -405,6 +414,8 @@ def main():
|
|
405 |
# Remove processed image from the list
|
406 |
st.session_state['input_list'].remove(selected_img)
|
407 |
st.rerun()
|
|
|
|
|
408 |
|
409 |
st.set_page_config(layout="wide", page_title='GreenSight')
|
410 |
|
@@ -436,4 +447,6 @@ if 'dir_uploaded_images_small' not in st.session_state:
|
|
436 |
|
437 |
|
438 |
st.title("GreenSight")
|
|
|
|
|
439 |
main()
|
|
|
275 |
validate_dir(st.session_state['dir_uploaded_images'])
|
276 |
validate_dir(st.session_state['dir_uploaded_images_small'])
|
277 |
|
278 |
+
def reset_demo_images():
|
279 |
+
st.session_state['dir_input'] = os.path.join(st.session_state['dir_home'],"demo")
|
280 |
+
st.session_state['input_list'] = [os.path.join(st.session_state['dir_input'], fname) for fname in os.listdir(st.session_state['dir_input']) if fname.endswith(('.jpg', '.jpeg', '.png'))]
|
281 |
+
n_images = len([f for f in os.listdir(st.session_state['dir_input']) if os.path.isfile(os.path.join(st.session_state['dir_input'], f))])
|
282 |
+
st.session_state['processing_add_on'] = f" {n_images} Images"
|
283 |
+
st.session_state['uploader_idk'] += 1
|
284 |
+
|
285 |
def main():
|
286 |
_, R_coverage, R_plot_area_cm2, R_save = st.columns([5,2,2,2])
|
287 |
img_gallery, img_main, img_seg, img_green, img_warp = st.columns([1,4,2,2,2])
|
|
|
316 |
st.info(f"Processing **{n_images}** images from {st.session_state['dir_input']}")
|
317 |
|
318 |
if st.session_state['dir_input'] is None:
|
319 |
+
reset_demo_images()
|
|
|
320 |
|
321 |
# dir_input = st.text_input("Input directory for images:", value=os.path.join(st.session_state['dir_home'],"demo"))
|
322 |
dir_output = os.path.join(st.session_state['dir_home'],"demo_out") # st.text_input("Output directory:", value=os.path.join(st.session_state['dir_home'],"demo_out"))
|
|
|
328 |
file_name = os.path.join(directory_manager.data, f"{run_name}.csv")
|
329 |
headers = ['image',"plant_coverage_uncorrected_percen", "plant_coverage_corrected_percent", "plant_area_corrected_cm2"]
|
330 |
file_exists = os.path.isfile(file_name)
|
331 |
+
st.button("Reset Demo Images", on_click=reset_demo_images)
|
332 |
|
333 |
|
334 |
if len(st.session_state['input_list']) == 0 or st.session_state['input_list'] is None:
|
335 |
st.balloons()
|
336 |
+
create_download_button(dir_output, run_name)
|
337 |
+
|
338 |
else:
|
339 |
with img_gallery:
|
340 |
selected_img = image_select("Select an image", st.session_state['input_list'], use_container_width=False)
|
341 |
base_name = os.path.basename(selected_img)
|
342 |
+
create_download_button(dir_output, run_name)
|
343 |
|
344 |
if selected_img:
|
345 |
|
|
|
414 |
# Remove processed image from the list
|
415 |
st.session_state['input_list'].remove(selected_img)
|
416 |
st.rerun()
|
417 |
+
create_download_button(dir_output, run_name)
|
418 |
+
|
419 |
|
420 |
st.set_page_config(layout="wide", page_title='GreenSight')
|
421 |
|
|
|
447 |
|
448 |
|
449 |
st.title("GreenSight")
|
450 |
+
st.write("Simple color segmentation app to estimate the vegetation coverage in a plot. Corners of the plot need to be marked with solid, uniforly colored flags.")
|
451 |
+
st.write("If you exit the session before completing the segmentation of all images, all progress will be lost!")
|
452 |
main()
|