Spaces:
Running
Running
Commit
·
ca048bb
1
Parent(s):
48130d6
Major update. Support for 15 LLMs, World Flora Online taxonomy validation, geolocation, 2 OCR methods, significant UI changes, stability improvements, consistent JSON parsing
Browse files
app.py
CHANGED
|
@@ -255,6 +255,7 @@ def handle_image_upload_and_gallery_hf(uploaded_files):
|
|
| 255 |
# Clear input image gallery and input list
|
| 256 |
clear_image_uploads()
|
| 257 |
|
|
|
|
| 258 |
for uploaded_file in uploaded_files:
|
| 259 |
# Determine the file type
|
| 260 |
if uploaded_file.name.lower().endswith('.pdf'):
|
|
@@ -266,26 +267,30 @@ def handle_image_upload_and_gallery_hf(uploaded_files):
|
|
| 266 |
converted_files = os.listdir(st.session_state['dir_uploaded_images'])
|
| 267 |
for file_name in converted_files:
|
| 268 |
if file_name.split('.')[1].lower() in ['jpg','jpeg']:
|
|
|
|
| 269 |
jpg_file_path = os.path.join(st.session_state['dir_uploaded_images'], file_name)
|
| 270 |
st.session_state['input_list'].append(jpg_file_path)
|
| 271 |
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
| 280 |
|
| 281 |
else:
|
|
|
|
| 282 |
# Handle JPG/JPEG files (existing process)
|
| 283 |
file_path = save_uploaded_file(st.session_state['dir_uploaded_images'], uploaded_file)
|
| 284 |
st.session_state['input_list'].append(file_path)
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
|
|
|
| 289 |
|
| 290 |
# After processing all files
|
| 291 |
st.session_state.config['leafmachine']['project']['dir_images_local'] = st.session_state['dir_uploaded_images']
|
|
@@ -334,27 +339,7 @@ def handle_image_upload_and_gallery():
|
|
| 334 |
file_path = save_uploaded_file_local(st.session_state.config['leafmachine']['project']['dir_images_local'], st.session_state['dir_uploaded_images'], input_file)
|
| 335 |
# Convert each page of the PDF to an image
|
| 336 |
n_pages = convert_pdf_to_jpg(file_path, st.session_state['dir_uploaded_images'], dpi=200)#st.session_state.config['leafmachine']['project']['dir_images_local'])
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
# pdf_files_pattern = os.path.join(st.session_state['dir_uploaded_images'], '*.pdf')
|
| 340 |
-
# for pdf_file in glob.glob(pdf_files_pattern):
|
| 341 |
-
# os.remove(pdf_file)
|
| 342 |
-
|
| 343 |
-
# # Update the input list for each page image
|
| 344 |
-
# converted_files = os.listdir(st.session_state['dir_uploaded_images'])
|
| 345 |
-
# for file_name in converted_files:
|
| 346 |
-
# if file_name.lower().endswith('.jpg'):
|
| 347 |
-
# jpg_file_path = os.path.join(st.session_state['dir_uploaded_images'], file_name)
|
| 348 |
-
# st.session_state['input_list'].append(jpg_file_path)
|
| 349 |
-
|
| 350 |
-
# # Optionally, create a thumbnail for the gallery
|
| 351 |
-
# img = Image.open(jpg_file_path)
|
| 352 |
-
# img.thumbnail((GALLERY_IMAGE_SIZE, GALLERY_IMAGE_SIZE), Image.Resampling.LANCZOS)
|
| 353 |
-
# file_path_small = save_uploaded_file_local(st.session_state['dir_uploaded_images'], st.session_state['dir_uploaded_images_small'], file_name, img)
|
| 354 |
-
# st.session_state['input_list_small'].append(file_path_small)
|
| 355 |
-
|
| 356 |
-
# st.session_state.config['leafmachine']['project']['dir_images_local'] = st.session_state['dir_uploaded_images']
|
| 357 |
-
|
| 358 |
else:
|
| 359 |
pass
|
| 360 |
# st.warning("Inputs must be '.PDF' or '.jpg' or '.jpeg'")
|
|
@@ -419,7 +404,6 @@ def list_jpg_files(directory_path):
|
|
| 419 |
break
|
| 420 |
|
| 421 |
for simg in jpg_files:
|
| 422 |
-
|
| 423 |
simg2 = Image.open(simg)
|
| 424 |
simg2.thumbnail((GALLERY_IMAGE_SIZE, GALLERY_IMAGE_SIZE), Image.Resampling.LANCZOS)
|
| 425 |
file_path_small = save_uploaded_local(st.session_state['dir_uploaded_images_small'], simg, simg2)
|
|
|
|
| 255 |
# Clear input image gallery and input list
|
| 256 |
clear_image_uploads()
|
| 257 |
|
| 258 |
+
ind_small = 0
|
| 259 |
for uploaded_file in uploaded_files:
|
| 260 |
# Determine the file type
|
| 261 |
if uploaded_file.name.lower().endswith('.pdf'):
|
|
|
|
| 267 |
converted_files = os.listdir(st.session_state['dir_uploaded_images'])
|
| 268 |
for file_name in converted_files:
|
| 269 |
if file_name.split('.')[1].lower() in ['jpg','jpeg']:
|
| 270 |
+
ind_small += 1
|
| 271 |
jpg_file_path = os.path.join(st.session_state['dir_uploaded_images'], file_name)
|
| 272 |
st.session_state['input_list'].append(jpg_file_path)
|
| 273 |
|
| 274 |
+
if ind_small < MAX_GALLERY_IMAGES +5:
|
| 275 |
+
# Optionally, create a thumbnail for the gallery
|
| 276 |
+
img = Image.open(jpg_file_path)
|
| 277 |
+
img.thumbnail((GALLERY_IMAGE_SIZE, GALLERY_IMAGE_SIZE), Image.Resampling.LANCZOS)
|
| 278 |
+
try:
|
| 279 |
+
file_path_small = save_uploaded_file(st.session_state['dir_uploaded_images_small'], file_name, img)
|
| 280 |
+
except:
|
| 281 |
+
file_path_small = save_uploaded_file_local(st.session_state['dir_uploaded_images_small'],st.session_state['dir_uploaded_images_small'], file_name, img)
|
| 282 |
+
st.session_state['input_list_small'].append(file_path_small)
|
| 283 |
|
| 284 |
else:
|
| 285 |
+
ind_small += 1
|
| 286 |
# Handle JPG/JPEG files (existing process)
|
| 287 |
file_path = save_uploaded_file(st.session_state['dir_uploaded_images'], uploaded_file)
|
| 288 |
st.session_state['input_list'].append(file_path)
|
| 289 |
+
if ind_small < MAX_GALLERY_IMAGES +5:
|
| 290 |
+
img = Image.open(file_path)
|
| 291 |
+
img.thumbnail((GALLERY_IMAGE_SIZE, GALLERY_IMAGE_SIZE), Image.Resampling.LANCZOS)
|
| 292 |
+
file_path_small = save_uploaded_file(st.session_state['dir_uploaded_images_small'], uploaded_file, img)
|
| 293 |
+
st.session_state['input_list_small'].append(file_path_small)
|
| 294 |
|
| 295 |
# After processing all files
|
| 296 |
st.session_state.config['leafmachine']['project']['dir_images_local'] = st.session_state['dir_uploaded_images']
|
|
|
|
| 339 |
file_path = save_uploaded_file_local(st.session_state.config['leafmachine']['project']['dir_images_local'], st.session_state['dir_uploaded_images'], input_file)
|
| 340 |
# Convert each page of the PDF to an image
|
| 341 |
n_pages = convert_pdf_to_jpg(file_path, st.session_state['dir_uploaded_images'], dpi=200)#st.session_state.config['leafmachine']['project']['dir_images_local'])
|
| 342 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
else:
|
| 344 |
pass
|
| 345 |
# st.warning("Inputs must be '.PDF' or '.jpg' or '.jpeg'")
|
|
|
|
| 404 |
break
|
| 405 |
|
| 406 |
for simg in jpg_files:
|
|
|
|
| 407 |
simg2 = Image.open(simg)
|
| 408 |
simg2.thumbnail((GALLERY_IMAGE_SIZE, GALLERY_IMAGE_SIZE), Image.Resampling.LANCZOS)
|
| 409 |
file_path_small = save_uploaded_local(st.session_state['dir_uploaded_images_small'], simg, simg2)
|