Spaces:
Running
Running
phyloforfun
commited on
Commit
·
ff6cbfc
1
Parent(s):
b769563
file upload
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
import yaml, os, json, random, time, re
|
3 |
import matplotlib.pyplot as plt
|
4 |
import plotly.graph_objs as go
|
5 |
import numpy as np
|
@@ -276,7 +276,20 @@ def create_space_saver():
|
|
276 |
st.session_state.config['leafmachine']['project']['delete_temps_keep_VVE'] = st.checkbox("Delete Temporary Files (KEEP files required for VoucherVisionEditor)", st.session_state.config['leafmachine']['project'].get('delete_temps_keep_VVE', False))
|
277 |
st.session_state.config['leafmachine']['project']['delete_all_temps'] = st.checkbox("Keep only the final transcription file", st.session_state.config['leafmachine']['project'].get('delete_all_temps', False),help="*WARNING:* This limits your ability to do quality assurance. This will delete all folders created by VoucherVision, leaving only the `transcription.xlsx` file.")
|
278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
|
282 |
# def create_private_file():
|
@@ -1051,7 +1064,7 @@ def content_tab_settings():
|
|
1051 |
|
1052 |
### Input Images Local
|
1053 |
with col_local_1:
|
1054 |
-
st.session_state.config['leafmachine']['project']['dir_images_local'] = st.text_input("Input images directory", st.session_state.config['leafmachine']['project'].get('dir_images_local', ''))
|
1055 |
st.session_state.config['leafmachine']['project']['continue_run_from_partial_xlsx'] = st.text_input("Continue run from partially completed project XLSX", st.session_state.config['leafmachine']['project'].get('continue_run_from_partial_xlsx', ''), disabled=True)
|
1056 |
st.write("---")
|
1057 |
st.subheader('LLM Version')
|
@@ -1073,29 +1086,16 @@ def content_tab_settings():
|
|
1073 |
st.session_state.config['leafmachine']['project']['prompt_version'] = st.selectbox("Prompt Version", versions, index=versions.index(selected_version))
|
1074 |
|
1075 |
with col_local_2:
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
st.
|
1081 |
-
st.
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
### Modules
|
1088 |
-
# with col_m1:
|
1089 |
-
# st.session_state.config['leafmachine']['modules']['specimen_crop'] = st.checkbox("Specimen Close-up", st.session_state.config['leafmachine']['modules'].get('specimen_crop', True),disabled=True)
|
1090 |
-
|
1091 |
-
### cropped_components
|
1092 |
-
# with col_cropped_1:
|
1093 |
-
# st.session_state.config['leafmachine']['cropped_components']['do_save_cropped_annotations'] = st.checkbox("Save cropped components as images", st.session_state.config['leafmachine']['cropped_components'].get('do_save_cropped_annotations', True), disabled=True)
|
1094 |
-
# st.session_state.config['leafmachine']['cropped_components']['save_per_image'] = st.checkbox("Save cropped components grouped by specimen", st.session_state.config['leafmachine']['cropped_components'].get('save_per_image', False), disabled=True)
|
1095 |
-
# st.session_state.config['leafmachine']['cropped_components']['save_per_annotation_class'] = st.checkbox("Save cropped components grouped by type", st.session_state.config['leafmachine']['cropped_components'].get('save_per_annotation_class', True), disabled=True)
|
1096 |
-
# st.session_state.config['leafmachine']['cropped_components']['binarize_labels'] = st.checkbox("Binarize labels", st.session_state.config['leafmachine']['cropped_components'].get('binarize_labels', False), disabled=True)
|
1097 |
-
# st.session_state.config['leafmachine']['cropped_components']['binarize_labels_skeletonize'] = st.checkbox("Binarize and skeletonize labels", st.session_state.config['leafmachine']['cropped_components'].get('binarize_labels_skeletonize', False), disabled=True)
|
1098 |
-
|
1099 |
with col_cropped_1:
|
1100 |
default_crops = st.session_state.config['leafmachine']['cropped_components'].get('save_cropped_annotations', ['leaf_whole'])
|
1101 |
st.write("Prior to transcription, use LeafMachine2 to crop all labels from input images to create label collages for each specimen image. (Requires GPU)")
|
|
|
1 |
import streamlit as st
|
2 |
+
import yaml, os, json, random, time, re, shutil
|
3 |
import matplotlib.pyplot as plt
|
4 |
import plotly.graph_objs as go
|
5 |
import numpy as np
|
|
|
276 |
st.session_state.config['leafmachine']['project']['delete_temps_keep_VVE'] = st.checkbox("Delete Temporary Files (KEEP files required for VoucherVisionEditor)", st.session_state.config['leafmachine']['project'].get('delete_temps_keep_VVE', False))
|
277 |
st.session_state.config['leafmachine']['project']['delete_all_temps'] = st.checkbox("Keep only the final transcription file", st.session_state.config['leafmachine']['project'].get('delete_all_temps', False),help="*WARNING:* This limits your ability to do quality assurance. This will delete all folders created by VoucherVision, leaving only the `transcription.xlsx` file.")
|
278 |
|
279 |
+
def save_uploaded_file(directory, img_file):
|
280 |
+
if not os.path.exists(directory):
|
281 |
+
os.makedirs(directory)
|
282 |
+
# Assuming the uploaded file is an image
|
283 |
+
with Image.open(img_file) as image:
|
284 |
+
# Save the image with a jpg extension
|
285 |
+
image.save(os.path.join(directory, img_file.name), "JPG")
|
286 |
|
287 |
+
def delete_directory(dir_path):
|
288 |
+
try:
|
289 |
+
shutil.rmtree(dir_path)
|
290 |
+
st.success(f"Deleted folder: {dir_path}")
|
291 |
+
except OSError as e:
|
292 |
+
st.error(f"Error: {dir_path} : {e.strerror}")
|
293 |
|
294 |
|
295 |
# def create_private_file():
|
|
|
1064 |
|
1065 |
### Input Images Local
|
1066 |
with col_local_1:
|
1067 |
+
st.session_state.config['leafmachine']['project']['dir_images_local'] = st.session_state['dir_uploaded_images'] #st.text_input("Input images directory", st.session_state.config['leafmachine']['project'].get('dir_images_local', ''))
|
1068 |
st.session_state.config['leafmachine']['project']['continue_run_from_partial_xlsx'] = st.text_input("Continue run from partially completed project XLSX", st.session_state.config['leafmachine']['project'].get('continue_run_from_partial_xlsx', ''), disabled=True)
|
1069 |
st.write("---")
|
1070 |
st.subheader('LLM Version')
|
|
|
1086 |
st.session_state.config['leafmachine']['project']['prompt_version'] = st.selectbox("Prompt Version", versions, index=versions.index(selected_version))
|
1087 |
|
1088 |
with col_local_2:
|
1089 |
+
st.session_state['dir_uploaded_images'] = os.path.join(st.session_state.dir_home,'uploads')
|
1090 |
+
uploaded_files = st.file_uploader("Upload Images", type=['jpg', 'jpeg'], accept_multiple_files=True)
|
1091 |
+
if uploaded_files:
|
1092 |
+
delete_directory(st.session_state['dir_uploaded_images'])
|
1093 |
+
st.session_state['dir_uploaded_images'] = os.path.join(st.session_state.dir_home,'uploads')
|
1094 |
+
validate_dir(st.session_state['dir_uploaded_images'])
|
1095 |
+
for uploaded_file in uploaded_files:
|
1096 |
+
print(uploaded_file)
|
1097 |
+
save_uploaded_file(st.session_state['dir_uploaded_images'], uploaded_file)
|
1098 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1099 |
with col_cropped_1:
|
1100 |
default_crops = st.session_state.config['leafmachine']['cropped_components'].get('save_cropped_annotations', ['leaf_whole'])
|
1101 |
st.write("Prior to transcription, use LeafMachine2 to crop all labels from input images to create label collages for each specimen image. (Requires GPU)")
|