Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,17 @@
|
|
2 |
|
3 |
# -*- coding: utf-8 -*-
|
4 |
#
|
5 |
-
# PROJECT: CognitiveEDA v5.
|
6 |
#
|
7 |
-
# DESCRIPTION: Main application entry point. This version
|
8 |
-
#
|
|
|
9 |
#
|
10 |
# SETUP: $ pip install -r requirements.txt
|
11 |
#
|
12 |
# AUTHOR: An MCP & PhD Expert in Data & AI Solutions
|
13 |
-
# VERSION: 5.
|
14 |
-
# LAST-UPDATE: 2023-
|
15 |
|
16 |
import warnings
|
17 |
import logging
|
@@ -38,7 +39,6 @@ def main():
|
|
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"):
|
@@ -52,24 +52,29 @@ def main():
|
|
52 |
plot_histogram = gr.Plot()
|
53 |
with gr.Row():
|
54 |
with gr.Column(scale=1):
|
55 |
-
dd_scatter_x
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
-
# ---
|
59 |
with gr.Tab("π§© Clustering (K-Means)", visible=False) as tab_cluster:
|
|
|
|
|
60 |
with gr.Row():
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
with gr.Column(scale=2):
|
65 |
-
plot_cluster = gr.Plot(label="PCA Visualization")
|
66 |
|
67 |
gr.Markdown("---")
|
68 |
-
gr.Markdown("##
|
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("---")
|
@@ -78,14 +83,16 @@ def main():
|
|
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 |
-
#
|
89 |
analysis_complete_event = analyze_button.click(
|
90 |
fn=callbacks.run_initial_analysis,
|
91 |
inputs=[upload_button],
|
@@ -102,18 +109,23 @@ def main():
|
|
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 |
-
#
|
106 |
-
|
107 |
-
fn=callbacks.
|
108 |
-
inputs=[state_analyzer,
|
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 |
|
|
|
2 |
|
3 |
# -*- coding: utf-8 -*-
|
4 |
#
|
5 |
+
# PROJECT: CognitiveEDA v5.9 - The QuantumLeap Intelligence Platform
|
6 |
#
|
7 |
+
# DESCRIPTION: Main application entry point. This version implements a fully
|
8 |
+
# generic, data-agnostic stratification system, allowing users
|
9 |
+
# to dynamically filter and analyze any high-cardinality feature.
|
10 |
#
|
11 |
# SETUP: $ pip install -r requirements.txt
|
12 |
#
|
13 |
# AUTHOR: An MCP & PhD Expert in Data & AI Solutions
|
14 |
+
# VERSION: 5.9 (Generic Stratification Engine)
|
15 |
+
# LAST-UPDATE: 2023-11-01 (Abstracted stratification controls)
|
16 |
|
17 |
import warnings
|
18 |
import logging
|
|
|
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"):
|
|
|
52 |
plot_histogram = gr.Plot()
|
53 |
with gr.Row():
|
54 |
with gr.Column(scale=1):
|
55 |
+
dd_scatter_x = gr.Dropdown(label="X-Axis", interactive=True)
|
56 |
+
dd_scatter_y = gr.Dropdown(label="Y-Axis", interactive=True)
|
57 |
+
dd_scatter_color = gr.Dropdown(label="Color By", interactive=True)
|
58 |
+
with gr.Column(scale=2):
|
59 |
+
plot_scatter = gr.Plot()
|
60 |
|
61 |
+
# --- GENERALIZED CLUSTERING TAB ---
|
62 |
with gr.Tab("π§© Clustering (K-Means)", visible=False) as tab_cluster:
|
63 |
+
gr.Markdown("### Stratified Analysis Control Panel")
|
64 |
+
gr.Markdown("Use this to control for a dominant categorical variable. First, select a feature to stratify by (e.g., 'Region', 'Product_Category'), then select a specific value to analyze.")
|
65 |
with gr.Row():
|
66 |
+
dd_stratify_by_col = gr.Dropdown(label="1. Stratify By Feature", interactive=True, scale=2)
|
67 |
+
dd_stratify_by_value = gr.Dropdown(label="2. Filter By Value", interactive=True, scale=2)
|
68 |
+
num_clusters = gr.Slider(minimum=2, maximum=10, value=4, step=1, label="Number of Clusters (K)", interactive=True, scale=1)
|
|
|
|
|
69 |
|
70 |
gr.Markdown("---")
|
71 |
+
gr.Markdown("## Segmentation Visualization & Profile")
|
72 |
with gr.Row():
|
73 |
with gr.Column(scale=1):
|
74 |
+
md_cluster_summary = gr.Markdown("Methodology summary will appear here.")
|
75 |
md_cluster_personas = gr.Markdown("Detailed cluster personas will appear here...")
|
76 |
with gr.Column(scale=2):
|
77 |
+
plot_cluster = gr.Plot(label="PCA Visualization")
|
78 |
plot_cluster_profile = gr.Plot(label="Cluster Profile Visualization")
|
79 |
|
80 |
gr.Markdown("---")
|
|
|
83 |
|
84 |
tab_timeseries, tab_text = gr.Tab("β Time-Series", visible=False), gr.Tab("π Text", visible=False)
|
85 |
|
86 |
+
# 2. DEFINE OUTPUT LISTS
|
87 |
main_outputs = [
|
88 |
ai_report_output, profile_missing_df, profile_numeric_df, profile_categorical_df,
|
89 |
plot_types, plot_missing, plot_correlation,
|
90 |
dd_hist_col, dd_scatter_x, dd_scatter_y, dd_scatter_color,
|
91 |
+
tab_timeseries, tab_text, tab_cluster,
|
92 |
+
dd_stratify_by_col
|
93 |
]
|
94 |
|
95 |
+
# 3. REGISTER EVENT HANDLERS
|
96 |
analysis_complete_event = analyze_button.click(
|
97 |
fn=callbacks.run_initial_analysis,
|
98 |
inputs=[upload_button],
|
|
|
109 |
for dropdown in [dd_scatter_x, dd_scatter_y, dd_scatter_color]:
|
110 |
dropdown.change(fn=callbacks.create_scatterplot, inputs=scatter_inputs, outputs=[plot_scatter])
|
111 |
|
112 |
+
# Chained callback for the stratification dropdowns
|
113 |
+
dd_stratify_by_col.change(
|
114 |
+
fn=callbacks.update_filter_dropdown,
|
115 |
+
inputs=[state_analyzer, dd_stratify_by_col],
|
116 |
+
outputs=[dd_stratify_by_value]
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
)
|
118 |
+
|
119 |
+
# Clustering callback now listens to changes on ALL THREE controls
|
120 |
+
cluster_inputs = [state_analyzer, dd_stratify_by_col, dd_stratify_by_value, num_clusters]
|
121 |
+
cluster_outputs = [plot_cluster, plot_elbow, md_cluster_summary, md_cluster_personas, plot_cluster_profile]
|
122 |
+
|
123 |
+
for control in [dd_stratify_by_col, dd_stratify_by_value, num_clusters]:
|
124 |
+
control.change(
|
125 |
+
fn=callbacks.update_stratified_clustering,
|
126 |
+
inputs=cluster_inputs,
|
127 |
+
outputs=cluster_outputs
|
128 |
+
)
|
129 |
|
130 |
demo.launch(debug=False, server_name="0.0.0.0")
|
131 |
|