Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
094bdb2
1
Parent(s):
d91f55d
v.1.46
Browse files
app.py
CHANGED
@@ -648,7 +648,7 @@ def create_interface():
|
|
648 |
# Create state for file data
|
649 |
current_file = gr.State(None)
|
650 |
|
651 |
-
gr.Markdown("# AI-анализ мониторинга новостей v.1.
|
652 |
|
653 |
with gr.Row():
|
654 |
file_input = gr.File(
|
@@ -698,16 +698,12 @@ def create_interface():
|
|
698 |
with gr.Column(scale=1):
|
699 |
events_plot = gr.Plot(label="Распределение событий")
|
700 |
|
701 |
-
# Create a download row with
|
702 |
with gr.Row():
|
703 |
-
download_btn = gr.Button(
|
704 |
-
"📥 Скачать результаты",
|
705 |
-
visible=False
|
706 |
-
)
|
707 |
file_output = gr.File(
|
708 |
-
label="",
|
709 |
visible=False,
|
710 |
-
interactive=
|
711 |
)
|
712 |
|
713 |
def stop_processing():
|
@@ -722,7 +718,6 @@ def create_interface():
|
|
722 |
pd.DataFrame(),
|
723 |
None,
|
724 |
None,
|
725 |
-
gr.update(visible=False),
|
726 |
None,
|
727 |
"Ожидание файла...",
|
728 |
""
|
@@ -745,8 +740,6 @@ def create_interface():
|
|
745 |
processed_rows = []
|
746 |
total = len(df)
|
747 |
batch_size = 3
|
748 |
-
|
749 |
-
|
750 |
|
751 |
for batch_start in range(0, total, batch_size):
|
752 |
if control.should_stop():
|
@@ -759,8 +752,7 @@ def create_interface():
|
|
759 |
result_df,
|
760 |
fig_sentiment,
|
761 |
fig_events,
|
762 |
-
|
763 |
-
("partial_results.xlsx", output_bytes_io.getvalue()), # Return tuple of (name, bytes)
|
764 |
f"Обработка остановлена. Обработано {len(processed_rows)}/{total} строк",
|
765 |
dedup_message
|
766 |
)
|
@@ -795,8 +787,6 @@ def create_interface():
|
|
795 |
except Exception as e:
|
796 |
logger.error(f"Error processing row {idx}: {str(e)}")
|
797 |
continue
|
798 |
-
|
799 |
-
# Create intermediate results
|
800 |
|
801 |
if processed_rows:
|
802 |
result_df = pd.DataFrame(processed_rows)
|
@@ -804,13 +794,11 @@ def create_interface():
|
|
804 |
fig_sentiment, fig_events = create_visualizations(result_df)
|
805 |
|
806 |
if output_bytes_io:
|
807 |
-
# Return values in the correct order
|
808 |
return (
|
809 |
result_df,
|
810 |
fig_sentiment,
|
811 |
fig_events,
|
812 |
-
|
813 |
-
output_bytes_io.getvalue(),
|
814 |
"Обработка завершена!",
|
815 |
dedup_message
|
816 |
)
|
@@ -819,7 +807,6 @@ def create_interface():
|
|
819 |
pd.DataFrame(),
|
820 |
None,
|
821 |
None,
|
822 |
-
gr.update(visible=False),
|
823 |
None,
|
824 |
"Нет обработанных данных",
|
825 |
dedup_message
|
@@ -833,7 +820,6 @@ def create_interface():
|
|
833 |
pd.DataFrame(),
|
834 |
None,
|
835 |
None,
|
836 |
-
gr.update(visible=False),
|
837 |
None,
|
838 |
error_msg,
|
839 |
""
|
@@ -842,13 +828,9 @@ def create_interface():
|
|
842 |
if detector:
|
843 |
detector.cleanup()
|
844 |
|
845 |
-
def update_file_output():
|
846 |
-
"""Handler for download button click"""
|
847 |
-
return gr.update(visible=True, value=("результаты_анализа.xlsx", current_file.value))
|
848 |
-
|
849 |
stop_btn.click(fn=stop_processing, outputs=[progress])
|
850 |
|
851 |
-
# Main processing
|
852 |
analyze_btn.click(
|
853 |
fn=process_and_download,
|
854 |
inputs=[file_input],
|
@@ -856,19 +838,12 @@ def create_interface():
|
|
856 |
stats,
|
857 |
sentiment_plot,
|
858 |
events_plot,
|
859 |
-
|
860 |
-
current_file, # State for file data
|
861 |
progress,
|
862 |
status_box
|
863 |
]
|
864 |
)
|
865 |
|
866 |
-
# Download handling
|
867 |
-
download_btn.click(
|
868 |
-
fn=update_file_output,
|
869 |
-
outputs=[file_output]
|
870 |
-
)
|
871 |
-
|
872 |
return app
|
873 |
|
874 |
if __name__ == "__main__":
|
|
|
648 |
# Create state for file data
|
649 |
current_file = gr.State(None)
|
650 |
|
651 |
+
gr.Markdown("# AI-анализ мониторинга новостей v.1.46")
|
652 |
|
653 |
with gr.Row():
|
654 |
file_input = gr.File(
|
|
|
698 |
with gr.Column(scale=1):
|
699 |
events_plot = gr.Plot(label="Распределение событий")
|
700 |
|
701 |
+
# Create a download row with file component only
|
702 |
with gr.Row():
|
|
|
|
|
|
|
|
|
703 |
file_output = gr.File(
|
704 |
+
label="Скачать результаты",
|
705 |
visible=False,
|
706 |
+
interactive=True
|
707 |
)
|
708 |
|
709 |
def stop_processing():
|
|
|
718 |
pd.DataFrame(),
|
719 |
None,
|
720 |
None,
|
|
|
721 |
None,
|
722 |
"Ожидание файла...",
|
723 |
""
|
|
|
740 |
processed_rows = []
|
741 |
total = len(df)
|
742 |
batch_size = 3
|
|
|
|
|
743 |
|
744 |
for batch_start in range(0, total, batch_size):
|
745 |
if control.should_stop():
|
|
|
752 |
result_df,
|
753 |
fig_sentiment,
|
754 |
fig_events,
|
755 |
+
("partial_results.xlsx", output_bytes_io.getvalue()),
|
|
|
756 |
f"Обработка остановлена. Обработано {len(processed_rows)}/{total} строк",
|
757 |
dedup_message
|
758 |
)
|
|
|
787 |
except Exception as e:
|
788 |
logger.error(f"Error processing row {idx}: {str(e)}")
|
789 |
continue
|
|
|
|
|
790 |
|
791 |
if processed_rows:
|
792 |
result_df = pd.DataFrame(processed_rows)
|
|
|
794 |
fig_sentiment, fig_events = create_visualizations(result_df)
|
795 |
|
796 |
if output_bytes_io:
|
|
|
797 |
return (
|
798 |
result_df,
|
799 |
fig_sentiment,
|
800 |
fig_events,
|
801 |
+
("результаты_анализа.xlsx", output_bytes_io.getvalue()),
|
|
|
802 |
"Обработка завершена!",
|
803 |
dedup_message
|
804 |
)
|
|
|
807 |
pd.DataFrame(),
|
808 |
None,
|
809 |
None,
|
|
|
810 |
None,
|
811 |
"Нет обработанных данных",
|
812 |
dedup_message
|
|
|
820 |
pd.DataFrame(),
|
821 |
None,
|
822 |
None,
|
|
|
823 |
None,
|
824 |
error_msg,
|
825 |
""
|
|
|
828 |
if detector:
|
829 |
detector.cleanup()
|
830 |
|
|
|
|
|
|
|
|
|
831 |
stop_btn.click(fn=stop_processing, outputs=[progress])
|
832 |
|
833 |
+
# Main processing - simplified outputs
|
834 |
analyze_btn.click(
|
835 |
fn=process_and_download,
|
836 |
inputs=[file_input],
|
|
|
838 |
stats,
|
839 |
sentiment_plot,
|
840 |
events_plot,
|
841 |
+
file_output,
|
|
|
842 |
progress,
|
843 |
status_box
|
844 |
]
|
845 |
)
|
846 |
|
|
|
|
|
|
|
|
|
|
|
|
|
847 |
return app
|
848 |
|
849 |
if __name__ == "__main__":
|