Spaces:
Sleeping
Sleeping
Commit
·
e853c54
1
Parent(s):
8075c83
v.1.45
Browse files
app.py
CHANGED
@@ -643,10 +643,12 @@ def create_output_file(df, uploaded_file):
|
|
643 |
|
644 |
def create_interface():
|
645 |
control = ProcessControl()
|
646 |
-
|
647 |
-
|
648 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
649 |
-
|
|
|
|
|
|
|
650 |
|
651 |
with gr.Row():
|
652 |
file_input = gr.File(
|
@@ -687,7 +689,8 @@ def create_interface():
|
|
687 |
stats = gr.DataFrame(
|
688 |
label="Результаты анализа",
|
689 |
interactive=False,
|
690 |
-
wrap=True
|
|
|
691 |
)
|
692 |
|
693 |
with gr.Row():
|
@@ -696,17 +699,18 @@ def create_interface():
|
|
696 |
with gr.Column(scale=1):
|
697 |
events_plot = gr.Plot(label="Распределение событий")
|
698 |
|
|
|
699 |
with gr.Row():
|
700 |
-
|
701 |
"📥 Скачать результаты",
|
702 |
visible=False
|
703 |
)
|
704 |
-
|
705 |
file_output = gr.File(
|
706 |
-
label="
|
707 |
-
visible=False
|
|
|
708 |
)
|
709 |
-
|
710 |
def stop_processing():
|
711 |
control.request_stop()
|
712 |
return "Остановка обработки..."
|
@@ -716,12 +720,13 @@ def create_interface():
|
|
716 |
if file_bytes is None:
|
717 |
gr.Warning("Пожалуйста, загрузите файл")
|
718 |
return (
|
719 |
-
pd.DataFrame(),
|
720 |
-
None,
|
721 |
-
None,
|
722 |
-
gr.update(visible=False),
|
723 |
-
|
724 |
-
""
|
|
|
725 |
)
|
726 |
|
727 |
try:
|
@@ -798,27 +803,27 @@ def create_interface():
|
|
798 |
result_df = pd.DataFrame(processed_rows)
|
799 |
output_bytes_io = create_output_file(result_df, file_obj)
|
800 |
fig_sentiment, fig_events = create_visualizations(result_df)
|
801 |
-
|
802 |
if output_bytes_io:
|
803 |
-
|
804 |
return (
|
805 |
result_df,
|
806 |
fig_sentiment,
|
807 |
fig_events,
|
808 |
gr.update(visible=True),
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
)
|
813 |
|
814 |
return (
|
815 |
-
pd.DataFrame(),
|
816 |
-
None,
|
817 |
-
None,
|
818 |
-
gr.update(visible=False),
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
)
|
823 |
|
824 |
except Exception as e:
|
@@ -830,22 +835,21 @@ def create_interface():
|
|
830 |
None,
|
831 |
None,
|
832 |
gr.update(visible=False),
|
|
|
833 |
error_msg,
|
834 |
-
""
|
835 |
-
None
|
836 |
)
|
837 |
finally:
|
838 |
if detector:
|
839 |
detector.cleanup()
|
840 |
|
841 |
-
def
|
842 |
-
"""
|
843 |
-
|
844 |
-
return file_data
|
845 |
-
return None
|
846 |
|
847 |
stop_btn.click(fn=stop_processing, outputs=[progress])
|
848 |
|
|
|
849 |
analyze_btn.click(
|
850 |
fn=process_and_download,
|
851 |
inputs=[file_input],
|
@@ -853,16 +857,16 @@ def create_interface():
|
|
853 |
stats,
|
854 |
sentiment_plot,
|
855 |
events_plot,
|
856 |
-
|
|
|
857 |
progress,
|
858 |
-
status_box
|
859 |
-
file_data
|
860 |
]
|
861 |
)
|
862 |
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
outputs=[file_output]
|
867 |
)
|
868 |
|
|
|
643 |
|
644 |
def create_interface():
|
645 |
control = ProcessControl()
|
646 |
+
|
|
|
647 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
648 |
+
# Create state for file data
|
649 |
+
current_file = gr.State(None)
|
650 |
+
|
651 |
+
gr.Markdown("# AI-анализ мониторинга новостей v.1.45")
|
652 |
|
653 |
with gr.Row():
|
654 |
file_input = gr.File(
|
|
|
689 |
stats = gr.DataFrame(
|
690 |
label="Результаты анализа",
|
691 |
interactive=False,
|
692 |
+
wrap=True,
|
693 |
+
max_rows=20
|
694 |
)
|
695 |
|
696 |
with gr.Row():
|
|
|
699 |
with gr.Column(scale=1):
|
700 |
events_plot = gr.Plot(label="Распределение событий")
|
701 |
|
702 |
+
# Create a download row with both button and file components
|
703 |
with gr.Row():
|
704 |
+
download_btn = gr.Button(
|
705 |
"📥 Скачать результаты",
|
706 |
visible=False
|
707 |
)
|
|
|
708 |
file_output = gr.File(
|
709 |
+
label="",
|
710 |
+
visible=False,
|
711 |
+
interactive=False
|
712 |
)
|
713 |
+
|
714 |
def stop_processing():
|
715 |
control.request_stop()
|
716 |
return "Остановка обработки..."
|
|
|
720 |
if file_bytes is None:
|
721 |
gr.Warning("Пожалуйста, загрузите файл")
|
722 |
return (
|
723 |
+
pd.DataFrame(),
|
724 |
+
None,
|
725 |
+
None,
|
726 |
+
gr.update(visible=False),
|
727 |
+
None,
|
728 |
+
"Ожидание файла...",
|
729 |
+
""
|
730 |
)
|
731 |
|
732 |
try:
|
|
|
803 |
result_df = pd.DataFrame(processed_rows)
|
804 |
output_bytes_io = create_output_file(result_df, file_obj)
|
805 |
fig_sentiment, fig_events = create_visualizations(result_df)
|
806 |
+
|
807 |
if output_bytes_io:
|
808 |
+
# Return values in the correct order
|
809 |
return (
|
810 |
result_df,
|
811 |
fig_sentiment,
|
812 |
fig_events,
|
813 |
gr.update(visible=True),
|
814 |
+
output_bytes_io.getvalue(),
|
815 |
+
"Обработка завершена!",
|
816 |
+
dedup_message
|
817 |
)
|
818 |
|
819 |
return (
|
820 |
+
pd.DataFrame(),
|
821 |
+
None,
|
822 |
+
None,
|
823 |
+
gr.update(visible=False),
|
824 |
+
None,
|
825 |
+
"Нет обработанных данных",
|
826 |
+
dedup_message
|
827 |
)
|
828 |
|
829 |
except Exception as e:
|
|
|
835 |
None,
|
836 |
None,
|
837 |
gr.update(visible=False),
|
838 |
+
None,
|
839 |
error_msg,
|
840 |
+
""
|
|
|
841 |
)
|
842 |
finally:
|
843 |
if detector:
|
844 |
detector.cleanup()
|
845 |
|
846 |
+
def update_file_output():
|
847 |
+
"""Handler for download button click"""
|
848 |
+
return gr.update(visible=True, value=("результаты_анализа.xlsx", current_file.value))
|
|
|
|
|
849 |
|
850 |
stop_btn.click(fn=stop_processing, outputs=[progress])
|
851 |
|
852 |
+
# Main processing
|
853 |
analyze_btn.click(
|
854 |
fn=process_and_download,
|
855 |
inputs=[file_input],
|
|
|
857 |
stats,
|
858 |
sentiment_plot,
|
859 |
events_plot,
|
860 |
+
download_btn,
|
861 |
+
current_file, # State for file data
|
862 |
progress,
|
863 |
+
status_box
|
|
|
864 |
]
|
865 |
)
|
866 |
|
867 |
+
# Download handling
|
868 |
+
download_btn.click(
|
869 |
+
fn=update_file_output,
|
870 |
outputs=[file_output]
|
871 |
)
|
872 |
|