Spaces:
Running
Running
Commit
·
7b8df6e
1
Parent(s):
22e0bab
file upload gallery
Browse files
app.py
CHANGED
|
@@ -279,20 +279,26 @@ def create_space_saver():
|
|
| 279 |
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))
|
| 280 |
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.")
|
| 281 |
|
| 282 |
-
def save_uploaded_file(directory, img_file):
|
| 283 |
if not os.path.exists(directory):
|
| 284 |
os.makedirs(directory)
|
| 285 |
# Assuming the uploaded file is an image
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
full_path = os.path.join(directory, img_file.name)
|
| 288 |
-
image.save(
|
| 289 |
-
|
| 290 |
-
return full_path
|
| 291 |
|
| 292 |
def delete_directory(dir_path):
|
| 293 |
try:
|
| 294 |
shutil.rmtree(dir_path)
|
| 295 |
st.session_state['input_list'] = []
|
|
|
|
| 296 |
st.success(f"Deleted previously uploaded images, making room for new images: {dir_path}")
|
| 297 |
except OSError as e:
|
| 298 |
st.error(f"Error: {dir_path} : {e.strerror}")
|
|
@@ -1192,6 +1198,7 @@ def content_tab_settings():
|
|
| 1192 |
### Input Images Local
|
| 1193 |
with col_local_1:
|
| 1194 |
st.session_state['dir_uploaded_images'] = os.path.join(st.session_state.dir_home,'uploads')
|
|
|
|
| 1195 |
uploaded_files = st.file_uploader("Upload Images", type=['jpg', 'jpeg'], accept_multiple_files=True)
|
| 1196 |
if uploaded_files:
|
| 1197 |
# Clear input image gallery and input list
|
|
@@ -1201,15 +1208,20 @@ def content_tab_settings():
|
|
| 1201 |
# Process the new iamges
|
| 1202 |
for uploaded_file in uploaded_files:
|
| 1203 |
file_path = save_uploaded_file(st.session_state['dir_uploaded_images'], uploaded_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1204 |
st.session_state['input_list'].append(file_path)
|
|
|
|
| 1205 |
print(uploaded_file.name)
|
| 1206 |
|
| 1207 |
with col_local_2:
|
| 1208 |
-
if st.session_state['
|
| 1209 |
st.subheader('Image Gallery')
|
| 1210 |
-
|
| 1211 |
# st.image(st.session_state['input_list'])
|
| 1212 |
-
display_image_gallery()
|
| 1213 |
# st.button("Clear Staged Images",on_click=delete_directory, args=[st.session_state['dir_uploaded_images']])
|
| 1214 |
|
| 1215 |
with col_cropped_1:
|
|
@@ -1499,6 +1511,8 @@ if 'zip_filepath' not in st.session_state:
|
|
| 1499 |
st.session_state['zip_filepath'] = None
|
| 1500 |
if 'input_list' not in st.session_state:
|
| 1501 |
st.session_state['input_list'] = []
|
|
|
|
|
|
|
| 1502 |
|
| 1503 |
|
| 1504 |
# if not st.session_state.private_file:
|
|
|
|
| 279 |
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))
|
| 280 |
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.")
|
| 281 |
|
| 282 |
+
def save_uploaded_file(directory, img_file, image=None):
|
| 283 |
if not os.path.exists(directory):
|
| 284 |
os.makedirs(directory)
|
| 285 |
# Assuming the uploaded file is an image
|
| 286 |
+
try:
|
| 287 |
+
with Image.open(img_file) as image:
|
| 288 |
+
full_path = os.path.join(directory, img_file.name)
|
| 289 |
+
image.save(full_path, "JPEG")
|
| 290 |
+
# Return the full path of the saved image
|
| 291 |
+
return full_path
|
| 292 |
+
except:
|
| 293 |
full_path = os.path.join(directory, img_file.name)
|
| 294 |
+
image.save(img_file, "JPEG")
|
| 295 |
+
return directory
|
|
|
|
| 296 |
|
| 297 |
def delete_directory(dir_path):
|
| 298 |
try:
|
| 299 |
shutil.rmtree(dir_path)
|
| 300 |
st.session_state['input_list'] = []
|
| 301 |
+
st.session_state['input_list_small'] = []
|
| 302 |
st.success(f"Deleted previously uploaded images, making room for new images: {dir_path}")
|
| 303 |
except OSError as e:
|
| 304 |
st.error(f"Error: {dir_path} : {e.strerror}")
|
|
|
|
| 1198 |
### Input Images Local
|
| 1199 |
with col_local_1:
|
| 1200 |
st.session_state['dir_uploaded_images'] = os.path.join(st.session_state.dir_home,'uploads')
|
| 1201 |
+
st.session_state['dir_uploaded_images_small'] = os.path.join(st.session_state.dir_home,'uploads_small')
|
| 1202 |
uploaded_files = st.file_uploader("Upload Images", type=['jpg', 'jpeg'], accept_multiple_files=True)
|
| 1203 |
if uploaded_files:
|
| 1204 |
# Clear input image gallery and input list
|
|
|
|
| 1208 |
# Process the new iamges
|
| 1209 |
for uploaded_file in uploaded_files:
|
| 1210 |
file_path = save_uploaded_file(st.session_state['dir_uploaded_images'], uploaded_file)
|
| 1211 |
+
img = Image.open(file_path)
|
| 1212 |
+
img.thumbnail((120, 120), Image.Resampling.LANCZOS)
|
| 1213 |
+
file_path_small = save_uploaded_file(st.session_state['dir_uploaded_images_small'], uploaded_file.name, img)
|
| 1214 |
+
|
| 1215 |
st.session_state['input_list'].append(file_path)
|
| 1216 |
+
st.session_state['input_list_small'].append(file_path_small)
|
| 1217 |
print(uploaded_file.name)
|
| 1218 |
|
| 1219 |
with col_local_2:
|
| 1220 |
+
if st.session_state['input_list_small']:
|
| 1221 |
st.subheader('Image Gallery')
|
| 1222 |
+
selected_img = image_select("Uploaded Images Ready for Transcription", st.session_state['input_list_small'], use_container_width=False)
|
| 1223 |
# st.image(st.session_state['input_list'])
|
| 1224 |
+
# display_image_gallery()
|
| 1225 |
# st.button("Clear Staged Images",on_click=delete_directory, args=[st.session_state['dir_uploaded_images']])
|
| 1226 |
|
| 1227 |
with col_cropped_1:
|
|
|
|
| 1511 |
st.session_state['zip_filepath'] = None
|
| 1512 |
if 'input_list' not in st.session_state:
|
| 1513 |
st.session_state['input_list'] = []
|
| 1514 |
+
if 'input_list_small' not in st.session_state:
|
| 1515 |
+
st.session_state['input_list_small'] = []
|
| 1516 |
|
| 1517 |
|
| 1518 |
# if not st.session_state.private_file:
|