pentarosarium commited on
Commit
e6534df
·
1 Parent(s): 09b6d24
Files changed (1) hide show
  1. app.py +50 -18
app.py CHANGED
@@ -645,7 +645,7 @@ def create_interface():
645
  control = ProcessControl()
646
 
647
  with gr.Blocks(theme=gr.themes.Soft()) as app:
648
- gr.Markdown("# AI-анализ мониторинга новостей v.1.31")
649
 
650
  with gr.Row():
651
  file_input = gr.File(
@@ -667,6 +667,14 @@ def create_interface():
667
  variant="stop",
668
  size="lg"
669
  )
 
 
 
 
 
 
 
 
670
 
671
  with gr.Row():
672
  progress = gr.Textbox(
@@ -688,12 +696,9 @@ def create_interface():
688
  with gr.Column(scale=1):
689
  events_plot = gr.Plot(label="Распределение событий")
690
 
691
- with gr.Row():
692
- download_file = gr.File(
693
- label="📥 Скачать полный отчет",
694
- file_types=[".xlsx"],
695
- interactive=False
696
- )
697
 
698
  def stop_processing():
699
  control.request_stop()
@@ -703,7 +708,7 @@ def create_interface():
703
  def analyze(file_bytes):
704
  if file_bytes is None:
705
  gr.Warning("Пожалуйста, загрузите файл")
706
- return None, None, None, None, "Ожидание файла..."
707
 
708
  try:
709
  # Reset stop flag
@@ -718,7 +723,9 @@ def create_interface():
718
  df = pd.read_excel(file_obj, sheet_name='Публикации')
719
  original_count = len(df)
720
  df = fuzzy_deduplicate(df, 'Выдержки из текста', threshold=55)
721
- logger.info(f"Removed {original_count - len(df)} duplicate entries")
 
 
722
 
723
  processed_rows = []
724
  total = len(df)
@@ -736,8 +743,10 @@ def create_interface():
736
  result_df,
737
  fig_sentiment,
738
  fig_events,
739
- (output, "partial_results.xlsx"),
740
- f"Обработка остановлена. Обработано {len(processed_rows)}/{total} строк"
 
 
741
  )
742
  break
743
 
@@ -781,8 +790,10 @@ def create_interface():
781
  result_df,
782
  fig_sentiment,
783
  fig_events,
784
- (output, f"results_{len(processed_rows)}_rows.xlsx"),
785
- f"Обработано {len(processed_rows)}/{total} строк"
 
 
786
  )
787
 
788
  # Cleanup GPU resources after batch
@@ -799,26 +810,47 @@ def create_interface():
799
  final_df,
800
  fig_sentiment,
801
  fig_events,
802
- (output, "results.xlsx"),
803
- "Обработка завершена!"
 
 
804
  )
805
  else:
806
- return None, None, None, None, "Нет обработанных данных"
807
 
808
  except Exception as e:
809
  error_msg = f"Ошибка анализа: {str(e)}"
810
  logger.error(error_msg)
811
  gr.Error(error_msg)
812
- return None, None, None, None, error_msg
813
  finally:
814
  if detector:
815
  detector.cleanup()
 
 
 
 
816
 
817
  stop_btn.click(fn=stop_processing, outputs=[progress])
818
  analyze_btn.click(
819
  fn=analyze,
820
  inputs=[file_input],
821
- outputs=[stats, sentiment_plot, events_plot, download_file, progress]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
822
  )
823
 
824
  return app
 
645
  control = ProcessControl()
646
 
647
  with gr.Blocks(theme=gr.themes.Soft()) as app:
648
+ gr.Markdown("# AI-анализ мониторинга новостей v.1.32")
649
 
650
  with gr.Row():
651
  file_input = gr.File(
 
667
  variant="stop",
668
  size="lg"
669
  )
670
+
671
+ # Add status messages container
672
+ with gr.Row():
673
+ status_box = gr.Textbox(
674
+ label="Статус дедупликации",
675
+ interactive=False,
676
+ value=""
677
+ )
678
 
679
  with gr.Row():
680
  progress = gr.Textbox(
 
696
  with gr.Column(scale=1):
697
  events_plot = gr.Plot(label="Распределение событий")
698
 
699
+ # Add download button
700
+ download_btn = gr.Button("📥 Скачать результаты", visible=False)
701
+ output_file = gr.File(label="", visible=False)
 
 
 
702
 
703
  def stop_processing():
704
  control.request_stop()
 
708
  def analyze(file_bytes):
709
  if file_bytes is None:
710
  gr.Warning("Пожалуйста, загрузите файл")
711
+ return None, None, None, False, None, "Ожидание файла...", ""
712
 
713
  try:
714
  # Reset stop flag
 
723
  df = pd.read_excel(file_obj, sheet_name='Публикации')
724
  original_count = len(df)
725
  df = fuzzy_deduplicate(df, 'Выдержки из текста', threshold=55)
726
+ removed_count = original_count - len(df)
727
+ dedup_message = f"Удалено {removed_count} дубликатов из {original_count} записей"
728
+ logger.info(f"Removed {removed_count} duplicate entries")
729
 
730
  processed_rows = []
731
  total = len(df)
 
743
  result_df,
744
  fig_sentiment,
745
  fig_events,
746
+ True, # Show download button
747
+ output, # Raw bytes
748
+ f"Обработка остановлена. Обработано {len(processed_rows)}/{total} строк",
749
+ dedup_message
750
  )
751
  break
752
 
 
790
  result_df,
791
  fig_sentiment,
792
  fig_events,
793
+ True, # Show download button
794
+ output, # Raw bytes
795
+ f"Обработано {len(processed_rows)}/{total} строк",
796
+ dedup_message
797
  )
798
 
799
  # Cleanup GPU resources after batch
 
810
  final_df,
811
  fig_sentiment,
812
  fig_events,
813
+ True, # Show download button
814
+ output, # Raw bytes
815
+ "Обработка завершена!",
816
+ dedup_message
817
  )
818
  else:
819
+ return None, None, None, False, None, "Нет обработанных данных", ""
820
 
821
  except Exception as e:
822
  error_msg = f"Ошибка анализа: {str(e)}"
823
  logger.error(error_msg)
824
  gr.Error(error_msg)
825
+ return None, None, None, False, None, error_msg, ""
826
  finally:
827
  if detector:
828
  detector.cleanup()
829
+
830
+ def trigger_download(show_button, file_content):
831
+ """Handle download button visibility and file content"""
832
+ return gr.update(visible=show_button), file_content
833
 
834
  stop_btn.click(fn=stop_processing, outputs=[progress])
835
  analyze_btn.click(
836
  fn=analyze,
837
  inputs=[file_input],
838
+ outputs=[
839
+ stats,
840
+ sentiment_plot,
841
+ events_plot,
842
+ download_btn, # Visibility control
843
+ output_file, # Actual file content
844
+ progress,
845
+ status_box
846
+ ]
847
+ )
848
+
849
+ # Connect download button to file output
850
+ download_btn.click(
851
+ fn=trigger_download,
852
+ inputs=[download_btn, output_file],
853
+ outputs=[download_btn, output_file]
854
  )
855
 
856
  return app