Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,16 @@
|
|
2 |
|
3 |
# -*- coding: utf-8 -*-
|
4 |
#
|
5 |
-
# PROJECT: CognitiveEDA v5.
|
6 |
#
|
7 |
-
# DESCRIPTION: Main application entry point. This
|
8 |
-
#
|
9 |
-
# a list of components to the `outputs` parameter.
|
10 |
#
|
11 |
# SETUP: $ pip install -r requirements.txt
|
12 |
#
|
13 |
# AUTHOR: An MCP & PhD Expert in Data & AI Solutions
|
14 |
-
# VERSION: 5.
|
15 |
-
# LAST-UPDATE: 2023-10-
|
16 |
|
17 |
import warnings
|
18 |
import logging
|
@@ -39,6 +38,7 @@ def main():
|
|
39 |
upload_button = gr.File(label="1. Upload Data File", file_types=[".csv", ".xlsx"], scale=3)
|
40 |
analyze_button = gr.Button("β¨ Generate Intelligence Report", variant="primary", scale=1)
|
41 |
with gr.Tabs():
|
|
|
42 |
with gr.Tab("π€ AI-Powered Strategy Report"):
|
43 |
ai_report_output = gr.Markdown("### Your AI-generated report will appear here...")
|
44 |
with gr.Tab("π Data Profile"):
|
@@ -54,27 +54,38 @@ def main():
|
|
54 |
with gr.Column(scale=1):
|
55 |
dd_scatter_x, dd_scatter_y, dd_scatter_color = gr.Dropdown(label="X-Axis", interactive=True), gr.Dropdown(label="Y-Axis", interactive=True), gr.Dropdown(label="Color By", interactive=True)
|
56 |
with gr.Column(scale=2): plot_scatter = gr.Plot()
|
|
|
|
|
57 |
with gr.Tab("π§© Clustering (K-Means)", visible=False) as tab_cluster:
|
58 |
with gr.Row():
|
59 |
with gr.Column(scale=1):
|
60 |
-
num_clusters = gr.Slider(minimum=2, maximum=10, value=
|
61 |
-
md_cluster_summary = gr.Markdown()
|
62 |
-
with gr.Column(scale=2):
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
tab_timeseries, tab_text = gr.Tab("β Time-Series", visible=False), gr.Tab("π Text", visible=False)
|
65 |
|
66 |
-
# 2. DEFINE THE OUTPUTS LIST
|
67 |
-
# This is the critical change. We create an explicit list of components
|
68 |
-
# that will be updated by the main analysis function.
|
69 |
-
# The order here MUST match the order of the returned tuple in the callback.
|
70 |
main_outputs = [
|
71 |
ai_report_output, profile_missing_df, profile_numeric_df, profile_categorical_df,
|
72 |
plot_types, plot_missing, plot_correlation,
|
73 |
dd_hist_col, dd_scatter_x, dd_scatter_y, dd_scatter_color,
|
74 |
tab_timeseries, tab_text, tab_cluster
|
75 |
]
|
76 |
-
|
77 |
-
#
|
78 |
analysis_complete_event = analyze_button.click(
|
79 |
fn=callbacks.run_initial_analysis,
|
80 |
inputs=[upload_button],
|
@@ -83,15 +94,26 @@ def main():
|
|
83 |
analysis_complete_event.then(
|
84 |
fn=callbacks.generate_reports_and_visuals,
|
85 |
inputs=[state_analyzer],
|
86 |
-
outputs=main_outputs
|
87 |
)
|
88 |
|
89 |
-
# --- Other Interactive Callbacks ---
|
90 |
dd_hist_col.change(fn=callbacks.create_histogram, inputs=[state_analyzer, dd_hist_col], outputs=[plot_histogram])
|
91 |
scatter_inputs = [state_analyzer, dd_scatter_x, dd_scatter_y, dd_scatter_color]
|
92 |
for dropdown in [dd_scatter_x, dd_scatter_y, dd_scatter_color]:
|
93 |
dropdown.change(fn=callbacks.create_scatterplot, inputs=scatter_inputs, outputs=[plot_scatter])
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
demo.launch(debug=False, server_name="0.0.0.0")
|
97 |
|
|
|
2 |
|
3 |
# -*- coding: utf-8 -*-
|
4 |
#
|
5 |
+
# PROJECT: CognitiveEDA v5.7 - The QuantumLeap Intelligence Platform
|
6 |
#
|
7 |
+
# DESCRIPTION: Main application entry point. This version adds UI components
|
8 |
+
# for cluster profiling to the Clustering tab.
|
|
|
9 |
#
|
10 |
# SETUP: $ pip install -r requirements.txt
|
11 |
#
|
12 |
# AUTHOR: An MCP & PhD Expert in Data & AI Solutions
|
13 |
+
# VERSION: 5.7 (Cluster Profiling Edition)
|
14 |
+
# LAST-UPDATE: 2023-10-31 (Integrated cluster persona analysis)
|
15 |
|
16 |
import warnings
|
17 |
import logging
|
|
|
38 |
upload_button = gr.File(label="1. Upload Data File", file_types=[".csv", ".xlsx"], scale=3)
|
39 |
analyze_button = gr.Button("β¨ Generate Intelligence Report", variant="primary", scale=1)
|
40 |
with gr.Tabs():
|
41 |
+
# ... (Other tabs remain the same)
|
42 |
with gr.Tab("π€ AI-Powered Strategy Report"):
|
43 |
ai_report_output = gr.Markdown("### Your AI-generated report will appear here...")
|
44 |
with gr.Tab("π Data Profile"):
|
|
|
54 |
with gr.Column(scale=1):
|
55 |
dd_scatter_x, dd_scatter_y, dd_scatter_color = gr.Dropdown(label="X-Axis", interactive=True), gr.Dropdown(label="Y-Axis", interactive=True), gr.Dropdown(label="Color By", interactive=True)
|
56 |
with gr.Column(scale=2): plot_scatter = gr.Plot()
|
57 |
+
|
58 |
+
# --- MODIFIED CLUSTERING TAB ---
|
59 |
with gr.Tab("π§© Clustering (K-Means)", visible=False) as tab_cluster:
|
60 |
with gr.Row():
|
61 |
with gr.Column(scale=1):
|
62 |
+
num_clusters = gr.Slider(minimum=2, maximum=10, value=5, step=1, label="Number of Clusters (K)", interactive=True)
|
63 |
+
md_cluster_summary = gr.Markdown("Methodology summary will appear here.")
|
64 |
+
with gr.Column(scale=2):
|
65 |
+
plot_cluster = gr.Plot(label="PCA Visualization")
|
66 |
+
|
67 |
+
gr.Markdown("---")
|
68 |
+
gr.Markdown("## Cluster Profile Analysis")
|
69 |
+
with gr.Row():
|
70 |
+
with gr.Column(scale=1):
|
71 |
+
md_cluster_personas = gr.Markdown("Detailed cluster personas will appear here...")
|
72 |
+
with gr.Column(scale=2):
|
73 |
+
plot_cluster_profile = gr.Plot(label="Cluster Profile Visualization")
|
74 |
+
|
75 |
+
gr.Markdown("---")
|
76 |
+
gr.Markdown("## Optimal K Analysis")
|
77 |
+
plot_elbow = gr.Plot(label="The Elbow Method")
|
78 |
+
|
79 |
tab_timeseries, tab_text = gr.Tab("β Time-Series", visible=False), gr.Tab("π Text", visible=False)
|
80 |
|
|
|
|
|
|
|
|
|
81 |
main_outputs = [
|
82 |
ai_report_output, profile_missing_df, profile_numeric_df, profile_categorical_df,
|
83 |
plot_types, plot_missing, plot_correlation,
|
84 |
dd_hist_col, dd_scatter_x, dd_scatter_y, dd_scatter_color,
|
85 |
tab_timeseries, tab_text, tab_cluster
|
86 |
]
|
87 |
+
|
88 |
+
# 2. REGISTER EVENT HANDLERS
|
89 |
analysis_complete_event = analyze_button.click(
|
90 |
fn=callbacks.run_initial_analysis,
|
91 |
inputs=[upload_button],
|
|
|
94 |
analysis_complete_event.then(
|
95 |
fn=callbacks.generate_reports_and_visuals,
|
96 |
inputs=[state_analyzer],
|
97 |
+
outputs=main_outputs
|
98 |
)
|
99 |
|
|
|
100 |
dd_hist_col.change(fn=callbacks.create_histogram, inputs=[state_analyzer, dd_hist_col], outputs=[plot_histogram])
|
101 |
scatter_inputs = [state_analyzer, dd_scatter_x, dd_scatter_y, dd_scatter_color]
|
102 |
for dropdown in [dd_scatter_x, dd_scatter_y, dd_scatter_color]:
|
103 |
dropdown.change(fn=callbacks.create_scatterplot, inputs=scatter_inputs, outputs=[plot_scatter])
|
104 |
+
|
105 |
+
# --- MODIFIED CLUSTERING CALLBACK WIRING ---
|
106 |
+
num_clusters.change(
|
107 |
+
fn=callbacks.update_clustering,
|
108 |
+
inputs=[state_analyzer, num_clusters],
|
109 |
+
outputs=[
|
110 |
+
plot_cluster,
|
111 |
+
plot_elbow,
|
112 |
+
md_cluster_summary,
|
113 |
+
md_cluster_personas,
|
114 |
+
plot_cluster_profile
|
115 |
+
]
|
116 |
+
)
|
117 |
|
118 |
demo.launch(debug=False, server_name="0.0.0.0")
|
119 |
|