# 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"

{settings.APP_TITLE}

") 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