File size: 4,837 Bytes
86695d8
d9ea3f9
60da408
c9ba3ae
d9ea3f9
c9ba3ae
86695d8
 
60da408
51dfd28
 
0d6622c
86695d8
 
 
60da408
86695d8
0d6622c
86695d8
 
d9ea3f9
86695d8
 
51dfd28
86695d8
 
 
51dfd28
86695d8
 
 
 
51dfd28
86695d8
 
 
 
51dfd28
86695d8
 
 
 
 
 
 
0d6622c
86695d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9ba3ae
86695d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60da408
86695d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# ui/layout.py

# -*- coding: utf-8 -*-
#
# PROJECT:      CognitiveEDA v5.0 - The QuantumLeap Intelligence Platform
#
# DESCRIPTION:  This module defines the entire Gradio UI structure. It is now
#               corrected to return only the dictionary of components.

import gradio as gr
from core.config import settings

def create_main_layout() -> dict:
    """
    Defines the Gradio UI structure and returns a dictionary of its components.

    This function is designed to be called within a `gr.Blocks` context.

    Returns:
        A dictionary mapping component names to their Gradio component objects.
    """
    # State object to hold the DataAnalyzer instance
    state_analyzer = gr.State()

    # --- Header ---
    gr.Markdown(f"<h1>{settings.APP_TITLE}</h1>")
    gr.Markdown("A world-class data discovery platform that provides a complete suite of EDA tools and intelligently unlocks specialized analysis modules.")

    # --- Input Row ---
    with gr.Row():
        upload_button = gr.File(label="1. Upload Data File (CSV, Excel)", file_types=[".csv", ".xlsx"], scale=3)
        analyze_button = gr.Button("✨ Generate Intelligence Report", variant="primary", scale=1)

    # --- Main Tabs ---
    with gr.Tabs():
        with gr.Tab("πŸ€– AI-Powered Strategy Report", id="tab_ai"):
            ai_report_output = gr.Markdown("### Your AI-generated report will appear here after analysis...")
        
        with gr.Tab("πŸ“‹ Data Profile", id="tab_profile"):
            with gr.Accordion("Missing Values Report", open=False):
                profile_missing_df = gr.DataFrame()
            with gr.Accordion("Numeric Features Summary", open=True):
                profile_numeric_df = gr.DataFrame()
            with gr.Accordion("Categorical Features Summary", open=True):
                profile_categorical_df = gr.DataFrame()

        with gr.Tab("πŸ“Š Overview Visuals", id="tab_overview"):
            with gr.Row():
                plot_types = gr.Plot()
                plot_missing = gr.Plot()
            plot_correlation = gr.Plot()
            
        with gr.Tab("🎨 Interactive Explorer", id="tab_explorer"):
             gr.Markdown("### Univariate Analysis")
             with gr.Row():
                 dd_hist_col = gr.Dropdown(label="Select Column for Histogram", interactive=True)
                 plot_histogram = gr.Plot()
             gr.Markdown("### Bivariate Analysis")
             with gr.Row():
                 with gr.Column(scale=1):
                     dd_scatter_x = gr.Dropdown(label="X-Axis (Numeric)", interactive=True)
                     dd_scatter_y = gr.Dropdown(label="Y-Axis (Numeric)", interactive=True)
                     dd_scatter_color = gr.Dropdown(label="Color By (Optional)", interactive=True)
                 with gr.Column(scale=2):
                     plot_scatter = gr.Plot()
        
        with gr.Tab("🧩 Clustering (K-Means)", id="tab_cluster", visible=False) as tab_cluster:
            with gr.Row():
                with gr.Column(scale=1):
                    num_clusters = gr.Slider(minimum=2, maximum=10, value=3, step=1, label="Number of Clusters (K)", interactive=True)
                    md_cluster_summary = gr.Markdown()
                with gr.Column(scale=2):
                    plot_cluster = gr.Plot()
            plot_elbow = gr.Plot()
            
        # Add other tabs as needed (Time-Series, Text)
        tab_timeseries = gr.Tab("βŒ› Time-Series Analysis", id="tab_timeseries", visible=False)
        tab_text = gr.Tab("πŸ“ Text Analysis", id="tab_text", visible=False)

    # Collect all components into a dictionary for easy access
    components = {
        # State
        "state_analyzer": state_analyzer,
        # Inputs
        "upload_button": upload_button,
        "analyze_button": analyze_button,
        # AI Tab
        "ai_report_output": ai_report_output,
        # Profile Tab
        "profile_missing_df": profile_missing_df,
        "profile_numeric_df": profile_numeric_df,
        "profile_categorical_df": profile_categorical_df,
        # Overview Tab
        "plot_types": plot_types,
        "plot_missing": plot_missing,
        "plot_correlation": plot_correlation,
        # Explorer Tab
        "dd_hist_col": dd_hist_col,
        "plot_histogram": plot_histogram,
        "dd_scatter_x": dd_scatter_x,
        "dd_scatter_y": dd_scatter_y,
        "dd_scatter_color": dd_scatter_color,
        "plot_scatter": plot_scatter,
        # Conditional Tabs
        "tab_timeseries": tab_timeseries,
        "tab_text": tab_text,
        "tab_cluster": tab_cluster,
        # Clustering Tab Components
        "num_clusters": num_clusters,
        "md_cluster_summary": md_cluster_summary,
        "plot_cluster": plot_cluster,
        "plot_elbow": plot_elbow,
    }

    return components