2626from particleanalyzer .core .languages import translations
2727from particleanalyzer .core .language_context import LanguageContext
2828
29+
2930lang = "ru"
3031
3132
@@ -124,6 +125,7 @@ def analyze_image(
124125 show_Feret_diametr : bool ,
125126 api_key : bool ,
126127 request : gr .Request ,
128+ pr = gr .Progress ()
127129 ) -> Tuple :
128130 """
129131 Основной метод для анализа изображения.
@@ -137,15 +139,14 @@ def analyze_image(
137139 desc = self ._get_translation ("Подготовка..." ),
138140 bar_format = "{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]" ,
139141 )
140-
142+ pr ( 0 , desc = self . _get_translation ( "Подготовка..." ))
141143 if (
142144 image ["background" ] is None
143145 and image ["composite" ] is None
144146 and not image ["layers" ]
145147 ) and (image2 is None ):
146148 gr .Warning (self ._get_translation ("Ошибка: изображение отсутствует..." ))
147149 return self ._create_error_return ()
148-
149150 image , orig_image , gray_image , scale , scale_factor_glob = (
150151 self .preprocessor .preprocess_image (
151152 image = image ,
@@ -154,6 +155,7 @@ def analyze_image(
154155 solution = solution ,
155156 request = request ,
156157 pbar = pbar ,
158+ pr = pr ,
157159 sahi_mode = sahi_mode ,
158160 lang = self .lang ,
159161 )
@@ -180,6 +182,7 @@ def analyze_image(
180182 overlap_height_ratio ,
181183 overlap_width_ratio ,
182184 pbar ,
185+ pr ,
183186 orig_image ,
184187 gray_image ,
185188 scale ,
@@ -193,6 +196,8 @@ def analyze_image(
193196 df = pd .DataFrame (particle_data )
194197
195198 pbar .set_description (self ._get_translation ("Построение таблицы..." ))
199+ pr (0.75 , desc = self ._get_translation ("Построение таблицы..." ))
200+
196201 builder = StatisticsBuilder (
197202 df ,
198203 scale_selector ,
@@ -204,9 +209,10 @@ def analyze_image(
204209 pbar .update (1 )
205210
206211 pbar .set_description (self ._get_translation ("Построение графиков..." ))
212+ pr (0.9 , desc = self ._get_translation ("Построение графиков..." ))
207213 fig = builder .build_distribution_fig (image )
208214 pbar .update (1 )
209-
215+ pr ( 1 , desc = self . _get_translation ( "Готово!" ))
210216 return (
211217 output_image ,
212218 df ,
@@ -254,6 +260,7 @@ def _process_with_yolo(
254260 overlap_height_ratio ,
255261 overlap_width_ratio ,
256262 pbar ,
263+ pr ,
257264 orig_image ,
258265 gray_image ,
259266 scale ,
@@ -263,6 +270,7 @@ def _process_with_yolo(
263270 """Обработка с использованием YOLO"""
264271 model = self .model_manager .get_model (model_change )
265272 pbar .set_description (self ._get_translation ("YOLO обрабатывает изображение..." ))
273+ pr (0.5 , desc = self ._get_translation ("YOLO обрабатывает изображение..." ))
266274
267275 try :
268276 with torch .no_grad ():
@@ -297,6 +305,7 @@ def _process_with_yolo(
297305 pbar .update (1 )
298306
299307 pbar .set_description (self ._get_translation ("Обработка частиц..." ))
308+ pr (0.62 , desc = self ._get_translation ("Обработка частиц..." ))
300309 output_image = orig_image .copy ()
301310 thickness = self ._get_scaled_thickness (
302311 output_image .shape [1 ], output_image .shape [0 ]
@@ -339,6 +348,7 @@ def _process_with_detectron(
339348 overlap_height_ratio ,
340349 overlap_width_ratio ,
341350 pbar ,
351+ pr ,
342352 orig_image ,
343353 gray_image ,
344354 scale ,
@@ -354,6 +364,7 @@ def _process_with_detectron(
354364 pbar .set_description (
355365 self ._get_translation ("Detectron2 обрабатывает изображение..." )
356366 )
367+ pr (0.5 , desc = self ._get_translation ("Detectron2 обрабатывает изображение..." ))
357368 try :
358369 predictor = DefaultPredictor (cfg )
359370 results = predictor (image )
@@ -373,6 +384,7 @@ def _process_with_detectron(
373384 pbar .update (1 )
374385
375386 pbar .set_description (self ._get_translation ("Обработка частиц..." ))
387+ pr (0.62 , desc = self ._get_translation ("Обработка частиц..." ))
376388 output_image = orig_image .copy ()
377389 thickness = self ._get_scaled_thickness (
378390 output_image .shape [1 ], output_image .shape [0 ]
@@ -420,6 +432,7 @@ def _process_with_sahi(
420432 overlap_height_ratio ,
421433 overlap_width_ratio ,
422434 pbar ,
435+ pr ,
423436 orig_image ,
424437 gray_image ,
425438 scale ,
@@ -443,6 +456,7 @@ def _process_with_sahi(
443456 )
444457
445458 pbar .set_description (self ._get_translation ("SAHI обрабатывает изображение..." ))
459+ pr (0.5 , desc = self ._get_translation ("SAHI обрабатывает изображение..." ))
446460 try :
447461 results = get_sliced_prediction (
448462 image ,
@@ -463,6 +477,7 @@ def _process_with_sahi(
463477 pbar .update (1 )
464478
465479 pbar .set_description (self ._get_translation ("Обработка частиц..." ))
480+ pr (0.62 , desc = self ._get_translation ("Обработка частиц..." ))
466481 output_image = orig_image .copy ()
467482 thickness = self ._get_scaled_thickness (
468483 output_image .shape [1 ], output_image .shape [0 ]
0 commit comments