55from PIL import Image
66import csv
77import os
8- from pathlib import Path
98from datetime import datetime
109from particleanalyzer .core .languages import translations
1110from particleanalyzer .core .language_context import LanguageContext
@@ -127,7 +126,7 @@ def reset_interface(scale_value):
127126 [(None , None )], # Очищаем chatbot
128127 gr .update (visible = False ), # Скрываем строку results_row
129128 gr .update (visible = False ), # Скрываем sidebar
130- gr .update (visible = True ), # Показываем строку row_image_file
129+ gr .update (visible = True ), # Показываем строку row_image_file
131130 gr .update (visible = False ), # Скрываем строку row_analysis
132131 None , # Очищаем image_file
133132 )
@@ -333,7 +332,11 @@ def statistic_an(
333332 )
334333 selected_image = cv2 .cvtColor (selected_image , cv2 .COLOR_BGR2RGB )
335334
336- return selected_image , stats_df , fig ,
335+ return (
336+ selected_image ,
337+ stats_df ,
338+ fig ,
339+ )
337340
338341
339342selected_particles = [] # Глобальный список для хранения выбранных частиц
@@ -395,7 +398,9 @@ def reset_selection(output_table_image2):
395398 )
396399
397400
398- def particle_removal (output_table_image2 , points_df , output_table , round_value , scale_selector ):
401+ def particle_removal (
402+ output_table_image2 , points_df , output_table , round_value , scale_selector
403+ ):
399404 global selected_particles
400405 if not output_table_image2 .empty and "№" in output_table_image2 .columns :
401406 try :
@@ -415,9 +420,9 @@ def particle_removal(output_table_image2, points_df, output_table, round_value,
415420 limits = ParticleAnalyzer .calculate_limits (output_table , round_value )
416421 scale_selector = ParticleAnalyzer .SCALE_OPTIONS [scale_selector ]
417422 return (
418- gr .update (visible = False ),
419- gr .update (visible = False ),
420- points_df ,
423+ gr .update (visible = False ),
424+ gr .update (visible = False ),
425+ points_df ,
421426 output_table ,
422427 gr .update (
423428 minimum = limits ["d_max_min" ],
@@ -428,9 +433,9 @@ def particle_removal(output_table_image2, points_df, output_table, round_value,
428433 ),
429434 gr .update (
430435 minimum = limits ["d_min_min" ],
431- maximum = limits ["d_min_max" ] ,
432- value = (limits ["d_min_min" ], limits ["d_min_max" ] ),
433- step = limits ["d_min_max" ] * 0.01 ,
436+ maximum = limits ["d_min_max" ],
437+ value = (limits ["d_min_min" ], limits ["d_min_max" ]),
438+ step = limits ["d_min_max" ] * 0.01 ,
434439 label = f"Dₘᵢₙ [{ get_translation (scale_selector ['unit' ])} ]" ,
435440 ),
436441 gr .update (
@@ -458,9 +463,14 @@ def particle_removal(output_table_image2, points_df, output_table, round_value,
458463 step = limits ["P_max" ] * 0.01 ,
459464 label = f"P [{ get_translation (scale_selector ['unit' ])} ]" ,
460465 ),
461- gr .update (minimum = limits ["I_min" ], maximum = limits ["I_max" ], value = (limits ["I_min" ], limits ["I_max" ])),
466+ gr .update (
467+ minimum = limits ["I_min" ],
468+ maximum = limits ["I_max" ],
469+ value = (limits ["I_min" ], limits ["I_max" ]),
470+ ),
462471 )
463472
473+
464474def img_to_numpy_array (file_path ):
465475 try :
466476 with Image .open (file_path ) as img :
@@ -469,15 +479,13 @@ def img_to_numpy_array(file_path):
469479 except Exception as e :
470480 print (f"Ошибка при загрузке TIFF: { e } " )
471481 return None , None
472-
482+
483+
473484def handle_file_upload (file , scale_selector ):
474485 if file is None :
475486 return gr .skip (), gr .skip (), gr .update (visible = True ), gr .update (visible = False )
476-
477- scale = ParticleAnalyzer .SCALE_OPTIONS [scale_selector ]["scale" ]
478-
487+
479488 file_path = file .name
480- file_ext = Path (file_path ).suffix .lower ()[1 :]
481489 in_image , im = img_to_numpy_array (file_path )
482490
483491 return (
@@ -487,6 +495,7 @@ def handle_file_upload(file, scale_selector):
487495 gr .update (visible = True ),
488496 )
489497
498+
490499empty_df_ParticleCharacteristics = get_columns ("Pixels" ).fillna ("" )
491500empty_df_ParticleStatistics = get_stats_columns ()
492501
0 commit comments