Spaces:
Sleeping
Sleeping
Commit
·
8075c83
1
Parent(s):
509acda
v.1.44
Browse files
app.py
CHANGED
@@ -643,9 +643,10 @@ def create_output_file(df, uploaded_file):
|
|
643 |
|
644 |
def create_interface():
|
645 |
control = ProcessControl()
|
646 |
-
|
|
|
647 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
648 |
-
gr.Markdown("# AI-анализ мониторинга новостей v.1.
|
649 |
|
650 |
with gr.Row():
|
651 |
file_input = gr.File(
|
@@ -701,6 +702,11 @@ def create_interface():
|
|
701 |
visible=False
|
702 |
)
|
703 |
|
|
|
|
|
|
|
|
|
|
|
704 |
def stop_processing():
|
705 |
control.request_stop()
|
706 |
return "Остановка обработки..."
|
@@ -791,16 +797,18 @@ def create_interface():
|
|
791 |
if processed_rows:
|
792 |
result_df = pd.DataFrame(processed_rows)
|
793 |
output_bytes_io = create_output_file(result_df, file_obj)
|
|
|
|
|
794 |
if output_bytes_io:
|
795 |
-
|
796 |
-
|
797 |
result_df,
|
798 |
fig_sentiment,
|
799 |
fig_events,
|
800 |
-
True,
|
801 |
-
#(f"results_{len(processed_rows)}_rows.xlsx", output_bytes_io.getvalue()), # Return tuple of (name, bytes)
|
802 |
f"Обработано {len(processed_rows)}/{total} строк",
|
803 |
-
dedup_message
|
|
|
804 |
)
|
805 |
|
806 |
return (
|
@@ -809,7 +817,8 @@ def create_interface():
|
|
809 |
None, # events plot
|
810 |
gr.update(visible=False), # hide download button
|
811 |
"Нет обработанных данных", # progress message
|
812 |
-
dedup_message # dedup message
|
|
|
813 |
)
|
814 |
|
815 |
except Exception as e:
|
@@ -822,16 +831,17 @@ def create_interface():
|
|
822 |
None,
|
823 |
gr.update(visible=False),
|
824 |
error_msg,
|
825 |
-
""
|
|
|
826 |
)
|
827 |
finally:
|
828 |
if detector:
|
829 |
detector.cleanup()
|
830 |
|
831 |
-
def handle_download(
|
832 |
"""Handle file download when button is clicked"""
|
833 |
-
if
|
834 |
-
return
|
835 |
return None
|
836 |
|
837 |
stop_btn.click(fn=stop_processing, outputs=[progress])
|
@@ -845,14 +855,15 @@ def create_interface():
|
|
845 |
events_plot,
|
846 |
download_button,
|
847 |
progress,
|
848 |
-
status_box
|
|
|
849 |
]
|
850 |
)
|
851 |
|
852 |
download_button.click(
|
853 |
fn=handle_download,
|
854 |
-
inputs=[],
|
855 |
-
outputs=[
|
856 |
)
|
857 |
|
858 |
return app
|
|
|
643 |
|
644 |
def create_interface():
|
645 |
control = ProcessControl()
|
646 |
+
file_data = gr.State(value=None)
|
647 |
+
|
648 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
649 |
+
gr.Markdown("# AI-анализ мониторинга новостей v.1.44")
|
650 |
|
651 |
with gr.Row():
|
652 |
file_input = gr.File(
|
|
|
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 "Остановка обработки..."
|
|
|
797 |
if processed_rows:
|
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 |
+
output_bytes = output_bytes_io.getvalue()
|
804 |
+
return (
|
805 |
result_df,
|
806 |
fig_sentiment,
|
807 |
fig_events,
|
808 |
+
gr.update(visible=True),
|
|
|
809 |
f"Обработано {len(processed_rows)}/{total} строк",
|
810 |
+
dedup_message,
|
811 |
+
(output_bytes, "результаты_анализа.xlsx")
|
812 |
)
|
813 |
|
814 |
return (
|
|
|
817 |
None, # events plot
|
818 |
gr.update(visible=False), # hide download button
|
819 |
"Нет обработанных данных", # progress message
|
820 |
+
dedup_message, # dedup message
|
821 |
+
None
|
822 |
)
|
823 |
|
824 |
except Exception as e:
|
|
|
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 handle_download(file_data):
|
842 |
"""Handle file download when button is clicked"""
|
843 |
+
if file_data is not None:
|
844 |
+
return file_data
|
845 |
return None
|
846 |
|
847 |
stop_btn.click(fn=stop_processing, outputs=[progress])
|
|
|
855 |
events_plot,
|
856 |
download_button,
|
857 |
progress,
|
858 |
+
status_box,
|
859 |
+
file_data
|
860 |
]
|
861 |
)
|
862 |
|
863 |
download_button.click(
|
864 |
fn=handle_download,
|
865 |
+
inputs=[file_data],
|
866 |
+
outputs=[file_output]
|
867 |
)
|
868 |
|
869 |
return app
|